summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-08-21 21:46:14 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-08-21 21:46:14 +0200
commit6ddcf67052545a0f77233f1a952dc90e296cda35 (patch)
tree68191dff374cc0c77974c382cb450b82aa2ad5a1
parent958924a8126cf532d44c4b446d13ed744438cc9b (diff)
downloademacs-6ddcf67052545a0f77233f1a952dc90e296cda35.tar.gz
emacs-6ddcf67052545a0f77233f1a952dc90e296cda35.tar.bz2
emacs-6ddcf67052545a0f77233f1a952dc90e296cda35.zip
Make it possible to mark generalized variables as obsolete
* doc/lispref/variables.texi (Adding Generalized Variables): Document it. * lisp/emacs-lisp/bytecomp.el (byte-compile-warn-obsolete): Alter the interface so that it can also be used by generalized variable warnings. (byte-compile-function-warn): Adjust caller. (byte-compile-check-variable): Adjust caller. * lisp/emacs-lisp/gv.el (gv-get): Warn about obsolete generalized variables (bug#49730). (make-obsolete-generalized-variable): New function.
-rw-r--r--doc/lispref/variables.texi10
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/emacs-lisp/byte-run.el1
-rw-r--r--lisp/emacs-lisp/bytecomp.el30
-rw-r--r--lisp/emacs-lisp/gv.el15
5 files changed, 48 insertions, 13 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 242b1a3be93..ed119a709c5 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2822,6 +2822,16 @@ expression manipulating @var{place} via @var{getter} and @var{setter}.
Consult the source file @file{gv.el} for more details.
+@defun make-obsolete-generalized-variable obsolete-name current-name when
+This function makes the byte compiler warn that the generalized
+variable @var{obsolete-name} is obsolete. If @var{current-name} is a
+symbol, then the warning message says to use @var{current-name}
+instead of @var{obsolete-name}. If @var{current-name} is a string,
+this is the message. @var{when} should be a string indicating when
+the variable was first made obsolete (usually a version number
+string).
+@end defun
+
@cindex CL note---no @code{setf} functions
@quotation
@b{Common Lisp note:} Common Lisp defines another way to specify the
diff --git a/etc/NEWS b/etc/NEWS
index c41b7ac6e82..2f68472163e 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2589,6 +2589,11 @@ patcomp.el, pc-mode.el, pc-select.el, s-region.el, and sregex.el.
* Lisp Changes in Emacs 29.1
+++
+** New function 'make-obsolete-generalized-variable'.
+This can be used to mark setters used by 'setf' as obsolete, and the
+byte-compiler will then warn about using them.
+
++++
** New functions 'pos-eol' and 'pos-bol'.
These are like 'line-end-position' and 'line-beginning-position'
(respectively), but ignore fields (and are more efficient).
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 4a2860cd43d..9a56ba0f7ad 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -568,7 +568,6 @@ ACCESS-TYPE if non-nil should specify the kind of access that will trigger
(purecopy (list current-name access-type when)))
obsolete-name)
-
(defmacro define-obsolete-variable-alias ( obsolete-name current-name when
&optional docstring)
"Make OBSOLETE-NAME a variable alias for CURRENT-NAME and mark it obsolete.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 1115ce391d4..5dde2d2bfbb 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -1355,16 +1355,22 @@ 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)))
-(defun byte-compile-warn-obsolete (symbol)
- "Warn that SYMBOL (a variable or function) is obsolete."
+(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."
(when (byte-compile-warning-enabled-p 'obsolete symbol)
- (let* ((funcp (get symbol 'byte-obsolete-info))
- (msg (macroexp--obsolete-warning
- symbol
- (or funcp (get symbol 'byte-obsolete-variable))
- (if funcp "function" "variable"))))
- (unless (and funcp (memq symbol byte-compile-not-obsolete-funcs))
- (byte-compile-warn-x symbol "%s" msg)))))
+ (byte-compile-warn-x
+ symbol "%s"
+ (macroexp--obsolete-warning
+ symbol
+ (pcase type
+ ("function"
+ (get symbol 'byte-obsolete-info))
+ ("variable"
+ (get symbol 'byte-obsolete-variable))
+ ("generalized variable"
+ (get symbol 'byte-obsolete-generalized-variable)))
+ type))))
(defun byte-compile-report-error (error-info &optional fill)
"Report Lisp error in compilation.
@@ -1468,8 +1474,8 @@ when printing the error message."
(defun byte-compile-function-warn (f nargs def)
(when (and (get f 'byte-obsolete-info)
- (byte-compile-warning-enabled-p 'obsolete f))
- (byte-compile-warn-obsolete f))
+ (not (memq f byte-compile-not-obsolete-funcs)))
+ (byte-compile-warn-obsolete f "function"))
;; Check to see if the function will be available at runtime
;; and/or remember its arity if it's unknown.
@@ -3604,7 +3610,7 @@ lambda-expression."
('set (not (eq access-type 'reference)))
('get (eq access-type 'reference))
(_ t))))
- (byte-compile-warn-obsolete var))))
+ (byte-compile-warn-obsolete var "variable"))))
(defsubst byte-compile-dynamic-variable-op (base-op var)
(let ((tmp (assq var byte-compile-variables)))
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index 54ddc7ac757..4618a349262 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -92,6 +92,9 @@ DO must return an Elisp expression."
(t
(let* ((head (car place))
(gf (function-get head 'gv-expander 'autoload)))
+ (when (and (symbolp head)
+ (get head 'byte-obsolete-generalized-variable))
+ (byte-compile-warn-obsolete head "generalized variable"))
(if gf (apply gf do (cdr place))
(let ((me (macroexpand-1 place
;; (append macroexpand-all-environment
@@ -616,6 +619,18 @@ 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)
(gv-define-setter buffer-modified-p (flag &optional buf)