]> git.eshelyaron.com Git - emacs.git/commitdiff
Filter out nul bytes when killing from a *grep* buffer
authorLars Ingebrigtsen <larsi@gnus.org>
Sat, 2 Jul 2022 15:58:56 +0000 (17:58 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sat, 2 Jul 2022 15:58:56 +0000 (17:58 +0200)
* lisp/progmodes/grep.el (grep-mode): Filter out the nul bytes
(bug#48321).

lisp/progmodes/grep.el

index a3ef90f397e3c75587bae6c0c70eae36b74a3a79..4f90a5344403ac1452f0e00bb9b5462a864cb85e 100644 (file)
@@ -885,6 +885,14 @@ The value depends on `grep-command', `grep-template',
   (setq-local compilation-disable-input t)
   (setq-local compilation-error-screen-columns
               grep-error-screen-columns)
+  ;; We normally use a nul byte to separate the file name from the
+  ;; contents, but display it as ":".  That's fine, but when yanking
+  ;; to other buffers, it's annoying to have the nul byte there.
+  (unless kill-transform-function
+    (setq-local kill-transform-function #'identity))
+  (add-function :filter-return (local 'kill-transform-function)
+                (lambda (string)
+                  (string-replace "\0" ":" string)))
   (add-hook 'compilation-filter-hook #'grep-filter nil t))
 
 (defun grep--save-buffers ()