all repos — archive/dotfiles @ 57d40296cdb4ad759b857b0ea4c396d2ade94b80

Superseded by nixfiles

Emacs: Improve hide/show mode line functions
Alan Pearce alan@alanpearce.uk
Mon, 06 Feb 2017 08:50:15 +0100
commit

57d40296cdb4ad759b857b0ea4c396d2ade94b80

parent

a0219037c6eff35b09b0ec4352efff3606b5d140

1 files changed, 25 insertions(+), 16 deletions(-)

jump to
M tag-emacs/emacs.d/init.orgtag-emacs/emacs.d/init.org
@@ -141,26 +141,25 @@ #+BEGIN_SRC emacs-lisp (use-package basic-theme
   :config (progn
             (load-theme 'basic t)
+
+            (set-face-background 'mode-line "#a1b56c")
+
+            (defvar mode-line-default-format mode-line-format)
+            (defcustom mode-line-default-hidden t
+              "Whether to hide the mode line by default")
+
             (defun show-mode-line ()
               (interactive)
-              (let ((faces-to-toggle '(mode-line mode-line-inactive)))
-                (mapcar (lambda (face)
-                          (set-face-background face "#a1b56c")
-                          (set-face-attribute face nil :height (face-attribute 'default :height)))
-                        faces-to-toggle)))
+              (setq mode-line-format mode-line-default-format)
+              (when (called-interactively-p)
+                (setq-default mode-line-format mode-line-default-format)
+                (setq mode-line-default-hidden nil)))
             (defun hide-mode-line ()
               (interactive)
-              (let ((faces-to-toggle '(mode-line mode-line-inactive)))
-                (mapcar (lambda (face)
-                          (set-face-background face "#e8e8e8")
-                          (set-face-attribute face nil :height 20))
-                        faces-to-toggle)))
-            (defun mode-line-visual-toggle ()
-              (interactive)
-              (cond ((string= "#a1b56c" (face-attribute 'mode-line :background))
-                     (hide-mode-line))
-                    (t
-                     (show-mode-line))))
+              (setq mode-line-format nil)
+              (when (called-interactively-p)
+                (setq-default mode-line-format nil)
+                (setq mode-line-default-hidden t)))
 
             (setq-default cursor-type 'bar)
             (setq-default cursor-in-non-selected-windows nil)
@@ -175,6 +174,16 @@ (interactive)               (fringe-mode '(8 . 4))
               (show-mode-line))
             (hide-clutter)
+
+            (when mode-line-default-hidden
+              (call-interactively #'hide-mode-line))
+
+            (defun hide-mode-line-if-default-hidden ()
+              (if mode-line-default-hidden
+                  (hide-mode-line)
+                (show-mode-line)))
+
+            (add-hook 'after-change-major-mode-hook #'hide-mode-line-if-default-hidden)
 
             (add-hook 'minibuffer-setup-hook #'show-mode-line)
             (add-hook 'minibuffer-exit-hook #'hide-mode-line)))