Windows configuration for registration

I'm starting to use the Cx rw and Cx rj commands quite a bit to store the window configuration for registering and recalling them at a later point, but I find it a little annoying that the cursor positions are kept in accordance with the time that the Window configuration was saved.

Basically, I would like the cursorโ€™s positions not to be saved (or updated automatically), so whenever I โ€œjumpโ€ to the configuration of a saved window, I get the same view as when I last visited it, and not like when creating It.

Any ideas? Angel

+4
source share
4 answers

If you look at the source code

(defun window-configuration-to-register (register &optional arg) ... (set-register register (list (current-window-configuration) (point-marker)))) 

you will see that it saves the point as the second argument. Just reformulate it as

 (defun my-window-configuration-to-register (register &optional arg) (interactive "cWindow configuration to register: \nP") (set-register register (list (current-window-configuration) nil))) 

and override the Cx rw shortcut and also use my-window-configuration-to-register

 (define-key (current-global-map) (kbd "Cx rw") 'my-window-configuration-to-register) 

Or define advice

 (defadvice window-configuration-to-register (after window-configuration-to-register-no-point activate) "Avoid storing current buffer 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))) 

The only problem is that when you click on it, an error message appears. You can override jump-to-register to avoid this.

+3
source

I also found this a very annoying and simply coded solution. Save the window configuration using the usual functionality (the current configuration window or the configuration window for registration). Then, before applying the saved config (or register) window,

  • Keep points of all open buffers.
  • Restore window configuration.
  • Apply saved points to current windows.

The following code does this. You will have to connect the recovery window configuration directly to the register 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))) 
+3
source

I will add another answer that takes a different approach.

Before changing to another register, you can save the current window configuration. Thus, it will save your last buffer positions just before you jump.

However, this will not work in all cases. For example, if you simply switch to another buffer or create a buffer using Mx dired or something, it will not save the current window configuration.

 (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)) 
+1
source

As an indirect answer to your question, you can instead use revive.el , which supports saving and restoring window configurations while restarting Emacs, but does not (I believe) preserve the point.

0
source

All Articles