From 3663fa52f623c44c65206d000a8d0a7a36ca9264 Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Fri, 19 Oct 2018 12:26:12 +0900 Subject: [PATCH] Fix overlay copy --- emacs.el | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/emacs.el b/emacs.el index 505d918..c92cdba 100644 --- a/emacs.el +++ b/emacs.el @@ -2333,10 +2333,20 @@ TYPE is target object type." (current-buffer)))))) (defun git-walktree--replace-into-buffer (target) - "Replace TARGET buffer contents with that of current buffer." - (let ((buf (current-buffer))) + "Replace TARGET buffer contents with that of current buffer. +It also copy text overlays." + (let ((src (current-buffer))) (with-current-buffer target - (replace-buffer-contents buf)))) + (replace-buffer-contents src))) + + (let ((overlays (overlays-in (point-min) (point-max)))) + (dolist (o overlays) + (let ((beg (overlay-start o)) + (end (overlay-end o))) + (move-overlay (copy-overlay o) + beg + end + target))))) (require 'ansi-color) (defun git-walktree--open-treeish (commitish path treeish) @@ -2359,6 +2369,8 @@ TYPE is target object type." (cd git-walktree-repository-root) (save-excursion (let ((inhibit-read-only t)) + ;; Remove existing overlays generated by ansi-color-apply-on-region + (remove-overlays) (with-temp-buffer (if commitish (progn (git-walktree--call-process nil @@ -2370,6 +2382,8 @@ TYPE is target object type." "--decorate" "--stat" commitish) + (ansi-color-apply-on-region (point-min) + (point)) (insert "\n") (insert (format "Contents of '%s:%s':\n" (git-walktree--commitish-fordisplay commitish) @@ -2384,11 +2398,7 @@ TYPE is target object type." treeish) (git-walktree--replace-into-buffer buf)) - ;; Overlays won't be copied with replace-buffer-contents so do this - ;; after copying contents - (remove-overlays) - (ansi-color-apply-on-region (point-min) - (point-max)))) + )) (git-walktree-mode) (set-buffer-modified-p nil)