Function: evil-text-object-make-linewise

evil-text-object-make-linewise is a byte-compiled function defined in evil-macros.el.

Signature

(evil-text-object-make-linewise RANGE)

Documentation

Turn the text object selection RANGE to linewise.

The selection is adjusted in a sensible way so that the selected lines match the user intent. In particular, whitespace-only parts at the first and last lines are omitted. This function returns the new range.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-macros.el
(defun evil-text-object-make-linewise (range)
  "Turn the text object selection RANGE to linewise.
The selection is adjusted in a sensible way so that the selected
lines match the user intent. In particular, whitespace-only parts
at the first and last lines are omitted. This function returns
the new range."
  ;; Bug #607
  ;; If new type is linewise and the selection of the
  ;; first line consists of whitespace only, the
  ;; beginning is moved to the start of the next line. If
  ;; the selections of the last line consists of
  ;; whitespace only, the end is moved to the end of the
  ;; previous line.
  (if (eq (evil-type range) 'line)
      range
    (let ((expanded (plist-get (evil-range-properties range) :expanded))
          (newrange (evil-expand-range range t)))
      (save-excursion
        ;; skip whitespace at the beginning
        (goto-char (evil-range-beginning newrange))
        (skip-chars-forward " \t")
        (when (and (not (bolp)) (eolp))
          (evil-set-range-beginning newrange (1+ (point))))
        ;; skip whitepsace at the end
        (goto-char (evil-range-end newrange))
        (skip-chars-backward " \t")
        (when (and (not (eolp)) (bolp))
          (evil-set-range-end newrange (1- (point))))
        ;; only modify range if result is not empty
        (if (> (evil-range-beginning newrange)
               (evil-range-end newrange))
            range
          (unless expanded
            (evil-contract-range newrange))
          newrange)))))