我开始大量使用命令Cx rw和Cx rj将窗口配置存储到寄存器中并在稍后调用它们,但我觉得有点烦人的是光标位置按照时间存储窗口配置已保存。
基本上我希望光标位置不存储(或自动更新),这样每当我“跳转”到存储的窗口配置时,我都会获得与上次访问时相同的视图,而不是像我创建时那样它。
有什么想法吗? 安赫尔
答案 0 :(得分:3)
如果您查看源代码
(defun window-configuration-to-register (register &optional arg)
...
(set-register register (list (current-window-configuration) (point-marker))))
你会看到它存储一个点作为第二个参数。 只需重新定义它就像
(defun my-window-configuration-to-register (register &optional arg)
(interactive "cWindow configuration to register: \nP")
(set-register register (list (current-window-configuration) nil)))
并重新定义C-x r w快捷方式以使用my-window-configuration-to-register
(define-key (current-global-map) (kbd "C-x r w") 'my-window-configuration-to-register)
或定义建议
(defadvice window-configuration-to-register (after window-configuration-to-register-no-point activate)
"Avoid storing current buffer's position in the register. We want to stay on the last used position, not to jump to the saved one"
(set-register register (list (current-window-configuration) nil)))
唯一的问题是当你跳转到它时会出现错误信息。您可以重新定义jump-to-register
以避免它
答案 1 :(得分:3)
我也发现这非常烦人,只是编写了一个解决方案。使用常规功能(current-window-configuration或window-configuration-to-register)存储窗口配置。然后,在应用保存的窗口配置(或寄存器)之前,
以下代码执行此操作。您必须自己将restore-window-configuration连接到寄存器代码。
(defun buffer-point-map ()
(save-excursion
(mapcar (lambda (buffer) (cons (buffer-name buffer)
(progn (set-buffer buffer) (point))))
(buffer-list))))
(defun apply-buffer-points (buff-point-map)
(mapc (lambda (window) (let* ((buffer (window-buffer window))
(buffer-point (cdr (assoc (buffer-name buffer) buff-point-map))))
(when buffer-point (set-window-point window buffer-point))))
(window-list))
nil)
(defun restore-window-configuration (window-config)
(let ((points (buffer-point-map)))
(set-window-configuration window-config)
(apply-buffer-points points)))
答案 2 :(得分:1)
我将添加另一个使用不同方法的答案。
在跳转到另一个寄存器之前,您可以存储当前窗口配置。这样它就会在你跳跃之前存储你最新的缓冲区位置。
但是,这并不适用于所有情况。例如,如果您只是切换到另一个缓冲区或使用M-x dired
创建一个缓冲区,那么它将不会存储当前窗口配置。
(defvar current-window-conf-register nil)
(defadvice window-configuration-to-register (after window-configuration-to-register-current-reg activate)
(setq current-window-conf-register register))
(defadvice jump-to-register (before jump-to-register-store-window-conf activate)
(if current-window-conf-register (window-configuration-to-register current-window-conf-register))
(setq current-window-conf-register register))
答案 3 :(得分:0)
作为对您的问题的间接回答,您可以考虑使用revive.el
,它支持在Emacs重新启动时保存和恢复窗口配置,但不(我相信)存储该点。