Function: expreg-expand

expreg-expand is an interactive and natively compiled function defined in expreg.el.

Signature

(expreg-expand)

Documentation

Expand region.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/29cdhkmkqv2bgp3p30khhf35kkbgx1ya-emacs-packages-deps/share/emacs/site-lisp/elpa/expreg-1.4.1/expreg.el
;;;###autoload
(defun expreg-expand ()
  "Expand region."
  (interactive)
  ;; Initialize states if this is the first call to expreg functions.
  (when (not (and (use-region-p)
                  (eq (region-beginning)
                      (cadr (car expreg--prev-regions)))
                  (eq (region-end)
                      (cddr (car expreg--prev-regions)))))
    (setq-local expreg--next-regions nil)
    (setq-local expreg--prev-regions nil)
    (setq-local expreg--initial-point (point))
    (when expreg-restore-point-on-quit
      ;; We have to add the advice using :before. :after doesn’t work
      ;; (advice doesn’t get called). ‘set-transient-map’ doesn’t work
      ;; either because of how special ‘keyboard-quit’ is.
      (advice-add 'keyboard-quit :before #'expreg--keyboard-quit-advice)))

  ;; If we are not already in the middle of expansions, compute them.
  (when (and (null expreg--next-regions)
             (null expreg--prev-regions))
    (let* ((orig (point))
           (regions (mapcan (lambda (fn) (save-excursion
                                           (funcall fn)))
                            expreg-functions))
           (regions (expreg--filter-regions regions orig))
           (regions (expreg--sort-regions regions))
           (regions (cl-remove-duplicates regions :test #'equal)))
      (setq-local expreg--next-regions regions)))

  ;; Go past all the regions that are smaller than the current region,
  ;; if region is active.
  (when (use-region-p)
    (while (and expreg--next-regions
                (let ((beg (cadr (car expreg--next-regions)))
                      (end (cddr (car expreg--next-regions))))
                  (and (<= (region-beginning) beg)
                       (<= end (region-end)))))
      ;; Pop from next-regions, push into prev-regions.
      (push (pop expreg--next-regions)
            expreg--prev-regions)))

  ;; Expand to the next expansion.
  (when expreg--next-regions
    (let ((region (pop expreg--next-regions)))
      (set-mark (cddr region))
      (goto-char (cadr region))
      (push region expreg--prev-regions)
      (unless transient-mark-mode
        (activate-mark))))

  (when expreg--verbose
    (message "blame: %s\nnext: %S\nprev: %S"
             (caar expreg--prev-regions)
             expreg--next-regions expreg--prev-regions)))