Function: evil--ex-string-for-print

evil--ex-string-for-print is a byte-compiled function defined in evil-commands.el.

Signature

(evil--ex-string-for-print BEG END LINUMP BORDERLINE)

Documentation

Return a string to be printed by :print etc.

Starts at line of BEG and end at line of END. Include line number at the start of each line if LINUMP is non-nil. Surround line denoted by BORDERLINE with dashes if non-nil.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-commands.el
(defun evil--ex-string-for-print (beg end linump borderline)
  "Return a string to be printed by :print etc.
Starts at line of BEG and end at line of END.
Include line number at the start of each line if LINUMP is non-nil.
Surround line denoted by BORDERLINE with dashes if non-nil."
  (let ((result-string "")
        (continue t)
        (line-move-visual nil))
    (save-excursion
      (goto-char beg)
      (while continue
        (let* ((line-num (line-number-at-pos))
               (border (and (natnump borderline) (= borderline line-num)))
               (raw-line (thing-at-point 'line))
               (line (if (string= "\n" (substring raw-line -1))
                         raw-line (concat raw-line "\n")))
               (border-length (1- (min (length line) (frame-width)))))
          (when border
            (setq result-string
                  (concat result-string (make-string border-length ?-) "\n")))
          (when linump
            (setq result-string
                  (concat result-string
                          (propertize (number-to-string (line-number-at-pos))
                                      'face 'line-number-current-line)
                          " ")))
          (unless (eobp)
            (setq result-string (concat result-string line)))
          (when border
            (setq result-string
                  (concat result-string (make-string border-length ?-) "\n")))
          (when (or (= (point) (progn (evil-line-move 1 t) (point)))
                    (> (line-end-position) end))
            (setq continue nil)))))
    (string-trim-right result-string "\n")))