git-timemachine-mode
是 minor-mode
不是 major-mode
,所以设置成 meow-motion-mode
只能看 hook。
git-timemachine 是通过新建了一个 buffer 渲染后展示的内容,其实也有个 git-timemachine-mode-hook
,我希望通过这个 hook 来把新的这个 buffer 设置成 meow-motion-mode
,但是一直不成功。
(defun my-custom-timemachine-hook ()
(message "%s" (buffer-name))
(meow-motion-mode 1))
(add-hook 'git-timemachine-mode-hook 'my-custom-timemachine-hook)
这样的代码 message 是正常输出的,就是 git-timemachine 新建后切换到的 buffer。
但我在新的 buffer,eval 执行 (meow-motion-mode 1)
是可以的。
1 个赞
我是直接使用magit 代替了timemachine的功能。
magit 提供了 magit-blob-next
与magit-blob-previous
如果嫌弃上面两个命令执行了太多次会产生很多临时buffer
可以通过下面两个advice kill掉之前的buffer
(define-advice magit-blob-next (:around (orig-fun &rest args) kill-all-blob-after-quit)
"kill last viewed buffer"
(let ((prev-buffer (current-buffer)))
(apply orig-fun args)
(kill-buffer prev-buffer)
(unless magit-buffer-file-name
(user-error "magit timemachine: You have reached the end of time"))))
(define-advice magit-blob-previous (:around (orig-fun &rest args) kill-all-blob-after-quit)
"kill last viewed buffer"
(let ((prev-buffer (current-buffer)))
(apply orig-fun args)
(unless (equal magit-buffer-file-name (buffer-file-name prev-buffer))
(kill-buffer prev-buffer))))
可以用C-xC-w
将当前view 的buffer 写入文件,实现恢复以前版本的作用
也可以像我写一个命令绑定到C-cC-c上
(defun vmacs-magit-blob-save()
(interactive)
(let ((file magit-buffer-file-name)
(blob-buf (current-buffer)))
(when file
(with-current-buffer (find-file file)
(widen)
(replace-buffer-contents blob-buf))
(message "save blob to file %s" file))
(dolist (buf (buffer-list)) ;关闭此文件所有版本的blob buffer
(with-current-buffer buf
(when (equal magit-buffer-file-name file)
(kill-this-buffer))))))
(define-key magit-blob-mode-map (kbd "M-n") 'magit-blob-next)
(define-key magit-blob-mode-map (kbd "M-p") 'magit-blob-previous)
(define-key magit-blob-mode-map (kbd "C-c C-c") 'vmacs-magit-blob-save)
(global-set-key (kbd "M-p") 'magit-blob-previous)
(global-set-key (kbd "M-n") 'magit-blob-next)
1 个赞