From: Stefan Kangas <stefankangas@gmail.com>
To: 59920@debbugs.gnu.org
Subject: bug#59920: [PATCH] Make checkdoc warn if not using lexical-binding
Date: Fri, 9 Dec 2022 02:10:16 -0800 [thread overview]
Message-ID: <CADwFkm=J3znL61PFONbQR1+R9Cjc2Eb1KD6WBJj=3TYiS2=N2Q@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 97 bytes --]
Severity: wishlist
The attached patch makes checkdoc warn if there's no lexical-binding
cookie.
[-- Attachment #2: 0001-Make-checkdoc-warn-if-not-using-lexical-binding.patch --]
[-- Type: text/x-diff, Size: 2461 bytes --]
From 2418e0aa770dbab25f73185d9a30acdbfd9d86ab Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Fri, 9 Dec 2022 10:58:22 +0100
Subject: [PATCH] Make checkdoc warn if not using lexical-binding
* lisp/emacs-lisp/checkdoc.el (checkdoc-file-comments-engine):
Warn if there is no lexical-binding cookie.
---
etc/NEWS | 7 +++++++
lisp/emacs-lisp/checkdoc.el | 24 ++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 7f073c4e2d..1025f43207 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -56,6 +56,13 @@ switches for shortlogs, such as the one produced by 'C-x v L'.
You can now configure how to display the "*buffer-selection*" buffer
using this new option. (Or set 'display-buffer-alist' directly.)
+** checkdoc
+
+---
+*** New checkdock warning if not using lexical-binding.
+Checkdoc now warns if the first line of an Emacs Lisp file does not
+end with a "-*- lexical-binding: t -*-" cookie.
+
\f
* New Modes and Packages in Emacs 30.1
diff --git a/lisp/emacs-lisp/checkdoc.el b/lisp/emacs-lisp/checkdoc.el
index 3bddb93b64..4ef6f0a212 100644
--- a/lisp/emacs-lisp/checkdoc.el
+++ b/lisp/emacs-lisp/checkdoc.el
@@ -2369,6 +2369,30 @@ checkdoc-file-comments-engine
(point-min) (save-excursion (goto-char (point-min))
(line-end-position))))
nil))
+ (setq
+ err
+ ;; Lexical binding cookie.
+ (if (not (save-excursion
+ (save-restriction
+ (goto-char (point-min))
+ (narrow-to-region (point) (pos-eol))
+ (re-search-forward
+ (rx "-*-" (* (* nonl) ";")
+ (* space) "lexical-binding:" (* space) "t" (* space)
+ (* ";" (* nonl))
+ "-*-")
+ nil t))))
+ (let ((pos (save-excursion (goto-char (point-min))
+ (goto-char (pos-eol))
+ (point))))
+ (if (checkdoc-y-or-n-p "There is no lexical-binding cookie! Add one?")
+ (progn
+ (goto-char pos)
+ (insert " -*- lexical-binding: t -*-"))
+ (checkdoc-create-error
+ "The first line should end with \"-*- lexical-binding: t -*-\""
+ pos (1+ pos) t)))
+ nil))
(setq
err
(or
--
2.35.1
next reply other threads:[~2022-12-09 10:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 10:10 Stefan Kangas [this message]
2022-12-09 12:25 ` bug#59920: [PATCH] Make checkdoc warn if not using lexical-binding Eli Zaretskii
2022-12-09 12:42 ` Stefan Kangas
2022-12-09 14:52 ` Eli Zaretskii
2022-12-10 23:26 ` Stefan Kangas
2022-12-11 7:29 ` Eli Zaretskii
2022-12-12 2:21 ` Stefan Kangas
2023-09-01 20:07 ` Stefan Kangas
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='CADwFkm=J3znL61PFONbQR1+R9Cjc2Eb1KD6WBJj=3TYiS2=N2Q@mail.gmail.com' \
--to=stefankangas@gmail.com \
--cc=59920@debbugs.gnu.org \
/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.