diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2020-08-14 23:55:14 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2020-08-15 00:00:37 +0100 |
commit | 5460412d96c2ccf05f04a5a229dd7230a29ce48e (patch) | |
tree | 4b6fc17d289aadc1d75056afa2b6585f10f768ec /Emacs/.config/emacs | |
parent | 8034383cc6eabee7eaff222f870afaaa2e4b4a3a (diff) | |
download | dotfiles-5460412d96c2ccf05f04a5a229dd7230a29ce48e.tar.gz dotfiles-5460412d96c2ccf05f04a5a229dd7230a29ce48e.tar.bz2 dotfiles-5460412d96c2ccf05f04a5a229dd7230a29ce48e.zip |
+custom code to toggle any given buffer
When called, function will:
- Close buffer hosting window if buffer displayed
- Open new window displaying buffer
This can be useful for utils like eshell which don't provide this
functionality.
Diffstat (limited to 'Emacs/.config/emacs')
-rw-r--r-- | Emacs/.config/emacs/config.org | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Emacs/.config/emacs/config.org b/Emacs/.config/emacs/config.org index c73670c..e58344f 100644 --- a/Emacs/.config/emacs/config.org +++ b/Emacs/.config/emacs/config.org @@ -129,6 +129,21 @@ The logic is pretty simple: (goto-char (+ old 1)) (evil-normal-state)))) #+END_SRC +** Toggle buffer +For some buffer with name =buf-name= with a creation function +=buf-create=, toggle it via this function. +#+BEGIN_SRC emacs-lisp +(defun +dx/toggle-buffer (buf-name buf-create) + (interactive) + (let* ((buffer (or (get-buffer buf-name) (funcall buf-create))) + (displayed (get-buffer-window buffer))) ; Get window when displayed, nil otherwise + (cond (displayed ; already displayed thus delete + (select-window displayed) + (delete-window)) + (t ; not displayed thus show and select + (display-buffer buffer) + (select-window (get-buffer-window buffer)))))) +#+END_SRC * General Setup general, a good package for defining keys. In this case, I generate a new definer for the "LEADER" keys. Leader is bound to SPC |