From bfe222288e02472bff0e1ab5ba7ef26af6a2769a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 21 Aug 2022 23:38:09 +0200 Subject: [PATCH] Make the generalized buffer-local-variable obsolete * lisp/paren.el (show-paren-local-mode): * lisp/electric.el (electric-indent-local-mode) (electric-layout-local-mode, electric-quote-local-mode): * lisp/elec-pair.el (electric-pair-local-mode): Don't use it. * lisp/emacs-lisp/bytecomp.el (byte-compile-warn-obsolete): Autoload. * lisp/emacs-lisp/gv.el (buffer-local-variable): Make obsolete (bug#26624). * lisp/emacs-lisp/gv.el (make-obsolete-generalized-variable): Move to allow usage. --- lisp/elec-pair.el | 3 ++- lisp/electric.el | 9 ++++++--- lisp/emacs-lisp/bytecomp.el | 1 + lisp/emacs-lisp/gv.el | 25 +++++++++++++------------ lisp/paren.el | 3 ++- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index e5adb0dda73..2a53535405f 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -666,12 +666,13 @@ To toggle the mode in a single buffer, use `electric-pair-local-mode'." ;;;###autoload (define-minor-mode electric-pair-local-mode "Toggle `electric-pair-mode' only in this buffer." - :variable (buffer-local-value 'electric-pair-mode (current-buffer)) + :lighter nil (cond ((eq electric-pair-mode (default-value 'electric-pair-mode)) (kill-local-variable 'electric-pair-mode)) ((not (default-value 'electric-pair-mode)) ;; Locally enabled, but globally disabled. + (make-local-variable 'electric-pair-mode) (electric-pair-mode 1) ; Setup the hooks. (setq-default electric-pair-mode nil) ; But keep it globally disabled. ))) diff --git a/lisp/electric.el b/lisp/electric.el index f2ff837333f..ae9b5ee1622 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -340,12 +340,13 @@ use `electric-indent-local-mode'." ;;;###autoload (define-minor-mode electric-indent-local-mode "Toggle `electric-indent-mode' only in this buffer." - :variable (buffer-local-value 'electric-indent-mode (current-buffer)) + :lighter nil (cond ((eq electric-indent-mode (default-value 'electric-indent-mode)) (kill-local-variable 'electric-indent-mode)) ((not (default-value 'electric-indent-mode)) ;; Locally enabled, but globally disabled. + (make-local-variable 'electric-indent-mode) (electric-indent-mode 1) ; Setup the hooks. (setq-default electric-indent-mode nil) ; But keep it globally disabled. ))) @@ -484,12 +485,13 @@ The variable `electric-layout-rules' says when and how to insert newlines." ;;;###autoload (define-minor-mode electric-layout-local-mode "Toggle `electric-layout-mode' only in this buffer." - :variable (buffer-local-value 'electric-layout-mode (current-buffer)) + :lighter nil (cond ((eq electric-layout-mode (default-value 'electric-layout-mode)) (kill-local-variable 'electric-layout-mode)) ((not (default-value 'electric-layout-mode)) ;; Locally enabled, but globally disabled. + (make-local-variable 'electric-indent-mode) (electric-layout-mode 1) ; Setup the hooks. (setq-default electric-layout-mode nil) ; But keep it globally disabled. ))) @@ -661,12 +663,13 @@ use `electric-quote-local-mode'." ;;;###autoload (define-minor-mode electric-quote-local-mode "Toggle `electric-quote-mode' only in this buffer." - :variable (buffer-local-value 'electric-quote-mode (current-buffer)) + :lighter nil (cond ((eq electric-quote-mode (default-value 'electric-quote-mode)) (kill-local-variable 'electric-quote-mode)) ((not (default-value 'electric-quote-mode)) ;; Locally enabled, but globally disabled. + (make-local-variable 'electric-indent-mode) (electric-quote-mode 1) ; Setup the hooks. (setq-default electric-quote-mode nil) ; But keep it globally disabled. ))) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 5dde2d2bfbb..ebc9aa75e56 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -1355,6 +1355,7 @@ FORMAT and ARGS are as in `byte-compile-warn'." (let ((byte-compile-form-stack (cons arg byte-compile-form-stack))) (apply #'byte-compile-warn format args))) +;;;###autoload (defun byte-compile-warn-obsolete (symbol type) "Warn that SYMBOL (a variable, function or generalized variable) is obsolete. TYPE is a string that say which one of these three types it is." diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 0c374ec5e37..db902d9db8c 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -141,6 +141,18 @@ all the parts of PLACE that can be evaluated and then runs E. (declare (indent 2) (debug (sexp form def-body))) `(gv-get ,place (lambda ,vars ,@body))) +(defun make-obsolete-generalized-variable (obsolete-name current-name when) + "Make byte-compiler warn that generalized variable OBSOLETE-NAME is obsolete. +The warning will say that CURRENT-NAME should be used instead. + +If CURRENT-NAME is a string, that is the `use instead' message. + +WHEN should be a string indicating when the variable was first +made obsolete, for example a date or a release number." + (put obsolete-name 'byte-obsolete-generalized-variable + (purecopy (list current-name when))) + obsolete-name) + ;; Different ways to declare a generalized variable. ;;;###autoload (defmacro gv-define-expander (name handler) @@ -395,6 +407,7 @@ The return value is the last VAL in the list. (gv-define-setter buffer-local-value (val var buf) (macroexp-let2 nil v val `(with-current-buffer ,buf (set (make-local-variable ,var) ,v)))) +(make-obsolete-generalized-variable 'buffer-local-value nil "29.1") (gv-define-expander alist-get (lambda (do key alist &optional default remove testfn) @@ -619,18 +632,6 @@ REF must have been previously obtained with `gv-ref'." ;;; Generalized variables. -(defun make-obsolete-generalized-variable (obsolete-name current-name when) - "Make byte-compiler warn that generalized variable OBSOLETE-NAME is obsolete. -The warning will say that CURRENT-NAME should be used instead. - -If CURRENT-NAME is a string, that is the `use instead' message. - -WHEN should be a string indicating when the variable was first -made obsolete, for example a date or a release number." - (put obsolete-name 'byte-obsolete-generalized-variable - (purecopy (list current-name when))) - obsolete-name) - ;; Some Emacs-related place types. (gv-define-simple-setter buffer-file-name set-visited-file-name t) (make-obsolete-generalized-variable diff --git a/lisp/paren.el b/lisp/paren.el index 4c268dbf771..5a73e3fce69 100644 --- a/lisp/paren.el +++ b/lisp/paren.el @@ -149,7 +149,7 @@ use `show-paren-local-mode'." ;;;###autoload (define-minor-mode show-paren-local-mode "Toggle `show-paren-mode' only in this buffer." - :variable (buffer-local-value 'show-paren-mode (current-buffer)) + :lighter nil (cond ((eq show-paren-mode (default-value 'show-paren-mode)) (unless show-paren-mode @@ -157,6 +157,7 @@ use `show-paren-local-mode'." (kill-local-variable 'show-paren-mode)) ((not (default-value 'show-paren-mode)) ;; Locally enabled, but globally disabled. + (make-local-variable 'show-paren-mode) (show-paren-mode 1) ; Setup the timer. (setq-default show-paren-mode nil) ; But keep it globally disabled. )