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)
@gpion
Copy link

gpion commented Jan 2, 2013

The code throws an error when "jump-to-register" is called,
backtrace:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  jump-to-register(_)
  (if (= 1 (length (window-list))) (jump-to-register (quote _)) (progn (set-register (quote _) (list (current-window-configuration))) (delete-other-windows)))
  toggle-maximize-buffer()
  call-interactively(toggle-maximize-buffer nil nil)

Using GNU Emacs 24.2.1 (powerpc-ibm-aix5.3.0.0, X toolkit)

@gpion
Copy link

gpion commented Jan 2, 2013

This version works:

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

@tmalsburg
Copy link

tmalsburg commented Aug 4, 2016

This is super useful. Thanks both for sharing.

@meain
Copy link

meain commented Mar 7, 2017

Awesome, thank you 👍

@johalun
Copy link

johalun commented Aug 17, 2018

Sweet, thanks!

@lopoisaac
Copy link

Works like a charm! Thank you!

@popoiopo
Copy link

Amazing! thanks ;)

@safijari
Copy link

Using this in my "make your own spacemacs" config. Thanks

@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