From 83e92e31c3ed1ba9d2b8d0eceb839ba6bb264cfc Mon Sep 17 00:00:00 2001 From: Yann Dutrieux Date: Fri, 19 Jan 2024 20:29:34 +0100 Subject: [PATCH 1/4] Fix text prop stickyness for evil-open-above/below commands --- evil-common.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evil-common.el b/evil-common.el index c305c256..d7127047 100644 --- a/evil-common.el +++ b/evil-common.el @@ -1801,7 +1801,7 @@ closer if MOVE is non-nil." with regard to indentation." (evil-narrow-to-field (evil-move-beginning-of-line) - (insert (if use-hard-newlines hard-newline "\n")) + (insert-and-inherit (if use-hard-newlines hard-newline "\n")) (forward-line -1) (back-to-indentation))) @@ -1810,7 +1810,7 @@ with regard to indentation." with regard to indentation." (evil-narrow-to-field (evil-move-end-of-line) - (insert (if use-hard-newlines hard-newline "\n")) + (insert-and-inherit (if use-hard-newlines hard-newline "\n")) (back-to-indentation))) ;;; Markers From e357183f2a60697fcd2e22b63b27d7a9bf9597c7 Mon Sep 17 00:00:00 2001 From: Yann Dutrieux Date: Sat, 3 Feb 2024 21:54:49 +0100 Subject: [PATCH 2/4] Add text property inheritance to all calls to insert and insert-char - 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 --- evil-commands.el | 23 ++++++++++++----------- evil-common.el | 16 ++++++++-------- evil-repeat.el | 2 +- evil-states.el | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 286cf946..a718f365 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -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)) @@ -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) @@ -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)))))) @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 () @@ -3349,7 +3350,7 @@ 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 '("#" "%")) @@ -3357,11 +3358,11 @@ If no FILE is specified, reload the current buffer from disk." (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 () diff --git a/evil-common.el b/evil-common.el index d7127047..eea98b3a 100644 --- a/evil-common.el +++ b/evil-common.el @@ -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) @@ -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))) @@ -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." @@ -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 @@ -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 diff --git a/evil-repeat.el b/evil-repeat.el index df00d8f6..7d1b8fe5 100644 --- a/evil-repeat.el +++ b/evil-repeat.el @@ -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) diff --git a/evil-states.el b/evil-states.el index c15b963d..c6d5a9f1 100644 --- a/evil-states.el +++ b/evil-states.el @@ -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. From cba701c8f31b60cac62bf5a3341fa531fe5c4a2d Mon Sep 17 00:00:00 2001 From: Yann Dutrieux Date: Fri, 29 Mar 2024 13:00:44 +0100 Subject: [PATCH 3/4] Preserve text properties upon evil-paste --- evil-commands.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index a718f365..f8b5bd62 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -2227,7 +2227,7 @@ The return value is the yanked text." ;; no yank-handler, default (when (vectorp text) (setq text (evil-vector-to-string text))) - (set-text-properties 0 (length text) nil text) + ;; (set-text-properties 0 (length text) nil text) (push-mark opoint t) (dotimes (_ (or count 1)) (insert-for-yank text)) @@ -2279,7 +2279,7 @@ The return value is the yanked text." ;; no yank-handler, default (when (vectorp text) (setq text (evil-vector-to-string text))) - (set-text-properties 0 (length text) nil text) + ;; (set-text-properties 0 (length text) nil text) (unless (eolp) (forward-char)) (push-mark (point) t) ;; TODO: Perhaps it is better to collect a list of all From 039f491c331f718547261139ddd2512321b080b2 Mon Sep 17 00:00:00 2001 From: Yann Dutrieux Date: Fri, 19 Apr 2024 09:07:31 +0200 Subject: [PATCH 4/4] Fix PR based on tomdl89's comments --- evil-commands.el | 2 -- evil-states.el | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index f8b5bd62..f6b632a6 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -2227,7 +2227,6 @@ The return value is the yanked text." ;; no yank-handler, default (when (vectorp text) (setq text (evil-vector-to-string text))) - ;; (set-text-properties 0 (length text) nil text) (push-mark opoint t) (dotimes (_ (or count 1)) (insert-for-yank text)) @@ -2279,7 +2278,6 @@ The return value is the yanked text." ;; no yank-handler, default (when (vectorp text) (setq text (evil-vector-to-string text))) - ;; (set-text-properties 0 (length text) nil text) (unless (eolp) (forward-char)) (push-mark (point) t) ;; TODO: Perhaps it is better to collect a list of all diff --git a/evil-states.el b/evil-states.el index c6d5a9f1..c15b963d 100644 --- a/evil-states.el +++ b/evil-states.el @@ -881,7 +881,7 @@ CORNER defaults to `upper-left'." (this-command #'evil-replace-backspace)) (when prev (delete-char 1) - (when char (save-excursion (insert-and-inherit char)))))) + (when char (save-excursion (insert 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.