Skip to content

Commit

Permalink
Fix edge case where old mode-line is forgotten
Browse files Browse the repository at this point in the history
Also removes hide-mode-line-reset, since it is no longer needed/used.
  • Loading branch information
hlissner committed Nov 12, 2021
1 parent cc81ba3 commit daa4908
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions hide-mode-line.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
:global nil
(if hide-mode-line-mode
(progn
(add-hook 'after-change-major-mode-hook #'hide-mode-line-reset nil t)
(setq hide-mode-line--old-format mode-line-format
mode-line-format hide-mode-line-format))
(remove-hook 'after-change-major-mode-hook #'hide-mode-line-reset t)
(add-hook 'after-change-major-mode-hook #'hide-mode-line-mode nil t)
(unless hide-mode-line--old-format
(setq hide-mode-line--old-format mode-line-format))
(setq mode-line-format hide-mode-line-format))
(remove-hook 'after-change-major-mode-hook #'hide-mode-line-mode t)
(setq mode-line-format hide-mode-line--old-format
hide-mode-line--old-format nil))
(when (called-interactively-p 'any)
Expand All @@ -51,21 +52,6 @@
;; Ensure major-mode or theme changes don't overwrite these variables
(put 'hide-mode-line--old-format 'permanent-local t)
(put 'hide-mode-line-mode 'permanent-local-hook t)
(put 'hide-mode-line-reset 'permanent-local-hook t)

(defun hide-mode-line-reset ()
"Reset `hide-mode-line-mode' in the current buffer, if necessary.
Sometimes, a major mode is activated after `hide-mode-line-mode' is activated,
thus disabling it (because changing major modes invokes
`kill-all-local-variables' and specifically kills `mode-line-format's local
value, whether or not it's permanent-local.
Attach this to `after-change-major-mode-hook' and `hide-mode-line-mode' will be
cycled to fix this."
(when hide-mode-line-mode
(hide-mode-line-mode -1)
(hide-mode-line-mode +1)))

;;;###autoload
(define-globalized-minor-mode global-hide-mode-line-mode
Expand Down

0 comments on commit daa4908

Please sign in to comment.