Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created August 20, 2012 10:05
Show Gist options
  • Save mads-hartmann/3402786 to your computer and use it in GitHub Desktop.
Save mads-hartmann/3402786 to your computer and use it in GitHub Desktop.
An Emacs function to temporarily make one buffer fullscreen. You can quickly restore the old window setup.
(defun toggle-maximize-buffer () "Maximize buffer"
(interactive)
(if (= 1 (length (window-list)))
(jump-to-register '_)
(progn
(set-register '_ (list (current-window-configuration)))
(delete-other-windows))))
;; Bind it to a key.
;; (global-set-key [(super shift return)] 'toggle-maximize-buffer)
@lebensterben
Copy link

Based on previous comments:
here's a version that works with both neotree and treemacs

(defun toggle-maximize-buffer ()
  "Maximize buffer."
  (interactive)
  (save-excursion
    (if (and (= 1 (length (cl-remove-if
                           (lambda (w)
                             (or (and (fboundp 'treemacs-is-treemacs-window?)
                                      (treemacs-is-treemacs-window? w))
                                 (and (bound-and-true-p neo-global--window)
                                      (eq neo-global--window w))))
                           (window-list))))
             (assoc ?_ register-alist))
        (jump-to-register ?_)
      (window-configuration-to-register ?_)
      (delete-other-windows))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment