Function: evil-motion-range
evil-motion-range is a byte-compiled function defined in
evil-macros.el.
Signature
(evil-motion-range MOTION &optional COUNT TYPE)
Documentation
Execute a motion and return the buffer positions.
The return value is a list (BEG END TYPE).
Source Code
;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-macros.el
(defun evil-motion-range (motion &optional count type)
"Execute a motion and return the buffer positions.
The return value is a list (BEG END TYPE)."
(let ((opoint (point))
(omark (mark t))
(obuffer (current-buffer))
(evil-motion-marker (move-marker (make-marker) (point)))
range)
(evil-with-transient-mark-mode
(evil-narrow-to-field
(unwind-protect
(let ((current-prefix-arg count)
;; Store type in global variable `evil-this-type'.
;; If necessary, motions can change their type
;; during execution by setting this variable.
(evil-this-type
(or type (evil-get-command-property motion :type 'exclusive))))
(condition-case err
(let ((repeat-type (evil--repeat-type motion)))
(when (functionp repeat-type) (funcall repeat-type 'pre))
(unless (with-local-quit
(setq range (call-interactively motion))
t)
(evil-repeat-abort)
(setq quit-flag t))
(when (functionp repeat-type) (funcall repeat-type 'post)))
(error
(evil-repeat-abort)
;; some operators depend on succeeding motions, in
;; particular for `evil-forward-char' (e.g., used by
;; `evil-substitute'), therefore we let end-of-line
;; and end-of-buffer pass
(if (memq (car err) '(end-of-line end-of-buffer))
(message (error-message-string err))
(signal (car err) (cdr err)))))
(cond
;; the motion returned a range
((evil-range-p range))
;; the motion made a Visual selection
((evil-visual-state-p)
(setq range (evil-visual-range)))
;; the motion made an active region
((region-active-p)
(setq range (evil-range (region-beginning) (region-end)
evil-this-type)))
;; default: range from previous position to current
(t (setq range (evil-expand-range
(evil-normalize evil-motion-marker
(point)
evil-this-type)))))
(unless (or (null type) (eq (evil-type range) type))
(evil-set-type range type)
(evil-expand-range range))
(evil-set-range-properties range nil)
range)
;; restore point and mark like `save-excursion',
;; but only if the motion hasn't disabled the operator
(unless evil-inhibit-operator
(set-buffer obuffer)
(evil-move-mark omark)
(goto-char opoint))
;; delete marker so it doesn't slow down editing
(move-marker evil-motion-marker nil))))))