Function: evil-yank-block-handler

evil-yank-block-handler is a byte-compiled function defined in evil-common.el.

Signature

(evil-yank-block-handler LINES)

Documentation

Insert the current text as block.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
(defun evil-yank-block-handler (lines)
  "Insert the current text as block."
  (let* ((count (or evil-paste-count 1))
         shifted-forward
         (col (if (and (eq this-command 'evil-paste-after)
                       (not (and (bolp) (eolp)))
                       (setq shifted-forward t))
                  (1+ (current-column))
                (current-column)))
         (opoint (point))
         (first t))
    (dolist (line lines)
      ;; maybe we have to insert a new line at eob
      (if first
          (setq first nil)
        (when (or (> (forward-line 1) 0)
                  (and (eobp) (not (bolp))))
          (insert "\n")))
      ;; concat multiple copies according to count
      (setq line (apply #'concat (make-list count line)))
      ;; trim whitespace at beginning and end
      (string-match "\\` *\\(.*?\\) *\\'" line)
      (let ((text (match-string 1 line))
            (begextra (match-beginning 1))
            (endextra (- (match-end 0) (match-end 1))))
        ;; insert text unless we insert an empty line behind eol
        (unless (and (< (evil-column (line-end-position)) col)
                     (string= text ""))
          ;; if we paste behind eol, it may be sufficient to insert tabs
          (if (< (evil-column (line-end-position)) col)
              (move-to-column (+ col begextra) t)
            (move-to-column col t)
            (insert (make-string begextra ?\s)))
          (evil-remove-yank-excluded-properties text)
          (insert text)
          (unless (eolp)
            ;; text follows, so we have to insert spaces
            (insert (make-string endextra ?\s))))))
    (setq evil-last-paste
          (list this-command
                evil-paste-count
                opoint
                (length lines)                   ; number of rows
                (* count (length (car lines))))) ; number of columns
    (evil-set-marker ?\[ opoint)
    (evil-set-marker ?\] (1- (point)))
    (if evil--cursor-after
        (backward-char)
      (goto-char opoint)
      (when shifted-forward (forward-char)))))