我開始使用相當繁重的命令Cx rw和Cx rj來將窗口配置存儲到寄存器並在稍後調用它們,但是我發現有點煩人,光標位置按每個窗口配置保存的時間。Windows配置到寄存器
基本上我希望光標位置不會被存儲(或自動更新),這樣每當我「跳」到存儲的窗口配置時,我都會得到與上次訪問時相同的視圖,而不是當我創建它。
任何想法? 安赫爾
我開始使用相當繁重的命令Cx rw和Cx rj來將窗口配置存儲到寄存器並在稍後調用它們,但是我發現有點煩人,光標位置按每個窗口配置保存的時間。Windows配置到寄存器
基本上我希望光標位置不會被存儲(或自動更新),這樣每當我「跳」到存儲的窗口配置時,我都會得到與上次訪問時相同的視圖,而不是當我創建它。
任何想法? 安赫爾
如果你看看到源代碼
(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)))
和重新定義一個CX RW快捷方式,以及使用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
,以避免它
作爲一個間接的回答你的問題,你可以考慮使用revive.el
相反,它支持保存和跨Emacs的重啓恢復窗口配置,但不會(我相信)存儲點。
謝謝,我會再次檢查它,但上次我看起來我認爲它不適合我,因爲它也存儲了該點,或者因爲我無法保存不同的配置並將它們命名爲稍後調用它們。 – 2011-05-03 08:40:41
我會添加另一個使用不同方法的答案。
在跳轉到另一個寄存器之前,您可以存儲當前的窗口配置。這樣它會在你跳轉之前存儲你最新的緩衝區。
但是,這並不適用於所有情況。例如,如果你只是切換到另一個緩衝區或創建一個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))
我也發現這非常惱人,只是編碼了一個解決方案。使用正常功能(current-window-configuration或window-configuration-to-register)存儲窗口配置。然後,在應用保存的窗口配置(或註冊)之前,
下面的代碼是這樣做的。儘管如此,您必須自己將註冊碼還原到窗口配置。
(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)))
嗨,這是偉大的,但我希望會有股票Emacs的一些選項(因爲我用它在多臺計算機的,我寧願不寫代碼爲他們每個人) – 2011-04-29 10:37:39
好,因爲它在源代碼中看起來沒有這種選擇。根據我的經驗,我定製了Emacs很多,另外一個定製不會改變任何東西 – 2011-04-29 10:43:15
好的,所以我添加了新的my-window-configuration-to-register和my-jump-to-register定義到我的.emacs文件,現在。非常感謝 – 2011-04-29 11:46:57