From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Damien Cassou <damien@cassou.me>
Cc: 30039@debbugs.gnu.org, Nicolas Petton <nicolas@petton.fr>
Subject: bug#30039: 26.0.90; [26.1] Making my code warning free is impossible with when-let
Date: Fri, 19 Jan 2018 15:00:30 -0500 [thread overview]
Message-ID: <CAM-tV-89Uf+CAXipPMqFgwjhp2DZC1dVz7Y_SftCt=27GJ+emA@mail.gmail.com> (raw)
In-Reply-To: <87o9m0u4zz.fsf@cassou.me>
[-- Attachment #1: Type: text/plain, Size: 667 bytes --]
On Thu, Jan 11, 2018 at 4:19 AM, Damien Cassou <damien@cassou.me> wrote:
> Noam Postavsky <npostavs@users.sourceforge.net> writes:
>> How about adding a variable which suppresses deprecation warnings from
>> a specified version and up. Attached is a work-in-progress patch which
>> would allow you to set byte-compile-not-obsolete-since to "25.1" in
>> your CI script (or file-locally) and thus ignore deprecation warnings
>> from 26.1 or newer.
>
> that’s a nice workaround. Is it too late for an inclusion in 26.1? I
> guess what I’m really after is a configurable lint tool…
Here's a finished version of the patch. Eli, is it okay for emacs-26?
[-- Attachment #2: v2-0001-Allow-suppressing-obsoletion-warnings-per-version.patch --]
[-- Type: application/octet-stream, Size: 7438 bytes --]
From eda75474d4216b1f03c901dd77bf03bd7dd7eee0 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Wed, 10 Jan 2018 14:07:27 -0500
Subject: [PATCH v2] Allow suppressing obsoletion warnings per-version
(Bug#30039)
* lisp/emacs-lisp/bytecomp.el (byte-compile-not-obsolete-since): New
variable.
(byte-compile-obsolete-p): New function, extracted from
byte-compile-warn-obsolete, consult the new variable.
* lisp/emacs-lisp/macroexp.el (macroexp-macroexpand): Use the new
function.
* etc/NEWS: Announce `byte-compile-not-obsolete-since'.
* test/lisp/emacs-lisp/bytecomp-tests.el
(byte-compile-not-obsolete-since): New test.
---
etc/NEWS | 5 +++++
lisp/emacs-lisp/bytecomp.el | 40 +++++++++++++++++++++++++++-------
lisp/emacs-lisp/macroexp.el | 16 ++++++++------
test/lisp/emacs-lisp/bytecomp-tests.el | 31 ++++++++++++++++++++++++++
4 files changed, 77 insertions(+), 15 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index b4c489c..7983ea3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1613,6 +1613,11 @@ which means ask about all file-visiting buffers.
---
** string-(to|as|make)-(uni|multi)byte are now declared obsolete.
+---
+** New variable 'byte-compile-not-obsolete-since'.
+It may be used to suppress obsoletion warnings later than some
+specified version.
+
+++
** New variable 'while-no-input-ignore-events' which allow
setting which special events 'while-no-input' should ignore.
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index acba9e2..eae43e7 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -392,6 +392,18 @@ byte-compile-global-not-obsolete-vars
(defvar byte-compile-not-obsolete-funcs nil
"List of functions that shouldn't be reported as obsolete.")
+(defvar byte-compile-not-obsolete-since nil
+ "Disable obsoletion warnings later than specified version.
+For example, if set to \"25.1\", a function marked as obsolete
+\"since 26.1\" will not be reported as obsolete. If nil, then
+all obsoletion warnings are enabled (as long as they are not
+already suppressed via `byte-compile-warnings',
+`byte-compile-not-obsolete-funcs', or
+`byte-compile-not-obsolete-vars').")
+
+;;;###autoload
+(put 'byte-compile-not-obsolete-since 'safe-local-variable #'stringp)
+
(defcustom byte-compile-generate-call-tree nil
"Non-nil means collect call-graph information when compiling.
This records which functions were called and from where.
@@ -1239,16 +1251,28 @@ byte-compile-warn
(error "%s" format) ; byte-compile-file catches and logs it
(byte-compile-log-warning format t :warning)))
-(defun byte-compile-warn-obsolete (symbol)
- "Warn that SYMBOL (a variable or function) is obsolete."
+(defun byte-compile-obsolete-p (symbol)
+ "Return obsoletion message if SYMBOL is obsolete, nil otherwise.
+Consult `byte-compile-warnings',
+`byte-compile-not-obsolete-funcs' and
+`byte-compile-not-obsolete-since'."
(when (byte-compile-warning-enabled-p 'obsolete)
(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 "%s" msg)))))
+ (var-info (get symbol 'byte-obsolete-variable)))
+ (unless (or (and funcp (memq symbol byte-compile-not-obsolete-funcs))
+ (and (stringp byte-compile-not-obsolete-since)
+ (version< byte-compile-not-obsolete-since
+ (nth 2 (or funcp var-info)))))
+ (macroexp--obsolete-warning
+ symbol
+ (or funcp var-info)
+ (if funcp "function" "variable"))))))
+
+(defun byte-compile-warn-obsolete (symbol)
+ "Warn that SYMBOL (a variable or function) is obsolete."
+ (let ((msg (byte-compile-obsolete-p symbol)))
+ (when msg
+ (byte-compile-warn "%s" msg))))
(defun byte-compile-report-error (error-info &optional fill)
"Report Lisp error in compilation.
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index b2ac8be..6fddec3 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -188,13 +188,15 @@ macroexp-macroexpand
(or (not (fboundp 'byte-compile-warning-enabled-p))
(byte-compile-warning-enabled-p 'obsolete)))
(let* ((fun (car form))
- (obsolete (get fun 'byte-obsolete-info)))
- (macroexp--warn-and-return
- (macroexp--obsolete-warning
- fun obsolete
- (if (symbolp (symbol-function fun))
- "alias" "macro"))
- new-form))
+ (obsolete (get fun 'byte-obsolete-info))
+ (msg (if (fboundp 'byte-compile-obsolete-p)
+ (byte-compile-obsolete-p (car form))
+ (macroexp--obsolete-warning
+ fun obsolete
+ (if (symbolp (symbol-function fun))
+ "alias" "macro")))))
+ (when msg
+ (macroexp--warn-and-return msg new-form)))
new-form)))
(defun macroexp--expand-all (form)
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 13df591..afe7b99 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -431,6 +431,37 @@ test-byte-comp-compile-and-load
;; Should not warn that mt--test2 is not known to be defined.
(should-not (re-search-forward "my--test2" nil t))))
+(ert-deftest byte-compile-not-obsolete-since ()
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (let ((inhibit-read-only t)) (erase-buffer)))
+ (let ((forms
+ '((defun test-obsolete-26 ())
+ (defun test-obsolete-25 ())
+ (defun test-obsolete-24 ())
+ ;; Normally, the obsoletion would only take effect after
+ ;; loading the file.
+ (eval-when-compile (make-obsolete 'test-obsolete-26 nil "26.1"))
+ (eval-when-compile (make-obsolete 'test-obsolete-25 nil "25.1"))
+ (eval-when-compile (make-obsolete 'test-obsolete-24 nil "24.1"))
+ (test-obsolete-26) (test-obsolete-25) (test-obsolete-24))))
+ (apply #'test-byte-comp-compile-and-load t forms)
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (goto-char (point-min))
+ (should (search-forward "obsolete-26"))
+ (should (search-forward "obsolete-25"))
+ (should (search-forward "obsolete-24")))
+ (let ((byte-compile-not-obsolete-since "25.1"))
+ (apply #'test-byte-comp-compile-and-load t forms)
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (goto-char (point-min))
+ (should (search-forward "obsolete-25"))
+ (should (search-forward "obsolete-24"))))
+ (let ((byte-compile-not-obsolete-since "25"))
+ (apply #'test-byte-comp-compile-and-load t forms)
+ (with-current-buffer (get-buffer-create "*Compile-Log*")
+ (goto-char (point-min))
+ (should (search-forward "obsolete-24"))))))
+
(ert-deftest test-eager-load-macro-expansion ()
(test-byte-comp-compile-and-load nil
'(progn (defmacro abc (arg) 1) (defun def () (abc 2))))
--
2.6.2.windows.1
next prev parent reply other threads:[~2018-01-19 20:00 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-09 7:27 bug#30039: 26.0.90; [26.1] Making my code warning free is impossible with when-let Damien Cassou
2018-01-09 8:16 ` Nicolas Petton
2018-01-10 19:11 ` Noam Postavsky
2018-01-10 21:50 ` Nicolas Petton
2018-01-11 9:19 ` Damien Cassou
2018-01-19 20:00 ` Noam Postavsky [this message]
2018-01-19 20:26 ` Eli Zaretskii
2018-01-19 20:40 ` Noam Postavsky
2018-01-20 7:42 ` Eli Zaretskii
2018-01-09 14:05 ` Noam Postavsky
2018-01-09 14:23 ` Damien Cassou
2018-01-09 14:43 ` Noam Postavsky
2018-01-10 12:13 ` Damien Cassou
2018-01-10 15:45 ` Eli Zaretskii
2018-01-10 16:24 ` Nicolas Petton
2018-01-10 17:24 ` Glenn Morris
2018-01-10 18:46 ` Eli Zaretskii
2018-01-10 21:48 ` Nicolas Petton
2018-01-10 22:05 ` Eric Abrahamsen
2018-01-10 22:23 ` Noam Postavsky
2018-01-10 22:40 ` Nicolas Petton
2018-01-10 22:57 ` Eric Abrahamsen
2018-01-10 23:06 ` Noam Postavsky
2018-01-11 0:03 ` Eric Abrahamsen
2018-01-11 9:02 ` Nicolas Petton
2018-04-14 20:17 ` Lars Ingebrigtsen
2018-04-15 11:53 ` Michael Heerdegen
2018-02-21 22:28 ` Michael Heerdegen
2018-02-22 7:42 ` Damien Cassou
2018-03-06 15:12 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAM-tV-89Uf+CAXipPMqFgwjhp2DZC1dVz7Y_SftCt=27GJ+emA@mail.gmail.com' \
--to=npostavs@users.sourceforge.net \
--cc=30039@debbugs.gnu.org \
--cc=damien@cassou.me \
--cc=nicolas@petton.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.