Function: evil-operator-range
evil-operator-range is a byte-compiled function defined in
evil-macros.el.
Signature
(evil-operator-range &optional RETURN-TYPE)
Documentation
Read a motion from the keyboard and return its buffer positions.
The return value is a list (BEG END), or (BEG END TYPE) if RETURN-TYPE is non-nil.
Source Code
;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-macros.el
;; this is used in the `interactive' specification of an operator command
(defun evil-operator-range (&optional return-type)
"Read a motion from the keyboard and return its buffer positions.
The return value is a list (BEG END), or (BEG END TYPE) if
RETURN-TYPE is non-nil."
(let ((motion (or evil-operator-range-motion
(when evil-called-from-ex-p 'evil-line)))
(type evil-operator-range-type)
range count)
(setq evil-this-type-modified nil)
(cond
;; Ex command
((and evil-called-from-ex-p evil-ex-range)
(setq range evil-ex-range))
;; Visual selection
((and (not evil-called-from-ex-p) (evil-visual-state-p))
(setq range (evil-visual-range)))
;; active region
((and (not evil-called-from-ex-p) (region-active-p))
(setq range (evil-range (region-beginning) (region-end)
(or evil-this-type 'exclusive))))
;; motion
(t
(evil-save-echo-area
(evil-save-state
(unless motion
;; Make linewise operator shortcuts. E.g., "d" yields the
;; shortcut "dd", and "g?" yields shortcuts "g??" and "g?g?".
(let ((keys (nth 2 (evil-extract-count (this-command-keys)))))
(evil-change-state 'operator)
(cl-loop for keys on (listify-key-sequence keys) do
(define-key evil-operator-shortcut-map
(vconcat keys) #'evil-line-or-visual-line)))
;; read motion from keyboard
(let ((command (evil-read-motion motion)))
(setq motion (car command)
count (cadr command)
type (or type (nth 2 command)))))
(cond
((eq motion #'undefined)
(setq range (list nil nil)
motion nil))
((or (null motion) ; keyboard-quit
(evil-get-command-property motion :suppress-operator))
(evil-repeat-abort)
(setq quit-flag t
range (evil-range (point) (point)) ; zero-len range
motion nil))
(evil-repeat-count
(setq count evil-repeat-count
;; only the first operator's count is overwritten
evil-repeat-count nil))
((or count current-prefix-arg)
;; multiply operator count and motion count together
(setq count
(* (prefix-numeric-value count)
(prefix-numeric-value current-prefix-arg)))))
(when motion
(let ((evil-state 'operator)
mark-active)
;; calculate motion range
(setq range (evil-motion-range motion count type))))
;; update global variables
(setq evil-this-motion motion
evil-this-motion-count count
type (evil-type range type)
evil-this-type type)))))
(unless (or (null type) (eq (evil-type range) type))
(evil-contract-range range)
(evil-set-range-type range type)
(evil-expand-range range))
(setq evil-operator-range-beginning (evil-range-beginning range)
evil-operator-range-end (evil-range-end range)
evil-operator-range-type (evil-type range))
(setcdr (cdr range)
(when return-type (list (evil-type range))))
range))