Skip to content

Instantly share code, notes, and snippets.

@mads-hartmann
Created August 20, 2012 10:05
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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)
@Xeite
Copy link

Xeite commented Jul 30, 2020

Thank you for sharing :)

For those who want to integrate treemacs window, I left little bit modified code.

(defun toggle-maximize-buffer () "Maximize buffer"
  (interactive)
  (if (= 1 (length (remove-if #'treemacs-is-treemacs-window? (window-list))))
      (jump-to-register '_) 
    (progn
      (window-configuration-to-register '_)
      (delete-other-windows))))

@g-gundam
Copy link

g-gundam commented Mar 4, 2022

Thanks to all who wrote variations of this function. It's quite useful.

@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