Skip to content

Commit

Permalink
Add text property inheritance to all calls to insert and insert-char
Browse files Browse the repository at this point in the history
- evil-ex-put
- evil-copy
- evil-move
- evil-invert-case
- evil-replace
- evil-visual-paste
- evil-insert-digraph
- evil-read
- evil-replace-backspace
- evil-yank-line-handler
- evil-yank-block-handler
- evil-execute-change
  • Loading branch information
ydutrieux committed Feb 3, 2024
1 parent 83e92e3 commit e357183
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
23 changes: 12 additions & 11 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ given."
(if force (evil-insert-newline-above) (evil-insert-newline-below))
(evil-set-marker ?\[ (point))
;; `insert' rather than `insert-for-yank' as we want to ignore yank-handlers...
(insert (if (and (< 0 (length text))
(insert-and-inherit (if (and (< 0 (length text))
(eq ?\n (aref text (1- (length text)))))
(substring text 0 (1- (length text)))
text))
Expand Down Expand Up @@ -1696,7 +1696,7 @@ of the block."
(when (or (zerop len) (/= (aref txt (1- len)) ?\n))
(setq txt (concat txt "\n")))
(when (and (eobp) (not (bolp))) (newline)) ; incomplete last line
(insert txt)
(insert-and-inherit txt)
(forward-line -1)))

(evil-define-command evil-move (beg end address)
Expand All @@ -1721,7 +1721,7 @@ of the block."
(when (and (eobp) (not (bolp))) (newline)) ; incomplete last line
(when (evil-visual-state-p)
(move-marker evil-visual-mark (point)))
(insert txt)
(insert-and-inherit txt)
(forward-line -1)
(when (evil-visual-state-p)
(move-marker evil-visual-point (point))))))
Expand Down Expand Up @@ -1774,7 +1774,8 @@ Add (add-hook 'evil-local-mode-hook 'turn-on-undo-tree-mode) to your init file f
(let ((char (following-char)))
(delete-char 1)
(insert-char
(if (eq (upcase char) char) (downcase char) (upcase char))))
(if (eq (upcase char) char) (downcase char) (upcase char))
1 t))
(setq beg (1+ beg))))))

(evil-define-operator evil-invert-char (beg end type)
Expand Down Expand Up @@ -2176,7 +2177,7 @@ The default for width is the value of `fill-column'."
(let ((beg (evil-move-to-column begcol nil t))
(end (evil-move-to-column endcol nil t)))
(delete-region beg end)
(insert (make-string (- endcol begcol) char))))))
(insert-and-inherit (make-string (- endcol begcol) char))))))
beg end char))
(goto-char beg)
(cond
Expand All @@ -2190,7 +2191,7 @@ The default for width is the value of `fill-column'."
(if (eq (char-after) ?\n)
(forward-char)
(delete-char 1)
(insert-char char 1)))
(insert-char char 1 t)))
(goto-char (max beg (1- end))))))))

(evil-define-command evil-paste-before
Expand Down Expand Up @@ -2366,7 +2367,7 @@ leave the cursor just after the new text."
(when (and (eq yank-handler #'evil-yank-line-handler)
(not (memq type '(line block)))
(/= end (point-max)))
(insert "\n"))
(insert-and-inherit "\n"))
(evil-normal-state)
(when kill-ring (current-kill 1)))
;; Effectively memoize `evil-get-register' because it can be
Expand Down Expand Up @@ -2878,7 +2879,7 @@ next VCOUNT - 1 lines below the current one."
insert-prompt (make-overlay opoint (+ chars-to-delete opoint)))
(evil-update-replace-alist opoint count chars-to-delete))
(setq insert-prompt (make-overlay opoint opoint)))
(insert-char (evil-read-digraph-char-with-overlay insert-prompt) count)
(insert-char (evil-read-digraph-char-with-overlay insert-prompt) count t)
(when chars-to-delete (delete-char chars-to-delete))))

(evil-define-command evil-ex-show-digraphs ()
Expand Down Expand Up @@ -3349,19 +3350,19 @@ If no FILE is specified, reload the current buffer from disk."
(when count (goto-char (point-min)))
(when (or (not (zerop (forward-line (or count 1))))
(not (bolp)))
(insert "\n"))
(insert-and-inherit "\n"))
(cond
((/= (aref file 0) ?!)
(when (member file '("#" "%"))
(setq file (evil-ex-replace-special-filenames file)))
(let ((result (insert-file-contents file)))
(save-excursion
(forward-char (cadr result))
(unless (bolp) (insert "\n")))))
(unless (bolp) (insert-and-inherit "\n")))))
(t
(shell-command (evil-ex-replace-special-filenames (substring file 1)) t)
(goto-char (mark))
(unless (bolp) (insert "\n"))
(unless (bolp) (insert-and-inherit "\n"))
(forward-line -1)))))

(evil-define-command evil-show-files ()
Expand Down
16 changes: 8 additions & 8 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ The tracked insertion is set to `evil-last-insertion'."
((eq this-command 'evil-paste-before)
(evil-move-beginning-of-line)
(let ((beg (point)))
(insert text)
(insert-and-inherit text)
(setq evil-last-paste
(list 'evil-paste-before evil-paste-count opoint beg (point)))
(evil-set-marker ?\[ beg)
Expand All @@ -2425,8 +2425,8 @@ The tracked insertion is set to `evil-last-insertion'."
((eq this-command 'evil-paste-after)
(evil-move-end-of-line)
(let ((beg (point)))
(insert "\n")
(insert text)
(insert-and-inherit "\n")
(insert-and-inherit text)
(delete-char -1) ; delete the last newline
(setq evil-last-paste
(list 'evil-paste-after evil-paste-count opoint beg (point)))
Expand All @@ -2435,7 +2435,7 @@ The tracked insertion is set to `evil-last-insertion'."
(unless evil--cursor-after
(goto-char (1+ beg))))
(back-to-indentation))
(t (insert text)))))
(t (insert-and-inherit text)))))

(defun evil-yank-block-handler (lines)
"Insert the current text as block."
Expand All @@ -2451,7 +2451,7 @@ The tracked insertion is set to `evil-last-insertion'."
(setq first nil)
(when (or (> (forward-line 1) 0)
(and (eobp) (not (bolp))))
(insert "\n")))
(insert-and-inherit "\n")))
;; concat multiple copies according to count
(setq line (apply #'concat (make-list count line)))
;; trim whitespace at beginning and end
Expand All @@ -2466,12 +2466,12 @@ The tracked insertion is set to `evil-last-insertion'."
(if (< (evil-column (line-end-position)) col)
(move-to-column (+ col begextra) t)
(move-to-column col t)
(insert (make-string begextra ?\s)))
(insert-and-inherit (make-string begextra ?\s)))
(evil-remove-yank-excluded-properties text)
(insert text)
(insert-and-inherit text)
(unless (eolp)
;; text follows, so we have to insert spaces
(insert (make-string endextra ?\s))))))
(insert-and-inherit (make-string endextra ?\s))))))
(setq evil-last-paste
(list this-command
evil-paste-count
Expand Down
2 changes: 1 addition & 1 deletion evil-repeat.el
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ where point should be placed after all changes."
(dolist (change changes)
(goto-char (+ point (nth 0 change)))
(delete-char (nth 2 change))
(insert (nth 1 change)))
(insert-and-inherit (nth 1 change)))
(goto-char (+ point rel-point)))))

(defun evil-execute-repeat-info (repeat-info)
Expand Down
2 changes: 1 addition & 1 deletion evil-states.el
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ CORNER defaults to `upper-left'."
(this-command #'evil-replace-backspace))
(when prev
(delete-char 1)
(when char (save-excursion (insert char))))))
(when char (save-excursion (insert-and-inherit char))))))

(defun evil-update-replace-alist (opoint count chars-to-delete &optional offset)
"Add CHARS-TO-DELETE chars to evil-replace-alist, starting at OPOINT.
Expand Down

0 comments on commit e357183

Please sign in to comment.