From 419fe81ab759823d43204d706d1e05df4b0e7052 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 29 Oct 2020 18:27:56 +0100 Subject: [PATCH] Make text-scale-mode optionally adjust header line face * lisp/face-remap.el (text-scale-remap-header-line-face): New buffer local variable. (text-scale-mode): Also adjust header-line face if above new variable is non-nil. (face-remap--clear-remappings, face-remap--remap-face): New functions. (text-scale-mode--remappings): New variable. (text-scale-mode-remapping): Make into obsolete variable alias for above new variable. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-mode): Use text-scale-remap-header-line-face. --- etc/NEWS | 15 +++++++++ lisp/emacs-lisp/tabulated-list.el | 1 + lisp/face-remap.el | 51 +++++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 4b1272d18b..f514133680 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1368,6 +1368,21 @@ mouse now pops up a TTY menu by default instead of running the command 'tmm-menubar'. To restore the old behavior, set the variable 'tty-menu-open-use-tmm' to non-nil. +** text-scale-mode + +--- +*** text-scale-mode can now adjust font size of the 'header-line' face. +When the new buffer local variable 'text-scale-mode-header-line' is +non-nil, 'text-scale-adjust' (bound to 'C-x C-+' and 'C-x C--' by +default) will also change the text height of the 'header-line' face. +This will also affect any face that inherits from it. + +This feature is intended for use by Emacs Lisp package authors in +major modes that arrange their display in tabular form below the +header-line. It is enabled in 'tabulated-list-mode' and its derived +modes (such as the modes used by 'list-packages', 'list-buffers' and +'bookmark-bmenu-list'). + ** xwidget-webkit mode *** New xwidget commands. diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el index b13f609f88..18b48edc4f 100644 --- a/lisp/emacs-lisp/tabulated-list.el +++ b/lisp/emacs-lisp/tabulated-list.el @@ -761,6 +761,7 @@ tabulated-list-mode (setq-local revert-buffer-function #'tabulated-list-revert) (setq-local glyphless-char-display (tabulated-list-make-glyphless-char-display-table)) + (setq-local text-scale-remap-header-line-face t) ;; Avoid messing up the entries' display just because the first ;; column of the first entry happens to begin with a R2L letter. (setq bidi-paragraph-direction 'left-to-right) diff --git a/lisp/face-remap.el b/lisp/face-remap.el index 028269a4b0..e61fa4cb4e 100644 --- a/lisp/face-remap.el +++ b/lisp/face-remap.el @@ -219,7 +219,11 @@ text-scale-mode-step ;; current remapping cookie for text-scale-mode (defvar text-scale-mode-remapping nil) -(make-variable-buffer-local 'text-scale-mode-remapping) +(make-obsolete-variable 'text-scale-mode-remapping + 'text-scale-mode--remappings "28.1") + +(defvar text-scale-mode--remappings nil + "List of current remapping cookies for `text-scale-mode'.") ;; Lighter displayed for text-scale-mode in mode-line minor-mode list (defvar text-scale-mode-lighter "+0") @@ -229,6 +233,32 @@ text-scale-mode-lighter (defvar text-scale-mode-amount 0) (make-variable-buffer-local 'text-scale-mode-amount) +(defvar text-scale-remap-header-line-face nil + "If non-nil, also change font size of the `header-line' face. +This will also affect any face that inherits from +`header-line'.") +(make-variable-buffer-local 'text-scale-header-line) + +(defun face-remap--clear-remappings () + (dolist (remapping + ;; This is a bit messy to stay backwards compatible. + ;; In the future, this can be simplified to just use + ;; `text-scale-mode--remappings'. + (if (consp (car-safe text-scale-mode--remappings)) + text-scale-mode--remappings + (cons text-scale-mode-remapping + text-scale-mode--remappings))) + (face-remap-remove-relative remapping)) + (setq text-scale-mode-remapping nil) ; backwards-compatibility + (setq text-scale-mode--remappings nil)) + +(defun face-remap--remap-face (sym) + (push (face-remap-add-relative sym + :height + (expt text-scale-mode-step + text-scale-mode-amount)) + text-scale-mode--remappings)) + (define-minor-mode text-scale-mode "Minor mode for displaying buffer text in a larger/smaller font. @@ -240,19 +270,20 @@ text-scale-mode The `text-scale-increase', `text-scale-decrease', and `text-scale-set' functions may be used to interactively modify the variable `text-scale-mode-amount' (they also enable or -disable `text-scale-mode' as necessary)." +disable `text-scale-mode' as necessary). + +If `text-scale-remap-header-line-face' is non-nil, also change +the font size of the `header-line' face (and any face that +inherits from it)." :lighter (" " text-scale-mode-lighter) - (when text-scale-mode-remapping - (face-remap-remove-relative text-scale-mode-remapping)) + (face-remap--clear-remappings) (setq text-scale-mode-lighter (format (if (>= text-scale-mode-amount 0) "+%d" "%d") text-scale-mode-amount)) - (setq text-scale-mode-remapping - (and text-scale-mode - (face-remap-add-relative 'default - :height - (expt text-scale-mode-step - text-scale-mode-amount)))) + (when text-scale-mode + (face-remap--remap-face 'default) + (when text-scale-remap-header-line-face + (face-remap--remap-face 'header-line))) (force-window-update (current-buffer))) (defun text-scale-min-amount () -- 2.28.0