From 58473dc6608fcfb1ce66e8f540bd804a70813246 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Sun, 31 Jan 2021 19:46:20 +0100 Subject: [PATCH] Prefer defvar-local in preloaded files * lisp/abbrev.el: * lisp/bindings.el (mode-line-mule-info, mode-line-modified) (mode-line-remote, mode-line-process) (mode-line-buffer-identification): * lisp/buff-menu.el (Buffer-menu-files-only): * lisp/files.el (buffer-file-number, buffer-file-read-only) (local-write-file-hooks, write-contents-functions) (file-local-variables-alist, dir-local-variables-alist) (save-buffer-coding-system, buffer-save-without-query): * lisp/font-core.el (font-lock-defaults): * lisp/font-lock.el (font-lock-keywords-case-fold-search) (font-lock-syntactically-fontified) (font-lock-extend-after-change-region-function) (font-lock-extend-region-functions, font-lock-major-mode): * lisp/menu-bar.el (list-buffers-directory): * lisp/simple.el (next-error--message-highlight-overlay) (next-error-buffer, next-error-function) (next-error-move-function, goto-line-history) (minibuffer-default-add-done, undo-extra-outer-limit): * lisp/tab-bar.el (tab-switcher-column): * lisp/term/ns-win.el (ns-select-overlay): * lisp/window.el (window-size-fixed, window-area-factor) (window-group-start-function, window-group-end-function) (set-window-group-start-function) (recenter-window-group-function) (pos-visible-in-window-group-p-function) (selected-window-group-function) (move-to-window-group-line-function): Prefer defvar-local. --- lisp/abbrev.el | 3 +-- lisp/bindings.el | 15 +++++---------- lisp/buff-menu.el | 3 +-- lisp/files.el | 24 ++++++++---------------- lisp/font-core.el | 3 +-- lisp/font-lock.el | 15 +++++---------- lisp/menu-bar.el | 3 +-- lisp/simple.el | 22 +++++++--------------- lisp/tab-bar.el | 3 +-- lisp/term/ns-win.el | 3 +-- lisp/window.el | 27 +++++++++------------------ 11 files changed, 40 insertions(+), 81 deletions(-) diff --git a/lisp/abbrev.el b/lisp/abbrev.el index 65f71183856..54783db2c3e 100644 --- a/lisp/abbrev.el +++ b/lisp/abbrev.el @@ -516,9 +516,8 @@ It is nil if the abbrev has already been unexpanded.") (defvar last-abbrev-location 0 "The location of the start of the last abbrev expanded.") -;; (defvar local-abbrev-table fundamental-mode-abbrev-table +;; (defvar-local local-abbrev-table fundamental-mode-abbrev-table ;; "Local (mode-specific) abbrev table of current buffer.") -;; (make-variable-buffer-local 'local-abbrev-table) (defun clear-abbrev-table (table) "Undefine all abbrevs in abbrev table TABLE, leaving it empty." diff --git a/lisp/bindings.el b/lisp/bindings.el index 187444af664..43b62f9bbfc 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -199,7 +199,7 @@ mouse-3: Set coding system" (symbol-name buffer-file-coding-system)) "Buffer coding system: none specified"))) -(defvar mode-line-mule-info +(defvar-local mode-line-mule-info `("" (current-input-method (:propertize ("" current-input-method-title) @@ -225,7 +225,6 @@ mnemonics of the following coding systems: coding system for terminal output (on a text terminal)") ;;;###autoload (put 'mode-line-mule-info 'risky-local-variable t) -(make-variable-buffer-local 'mode-line-mule-info) (defvar mode-line-client `("" @@ -247,7 +246,7 @@ mnemonics of the following coding systems: (format "Buffer is %smodified\nmouse-1: Toggle modification state" (if (buffer-modified-p (window-buffer window)) "" "not "))) -(defvar mode-line-modified +(defvar-local mode-line-modified (list (propertize "%1*" 'help-echo 'mode-line-read-only-help-echo @@ -264,9 +263,8 @@ mnemonics of the following coding systems: "Mode line construct for displaying whether current buffer is modified.") ;;;###autoload (put 'mode-line-modified 'risky-local-variable t) -(make-variable-buffer-local 'mode-line-modified) -(defvar mode-line-remote +(defvar-local mode-line-remote (list (propertize "%1@" 'mouse-face 'mode-line-highlight @@ -283,7 +281,6 @@ mnemonics of the following coding systems: "Mode line construct to indicate a remote buffer.") ;;;###autoload (put 'mode-line-remote 'risky-local-variable t) -(make-variable-buffer-local 'mode-line-remote) ;; MSDOS frames have window-system, but want the Fn identification. (defun mode-line-frame-control () @@ -301,12 +298,11 @@ Value is used for `mode-line-frame-identification', which see." ;;;###autoload (put 'mode-line-frame-identification 'risky-local-variable t) -(defvar mode-line-process nil +(defvar-local mode-line-process nil "Mode line construct for displaying info on process status. Normally nil in most modes, since there is no process to display.") ;;;###autoload (put 'mode-line-process 'risky-local-variable t) -(make-variable-buffer-local 'mode-line-process) (defun bindings--define-key (map key item) "Define KEY in keymap MAP according to ITEM from a menu. @@ -543,7 +539,7 @@ mouse-1: Previous buffer\nmouse-3: Next buffer") 'mouse-face 'mode-line-highlight 'local-map mode-line-buffer-identification-keymap))) -(defvar mode-line-buffer-identification +(defvar-local mode-line-buffer-identification (propertized-buffer-identification "%12b") "Mode line construct for identifying the buffer being displayed. Its default value is (\"%12b\") with some text properties added. @@ -551,7 +547,6 @@ Major modes that edit things other than ordinary files may change this \(e.g. Info, Dired,...)") ;;;###autoload (put 'mode-line-buffer-identification 'risky-local-variable t) -(make-variable-buffer-local 'mode-line-buffer-identification) (defvar mode-line-misc-info '((global-mode-string ("" global-mode-string " "))) diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el index 49f8604f52e..bb39e1f5795 100644 --- a/lisp/buff-menu.el +++ b/lisp/buff-menu.el @@ -111,11 +111,10 @@ as it is by default." :group 'Buffer-menu :version "22.1") -(defvar Buffer-menu-files-only nil +(defvar-local Buffer-menu-files-only nil "Non-nil if the current Buffer Menu lists only file buffers. This is set by the prefix argument to `buffer-menu' and related commands.") -(make-variable-buffer-local 'Buffer-menu-files-only) (defvar Buffer-menu-mode-map (let ((map (make-sparse-keymap)) diff --git a/lisp/files.el b/lisp/files.el index 77e3a3a834c..dada69c1457 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -191,20 +191,18 @@ if the file has changed on disk and you have not edited the buffer." :type '(repeat regexp) :group 'find-file) -(defvar buffer-file-number nil +(defvar-local buffer-file-number nil "The device number and file number of the file visited in the current buffer. The value is a list of the form (FILENUM DEVNUM). This pair of numbers uniquely identifies the file. If the buffer is visiting a new file, the value is nil.") -(make-variable-buffer-local 'buffer-file-number) (put 'buffer-file-number 'permanent-local t) (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) "Non-nil means that `buffer-file-number' uniquely identifies files.") -(defvar buffer-file-read-only nil +(defvar-local buffer-file-read-only nil "Non-nil if visited file was read-only when visited.") -(make-variable-buffer-local 'buffer-file-read-only) (defcustom small-temporary-file-directory (if (eq system-type 'ms-dos) (getenv "TMPDIR")) @@ -529,15 +527,14 @@ updates before the buffer is saved, use `before-save-hook'.") (put 'write-file-functions 'permanent-local t) ;; I found some files still using the obsolete form in 2018. -(defvar local-write-file-hooks nil) -(make-variable-buffer-local 'local-write-file-hooks) +(defvar-local local-write-file-hooks nil) (put 'local-write-file-hooks 'permanent-local t) (make-obsolete-variable 'local-write-file-hooks 'write-file-functions "22.1") ;; I found some files still using the obsolete form in 2018. (define-obsolete-variable-alias 'write-contents-hooks 'write-contents-functions "22.1") -(defvar write-contents-functions nil +(defvar-local write-contents-functions nil "List of functions to be called before writing out a buffer to a file. Used only by `save-buffer'. If one of them returns non-nil, the @@ -556,7 +553,6 @@ For hooks that _do_ pertain to the particular visited file, use `write-file-functions' relate to how a buffer is saved to file. To perform various checks or updates before the buffer is saved, use `before-save-hook'.") -(make-variable-buffer-local 'write-contents-functions) (defcustom enable-local-variables t "Control use of local variables in files you visit. @@ -3443,23 +3439,21 @@ asking you for confirmation." (put 'c-set-style 'safe-local-eval-function t) -(defvar file-local-variables-alist nil +(defvar-local file-local-variables-alist nil "Alist of file-local variable settings in the current buffer. Each element in this list has the form (VAR . VALUE), where VAR is a file-local variable (a symbol) and VALUE is the value specified. The actual value in the buffer may differ from VALUE, if it is changed by the major or minor modes, or by the user.") -(make-variable-buffer-local 'file-local-variables-alist) (put 'file-local-variables-alist 'permanent-local t) -(defvar dir-local-variables-alist nil +(defvar-local dir-local-variables-alist nil "Alist of directory-local variable settings in the current buffer. Each element in this list has the form (VAR . VALUE), where VAR is a directory-local variable (a symbol) and VALUE is the value specified in .dir-locals.el. The actual value in the buffer may differ from VALUE, if it is changed by the major or minor modes, or by the user.") -(make-variable-buffer-local 'dir-local-variables-alist) (defvar before-hack-local-variables-hook nil "Normal hook run before setting file-local variables. @@ -5233,7 +5227,7 @@ Used only by `save-buffer'." :type 'hook :group 'files) -(defvar save-buffer-coding-system nil +(defvar-local save-buffer-coding-system nil "If non-nil, use this coding system for saving the buffer. More precisely, use this coding system in place of the value of `buffer-file-coding-system', when saving the buffer. @@ -5241,7 +5235,6 @@ Calling `write-region' for any purpose other than saving the buffer will still use `buffer-file-coding-system'; this variable has no effect in such cases.") -(make-variable-buffer-local 'save-buffer-coding-system) (put 'save-buffer-coding-system 'permanent-local t) (defun basic-save-buffer (&optional called-interactively) @@ -5510,9 +5503,8 @@ Before and after saving the buffer, this function runs "ACTION-ALIST argument used in call to `map-y-or-n-p'.") (put 'save-some-buffers-action-alist 'risky-local-variable t) -(defvar buffer-save-without-query nil +(defvar-local buffer-save-without-query nil "Non-nil means `save-some-buffers' should save this buffer without asking.") -(make-variable-buffer-local 'buffer-save-without-query) (defcustom save-some-buffers-default-predicate nil "Default predicate for `save-some-buffers'. diff --git a/lisp/font-core.el b/lisp/font-core.el index 0f1a3d1c364..4b695424977 100644 --- a/lisp/font-core.el +++ b/lisp/font-core.el @@ -26,7 +26,7 @@ ;; This variable is used by mode packages that support Font Lock mode by ;; defining their own keywords to use for `font-lock-keywords'. (The mode ;; command should make it buffer-local and set it to provide the set up.) -(defvar font-lock-defaults nil +(defvar-local font-lock-defaults nil "Defaults for Font Lock mode specified by the major mode. Defaults should be of the form: @@ -66,7 +66,6 @@ functions, `font-lock-fontify-buffer-function', `font-lock-unfontify-region-function', and `font-lock-inhibit-thing-lock'.") ;;;###autoload (put 'font-lock-defaults 'risky-local-variable t) -(make-variable-buffer-local 'font-lock-defaults) (defvar font-lock-function 'font-lock-default-function "A function which is called when `font-lock-mode' is toggled. diff --git a/lisp/font-lock.el b/lisp/font-lock.el index a9fc69d419a..c344a612581 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -515,17 +515,15 @@ This is normally set via `font-lock-add-keywords' and "Non-nil means Font Lock should not fontify comments or strings. This is normally set via `font-lock-defaults'.") -(defvar font-lock-keywords-case-fold-search nil +(defvar-local font-lock-keywords-case-fold-search nil "Non-nil means the patterns in `font-lock-keywords' are case-insensitive. This is set via the function `font-lock-set-defaults', based on the CASE-FOLD argument of `font-lock-defaults'.") -(make-variable-buffer-local 'font-lock-keywords-case-fold-search) -(defvar font-lock-syntactically-fontified 0 +(defvar-local font-lock-syntactically-fontified 0 "Point up to which `font-lock-syntactic-keywords' has been applied. If nil, this is ignored, in which case the syntactic fontification may sometimes be slightly incorrect.") -(make-variable-buffer-local 'font-lock-syntactically-fontified) (defvar font-lock-syntactic-face-function (lambda (state) @@ -1026,7 +1024,7 @@ The value of this variable is used when Font Lock mode is turned on." ;; directives correctly and cleanly. (It is the same problem as fontifying ;; multi-line strings and comments; regexps are not appropriate for the job.) -(defvar font-lock-extend-after-change-region-function nil +(defvar-local font-lock-extend-after-change-region-function nil "A function that determines the region to refontify after a change. This variable is either nil, or is a function that determines the @@ -1040,7 +1038,6 @@ and end buffer positions \(in that order) of the region to refontify, or nil \(which directs the caller to fontify a default region). This function should preserve the match-data. The region it returns may start or end in the middle of a line.") -(make-variable-buffer-local 'font-lock-extend-after-change-region-function) (defun font-lock-fontify-buffer (&optional interactively) "Fontify the current buffer the way the function `font-lock-mode' would." @@ -1159,7 +1156,7 @@ a very meaningful entity to highlight.") (defvar font-lock-beg) (defvar font-lock-end) -(defvar font-lock-extend-region-functions +(defvar-local font-lock-extend-region-functions '(font-lock-extend-region-wholelines ;; This use of font-lock-multiline property is unreliable but is just ;; a handy heuristic: in case you don't have a function that does @@ -1181,7 +1178,6 @@ These functions are run in turn repeatedly until they all return nil. Put first the functions more likely to cause a change and cheaper to compute.") ;; Mark it as a special hook which doesn't use any global setting ;; (i.e. doesn't obey the element t in the buffer-local value). -(make-variable-buffer-local 'font-lock-extend-region-functions) (defun font-lock-extend-region-multiline () "Move fontification boundaries away from any `font-lock-multiline' property." @@ -1888,9 +1884,8 @@ preserve `hi-lock-mode' highlighting patterns." (kill-local-variable 'font-lock-set-defaults) (font-lock-mode 1)) -(defvar font-lock-major-mode nil +(defvar-local font-lock-major-mode nil "Major mode for which the font-lock settings have been setup.") -(make-variable-buffer-local 'font-lock-major-mode) (defun font-lock-set-defaults () "Set fontification defaults appropriately for this mode. diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 526491f0272..2fdfcc8b582 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2240,9 +2240,8 @@ Buffers menu is regenerated." :type 'boolean :group 'menu) -(defvar list-buffers-directory nil +(defvar-local list-buffers-directory nil "String to display in buffer listings for buffers not visiting a file.") -(make-variable-buffer-local 'list-buffers-directory) (defun menu-bar-select-buffer () (interactive) diff --git a/lisp/simple.el b/lisp/simple.el index 742fc5004dc..e4a363a9a59 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -134,10 +134,9 @@ messages are highlighted; this helps to see what messages were visited." :group 'next-error :version "28.1") -(defvar next-error--message-highlight-overlay +(defvar-local next-error--message-highlight-overlay nil "Overlay highlighting the current error message in the `next-error' buffer.") -(make-variable-buffer-local 'next-error--message-highlight-overlay) (defcustom next-error-hook nil "List of hook functions run by `next-error' after visiting source file." @@ -165,15 +164,14 @@ A buffer becomes most recent when its compilation, grep, or similar mode is started, or when it is used with \\[next-error] or \\[compile-goto-error].") -(defvar next-error-buffer nil +(defvar-local next-error-buffer nil "The buffer-local value of the most recent `next-error' buffer.") ;; next-error-buffer is made buffer-local to keep the reference ;; to the parent buffer used to navigate to the current buffer, so the ;; next call of next-buffer will use the same parent buffer to ;; continue navigation from it. -(make-variable-buffer-local 'next-error-buffer) -(defvar next-error-function nil +(defvar-local next-error-function nil "Function to use to find the next error in the current buffer. The function is called with 2 parameters: ARG is an integer specifying by how many errors to move. @@ -182,15 +180,13 @@ of the errors before moving. Major modes providing compile-like functionality should set this variable to indicate to `next-error' that this is a candidate buffer and how to navigate in it.") -(make-variable-buffer-local 'next-error-function) -(defvar next-error-move-function nil +(defvar-local next-error-move-function nil "Function to use to move to an error locus. It takes two arguments, a buffer position in the error buffer and a buffer position in the error locus buffer. The buffer for the error locus should already be current. nil means use goto-char using the second argument position.") -(make-variable-buffer-local 'next-error-move-function) (defsubst next-error-buffer-p (buffer &optional avoid-current @@ -1268,9 +1264,8 @@ that uses or sets the mark." ;; Counting lines, one way or another. -(defvar goto-line-history nil +(defvar-local goto-line-history nil "History of values entered with `goto-line'.") -(make-variable-buffer-local 'goto-line-history) (defun goto-line-read-args (&optional relative) "Read arguments for `goto-line' related commands." @@ -2309,14 +2304,12 @@ once. In special cases, when this function needs to be called more than once, it can set `minibuffer-default-add-done' to nil explicitly, overriding the setting of this variable to t in `goto-history-element'.") -(defvar minibuffer-default-add-done nil +(defvar-local minibuffer-default-add-done nil "When nil, add more elements to the end of the list of default values. The value nil causes `goto-history-element' to add more elements to the list of defaults when it reaches the end of this list. It does this by calling a function defined by `minibuffer-default-add-function'.") -(make-variable-buffer-local 'minibuffer-default-add-done) - (defun minibuffer-default-add-completions () "Return a list of all completions without the default value. This function is used to add all elements of the completion table to @@ -3480,13 +3473,12 @@ excessively long before answering the question." :group 'undo :version "22.1") -(defvar undo-extra-outer-limit nil +(defvar-local undo-extra-outer-limit nil "If non-nil, an extra level of size that's ok in an undo item. We don't ask the user about truncating the undo list until the current item gets bigger than this amount. This variable matters only if `undo-ask-before-discard' is non-nil.") -(make-variable-buffer-local 'undo-extra-outer-limit) ;; When the first undo batch in an undo list is longer than ;; undo-outer-limit, this function gets called to warn the user that diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 7e556550daa..6720d82b471 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1308,8 +1308,7 @@ For more information, see the function `tab-switcher'." (setq buffer-read-only t) (current-buffer)))) -(defvar tab-switcher-column 3) -(make-variable-buffer-local 'tab-switcher-column) +(defvar-local tab-switcher-column 3) (defvar tab-switcher-mode-map (let ((map (make-keymap))) diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index 94e9d5c5828..af1e388c2a3 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -374,9 +374,8 @@ prompting. If file is a directory perform a `find-file' on it." (find-file f) (push-mark (+ (point) (cadr (insert-file-contents f))))))) -(defvar ns-select-overlay nil +(defvar-local ns-select-overlay nil "Overlay used to highlight areas in files requested by Nextstep apps.") -(make-variable-buffer-local 'ns-select-overlay) (defvar ns-input-line) ; nsterm.m diff --git a/lisp/window.el b/lisp/window.el index d5876914201..8905d4a826e 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -1500,7 +1500,7 @@ otherwise." (window-pixel-height window) (window-total-height window round)))) -(defvar window-size-fixed nil +(defvar-local window-size-fixed nil "Non-nil in a buffer means windows displaying the buffer are fixed-size. If the value is `height', then only the window's height is fixed. If the value is `width', then only the window's width is fixed. @@ -1509,7 +1509,6 @@ Any other non-nil value fixes both the width and the height. Emacs won't change the size of any window displaying that buffer, unless it has no other choice (like when deleting a neighboring window).") -(make-variable-buffer-local 'window-size-fixed) (defun window--preservable-size (window &optional horizontal) "Return height of WINDOW as `window-preserve-size' would preserve it. @@ -5753,11 +5752,10 @@ nil (i.e. any), `height' or `width'." '((height . width) (width . height)))))))) ;;; A different solution to balance-windows. -(defvar window-area-factor 1 +(defvar-local window-area-factor 1 "Factor by which the window area should be over-estimated. This is used by `balance-windows-area'. Changing this globally has no effect.") -(make-variable-buffer-local 'window-area-factor) (defun balance-windows-area-adjust (window delta horizontal pixelwise) "Wrapper around `window-resize' with error checking. @@ -9580,8 +9578,7 @@ buffers displaying right to left text." ;; status is undone only when explicitly programmed, not when a buffer ;; is reverted or a mode function is called. -(defvar window-group-start-function nil) -(make-variable-buffer-local 'window-group-start-function) +(defvar-local window-group-start-function nil) (put 'window-group-start-function 'permanent-local t) (defun window-group-start (&optional window) "Return position at which display currently starts in the group of @@ -9594,8 +9591,7 @@ This is updated by redisplay or by calling `set-window*-start'." (funcall window-group-start-function window) (window-start window))) -(defvar window-group-end-function nil) -(make-variable-buffer-local 'window-group-end-function) +(defvar-local window-group-end-function nil) (put 'window-group-end-function 'permanent-local t) (defun window-group-end (&optional window update) "Return position at which display currently ends in the group of @@ -9614,8 +9610,7 @@ if it isn't already recorded." (funcall window-group-end-function window update) (window-end window update))) -(defvar set-window-group-start-function nil) -(make-variable-buffer-local 'set-window-group-start-function) +(defvar-local set-window-group-start-function nil) (put 'set-window-group-start-function 'permanent-local t) (defun set-window-group-start (window pos &optional noforce) "Make display in the group of windows containing WINDOW start at @@ -9629,8 +9624,7 @@ overriding motion of point in order to display at this exact start." (funcall set-window-group-start-function window pos noforce) (set-window-start window pos noforce))) -(defvar recenter-window-group-function nil) -(make-variable-buffer-local 'recenter-window-group-function) +(defvar-local recenter-window-group-function nil) (put 'recenter-window-group-function 'permanent-local t) (defun recenter-window-group (&optional arg) "Center point in the group of windows containing the selected window @@ -9656,8 +9650,7 @@ and redisplay normally--don't erase and redraw the frame." (funcall recenter-window-group-function arg) (recenter arg))) -(defvar pos-visible-in-window-group-p-function nil) -(make-variable-buffer-local 'pos-visible-in-window-group-p-function) +(defvar-local pos-visible-in-window-group-p-function nil) (put 'pos-visible-in-window-group-p-function 'permanent-local t) (defun pos-visible-in-window-group-p (&optional pos window partially) "Return non-nil if position POS is currently on the frame in the @@ -9687,8 +9680,7 @@ POS, ROWH is the visible height of that row, and VPOS is the row number (funcall pos-visible-in-window-group-p-function pos window partially) (pos-visible-in-window-p pos window partially))) -(defvar selected-window-group-function nil) -(make-variable-buffer-local 'selected-window-group-function) +(defvar-local selected-window-group-function nil) (put 'selected-window-group-function 'permanent-local t) (defun selected-window-group () "Return the list of windows in the group containing the selected window. @@ -9698,8 +9690,7 @@ result is a list containing only the selected window." (funcall selected-window-group-function) (list (selected-window)))) -(defvar move-to-window-group-line-function nil) -(make-variable-buffer-local 'move-to-window-group-line-function) +(defvar-local move-to-window-group-line-function nil) (put 'move-to-window-group-line-function 'permanent-local t) (defun move-to-window-group-line (arg) "Position point relative to the current group of windows. -- 2.39.2