branch: elpa/git-commit
commit ee0b557a94876cf89f9b8116ab9e9012c5d1404a
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
Remove text properties when copying from magit buffers
If there is yanked text with the `magit-section' property at point,
many magit commands would believe that there indeed is a section at
point. This may or may not result in an error, and if not, then the
resulting behavior can be very confusing.
It might have been nice to preserve the `face' property, and maybe
some others, but `remove-list-of-text-properties' does not support
prefixing LIST-OF-PROPERTIES with `not' to remove all but the named
properties.
---
lisp/magit-section.el | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index e75e64eb8d..03883475bb 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -424,6 +424,8 @@ Magit-Section is documented in info node `(magit-section)'."
#'magit-section--highlight-region)
(setq-local redisplay-unhighlight-region-function
#'magit-section--unhighlight-region)
+ (add-function :filter-return (local 'filter-buffer-substring-function)
+ #'magit-section--remove-text-properties)
(when (fboundp 'magit-section-context-menu)
(add-hook 'context-menu-functions #'magit-section-context-menu 10 t))
(when magit-section-disable-line-numbers
@@ -439,6 +441,12 @@ Magit-Section is documented in info node
`(magit-section)'."
(when (fboundp 'magit-preserve-section-visibility-cache)
(add-hook 'kill-buffer-hook #'magit-preserve-section-visibility-cache)))
+(defun magit-section--remove-text-properties (string)
+ "Remove all text-properties from STRING.
+Most importantly `magit-section'."
+ (set-text-properties 0 (length string) nil string)
+ string)
+
;;; Core
(defvar-local magit-root-section nil