Last active
December 2, 2018 13:33
-
-
Save ksqsf/1461090f2a1d80721b5485b809bad653 to your computer and use it in GitHub Desktop.
Window Configuration Ring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar wc-ring nil) | |
(defvar wc-ring-max 10) | |
(defun push-wc () | |
(if (not (null (get-register ?9))) | |
(set-register ?0 (get-register ?9))) | |
(dolist (i '(?9 ?8 ?7 ?6 ?5 ?4 ?3 ?2)) | |
(if (not (null (get-register (1- i)))) | |
(set-register i (get-register (1- i))))) | |
(window-configuration-to-register ?1)) | |
(defun go-to-home () | |
"Quickly go back to scratch. Previous window configuration is | |
saved in register 1." | |
(interactive) | |
(if (not (equal (current-window-configuration) (get-register ?1))) | |
(push-wc)) | |
(delete-other-windows) | |
(switch-to-buffer "*scratch*") | |
(erase-buffer) | |
(insert initial-scratch-message) | |
(set-buffer-modified-p nil)) | |
(global-set-key (kbd "<home>") #'go-to-home) |
NOTE: I wasn't aware of the existence of ring
in Emacs, which is a generic ring data structure.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
winner-undo
can be useless when you do many things after go back home. That's why current window configuration is saved.