From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.bugs Subject: bug#66706: [PATCH] Automatic elisp dialect insertion Date: Tue, 24 Oct 2023 19:31:33 +0200 Message-ID: <98CD592C-0E82-4795-8168-2B5E597FF7A7@gmail.com> References: <17C83052-7946-45DE-B660-DA7EB82001B0@gmail.com> <83sf61mb54.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.15\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_99AF7CD7-EDAA-4EEB-A008-E149862B67F9" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3320"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 66706@debbugs.gnu.org, Stefan Monnier To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 24 19:33:04 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qvLH5-0000fl-K0 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 24 Oct 2023 19:33:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvLGg-0006fq-Kw; Tue, 24 Oct 2023 13:32:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvLGb-0006cF-8g for bug-gnu-emacs@gnu.org; Tue, 24 Oct 2023 13:32:34 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvLGa-0002pO-W2 for bug-gnu-emacs@gnu.org; Tue, 24 Oct 2023 13:32:33 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qvLH4-00079n-7k for bug-gnu-emacs@gnu.org; Tue, 24 Oct 2023 13:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 24 Oct 2023 17:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66706 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66706-submit@debbugs.gnu.org id=B66706.169816873427453 (code B ref 66706); Tue, 24 Oct 2023 17:33:02 +0000 Original-Received: (at 66706) by debbugs.gnu.org; 24 Oct 2023 17:32:14 +0000 Original-Received: from localhost ([127.0.0.1]:56549 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvLGI-00078h-Bi for submit@debbugs.gnu.org; Tue, 24 Oct 2023 13:32:14 -0400 Original-Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]:49600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qvLGF-00078S-DO for 66706@debbugs.gnu.org; Tue, 24 Oct 2023 13:32:12 -0400 Original-Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-507973f3b65so7501654e87.3 for <66706@debbugs.gnu.org>; Tue, 24 Oct 2023 10:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698168695; x=1698773495; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:from:to:cc:subject:date:message-id:reply-to; bh=UXpepJGH2rKONY67R200kql3d8GWvKWbsfcF3jPJklg=; b=j82CAnFUSn9XhKnrPzLpyN043lZRM4RWgrz6vh4uzQb5NH1fO0zzrY4THkbP7xWHmK J/J90nx59ZMUeym8kq8v8OdW8PpY1as3k//W3C2pyMHvSipg6IumHTzghCMEiEZ3RMf3 VtblJHCAqqCa6Tp8iufODVkhy+4O+Epq/XvHkv1sCsUhHy7A7uWLbeiEqVhOWF+wdQdE 3FVLEMo5lBM998Y682Uid2zPg7YwKQaoYrcPMEefrXWVdL+pmAKFBt3v/ZjiYxCKaKXD iReCmN6vXvXRzZV6IldAwWdohRy8aLRnU4agzYah+AMyTgKkvPCdQRvQB+pJKiv4g+5w kdIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698168695; x=1698773495; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UXpepJGH2rKONY67R200kql3d8GWvKWbsfcF3jPJklg=; b=eSTWH+MojuY5IoYHuNfLDcMkdN7PEVfohz9A+Yf2GrxzrSgAutkZ5OHjhb7DfgVfXj Q1oveG5sP9K1Nw9mYp5kZtf8+i2z2jND3bHs9wh19ICulp4+88NCk/Mk4oTIUkRyLAYP FfdbxNKIxwTf6JIQRJyakfYrzzGTnq6S607biZCCb0cKmIHdSDyW6eUkUcr9/S2M/pr5 use4PmhAEKjhC8IGHehYM3MWN0S0hn3hfu+hqIuLcrLx+Y1VhvCXK/TGR+uWVFUo9Kmb T5ZXlmy1kxc0efuC6N8m6YZZuAW5QEf74ViL2UOxigSfnFzGnDtn57TI645pQ2NAu0aK BjCA== X-Gm-Message-State: AOJu0YyPeO+wtu9TvTXz7bn9ZGFCHpfXKg8Zf348XhInXFd3vBy0nRFq 0Gc4+HZE0LImxpG3Tb4XrGE= X-Google-Smtp-Source: AGHT+IECEohs6YgAG3srJguavPc+KjVi9yzjB/JCns7DiIrQrcaFDczlGumTwACO4NudZq+8OSa6gA== X-Received: by 2002:a05:6512:48c5:b0:507:9701:26ff with SMTP id er5-20020a05651248c500b00507970126ffmr8370169lfb.31.1698168695327; Tue, 24 Oct 2023 10:31:35 -0700 (PDT) Original-Received: from smtpclient.apple (c188-150-165-235.bredband.tele2.se. [188.150.165.235]) by smtp.gmail.com with ESMTPSA id v12-20020a056512348c00b0050318721b62sm2213165lfr.6.2023.10.24.10.31.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Oct 2023 10:31:34 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3654.120.0.1.15) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273116 Archived-At: --Apple-Mail=_99AF7CD7-EDAA-4EEB-A008-E149862B67F9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Here is an updated patch, now with a test. Not sure if this belongs in the manual, but if so it's probably in the = Elisp manual ('Selecting Lisp Dialect'), right? --Apple-Mail=_99AF7CD7-EDAA-4EEB-A008-E149862B67F9 Content-Disposition: attachment; filename=0001-Automatic-Elisp-dialect-declaration-insertion.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="0001-Automatic-Elisp-dialect-declaration-insertion.patch" Content-Transfer-Encoding: quoted-printable =46rom=2066270adb8cd546f4839fa6a476312063e01b7fa0=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20=3D?UTF-8?q?Mattias=3D20Engdeg=3DC3=3DA5rd?=3D=20= =0ADate:=20Sun,=2022=20Oct=202023=2016:25:28=20+0200=0A= Subject:=20[PATCH]=20Automatic=20Elisp=20dialect=20declaration=20= insertion=0A=0AInsert=20the=20`;;;=20-*-=20lexical-binding:t=20-*-`=20= cookie=20and=20set=0A`lexical-binding`=20to=20`t`=20when=20the=20user=20= visits=20a=20new=20Elisp=20file,=20unless=0Athis=20feature=20is=20= disabled.=20=20`auto-insert-mode`=20takes=20precedence.=0A=0A*=20= etc/NEWS:=20Announce.=0A*=20lisp/progmodes/elisp-mode.el=20= (emacs-lisp-mode):=20Add=20hook.=0A(elisp-auto-dialect-declaration):=20= New=20defcustom.=0A(elisp--insert-auto-dialect-declaration):=20New=20= function.=0A*=20test/lisp/progmodes/elisp-mode-tests.el=0A= (elisp-auto-dialect-declaration):=20New=20test.=0A---=0A=20etc/NEWS=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20|=2011=20++++++++=0A=20lisp/progmodes/elisp-mode.el=20=20=20= =20=20=20=20=20=20=20=20=20|=2035=20++++++++++++++++++++++++-=0A=20= test/lisp/progmodes/elisp-mode-tests.el=20|=2025=20++++++++++++++++++=0A=20= 3=20files=20changed,=2070=20insertions(+),=201=20deletion(-)=0A=0Adiff=20= --git=20a/etc/NEWS=20b/etc/NEWS=0Aindex=208becfae7bb9..d09abd42313=20= 100644=0A---=20a/etc/NEWS=0A+++=20b/etc/NEWS=0A@@=20-804,6=20+804,17=20= @@=20This=20argument=20specifies=20the=20prettifying=20algorithm=20to=20= use.=0A=20=0A=20**=20Emacs=20Lisp=20mode=0A=20=0A+***=20Automatic=20= Elisp=20dialect=20declaration=20insertion.=0A+When=20visiting=20a=20new=20= Elisp=20file,=20Emacs=20will=20now=20automatically=20insert=20a=0A+';;;=20= -*-=20lexical-binding:=20t=20-*-'=20line=20to=20declare=20the=20modern=20= Elisp=0A+lexical-binding=20dialect,=20and=20set=20the=20= 'lexical-binding'=20variable=0A+in=20the=20buffer=20to=20't'.=0A+=0A= +This=20mechanism=20is=20controlled=20by=20the=20new=20= 'elisp-auto-dialect-declaration'=0A+user=20option.=20=20It=20will=20only=20= insert=20a=20declaration=20into=20an=20empty=20buffer:=0A+if=20the=20= buffer=20already=20had=20text=20added=20by=20means=20of=20= 'auto-insert-mode'=0A+then=20it=20will=20not=20do=20anything.=0A+=0A=20= ---=0A=20***=20',@'=20now=20has=20'prefix'=20syntax.=0A=20Previously,=20= the=20'@'=20character,=20which=20normally=20has=20'symbol'=20syntax,=0A= diff=20--git=20a/lisp/progmodes/elisp-mode.el=20= b/lisp/progmodes/elisp-mode.el=0Aindex=20ff90a744ea3..8ac32ecd077=20= 100644=0A---=20a/lisp/progmodes/elisp-mode.el=0A+++=20= b/lisp/progmodes/elisp-mode.el=0A@@=20-363,7=20+363,40=20@@=20= emacs-lisp-mode=0A=20=20=20(add-hook=20'flymake-diagnostic-functions=20= #'elisp-flymake-checkdoc=20nil=20t)=0A=20=20=20(add-hook=20= 'flymake-diagnostic-functions=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20#'elisp-flymake-byte-compile=20nil=20t)=0A-=20=20(add-hook=20= 'context-menu-functions=20#'elisp-context-menu=2010=20t))=0A+=20=20= (add-hook=20'context-menu-functions=20#'elisp-context-menu=2010=20t)=0A+=20= =20;;=20Add=20this=20hook=20sufficient=20late=20to=20give=20other=20= hooks=20(like=20`auto-insert')=0A+=20=20;;=20the=20opportunity=20to=20= insert=20something=20with=20higher=20priority.=0A+=20=20(add-hook=20= 'find-file-hook=20#'elisp--insert-auto-dialect-declaration=2050=20t))=0A= +=0A+(defcustom=20elisp-auto-dialect-declaration=20'lexical=0A+=20=20= "Dialect=20declaration=20automatically=20inserted=20in=20new=20Elisp=20= buffers.=0A+The=20declaration=20is=20\";;;=20-*-=20lexical-binding:=20t=20= -*-\".=0A+It=20is=20only=20inserted=20when=20an=20empty=20non-existing=20= file=20is=20visited.=0A+Possible=20values=20are:=0A+=20=20`lexical'=20=20= declare=20use=20of=20the=20modern=20lexical=20binding=20dialect.=0A+=20=20= `nil'=20=20=20=20=20=20do=20not=20automatically=20insert=20any=20= declaration.=0A+=0A+If=20`auto-insert-mode'=20is=20used=20to=20put=20= something=20in=20the=20buffer=20instead,=0A+then=20no=20declaration=20is=20= inserted."=0A+=20=20:type=20'(choice=20(const=20:tag=20"Lexical=20= binding=20(modern)"=20lexical)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(const=20:tag=20"No=20automatic=20declaration"=20nil))=0A+=20= =20:group=20'lisp=0A+=20=20:version=20"30.1")=0A+=0A+(defun=20= elisp--insert-auto-dialect-declaration=20()=0A+=20=20"Insert=20the=20= `elisp-auto-dialect-declaration'=20selection=20in=20a=20new=20empty=20= buffer.=0A+Otherwise,=20do=20nothing."=0A+=20=20(when=20(and=20(eq=20= elisp-auto-dialect-declaration=20'lexical)=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20(not=20buffer-read-only)=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20(zerop=20(buffer-size))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= ;;=20Don't=20modify=20a=20buffer=20corresponding=20to=20an=20existing=20= empty=20file.=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20(not=20(and=20= buffer-file-name=20(file-exists-p=20buffer-file-name))))=0A+=20=20=20=20= (let=20((was-modified=20(buffer-modified-p)))=0A+=20=20=20=20=20=20= (insert=20";;;=20-*-=20lexical-binding:=20t=20-*-\n")=0A+=20=20=20=20=20=20= (setq-local=20lexical-binding=20t)=0A+=20=20=20=20=20=20;;=20Mark=20the=20= buffer=20unmodified=20(unless=20it=20was=20modified=20before)=0A+=20=20=20= =20=20=20;;=20so=20that=20the=20user=20isn't=20bothered=20when=20killing=20= it=20or=20quitting=20Emacs.=0A+=20=20=20=20=20=20(set-buffer-modified-p=20= was-modified))))=0A=20=0A=20;;=20Font-locking=20support.=0A=20=0Adiff=20= --git=20a/test/lisp/progmodes/elisp-mode-tests.el=20= b/test/lisp/progmodes/elisp-mode-tests.el=0Aindex=20= 4fa869c773f..2a18b204ef1=20100644=0A---=20= a/test/lisp/progmodes/elisp-mode-tests.el=0A+++=20= b/test/lisp/progmodes/elisp-mode-tests.el=0A@@=20-1131,5=20+1131,30=20@@=20= test-indentation=0A=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(emacs-lisp-mode)=0A=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(indent-region=20(point-min)=20= (point-max)))))=0A=20=0A+(defun=20elisp-mode-tests--insert-gibberish=20= ()=0A+=20=20(insert=20"gibberish\n")=0A+=20=20(set-buffer-modified-p=20= nil))=0A+=0A+(ert-deftest=20elisp-auto-dialect-declaration=20()=0A+=20=20= (let=20((file=20"does-not-exist.el"))=0A+=20=20=20=20(should-not=20= (file-exists-p=20file))=0A+=20=20=20=20;;=20Try=20with=20= `elisp-auto-dialect-declaration'=20off=20and=20on.=0A+=20=20=20=20= (dolist=20(enabled=20'(nil=20lexical))=0A+=20=20=20=20=20=20(let=20= ((elisp-auto-dialect-declaration=20enabled))=0A+=20=20=20=20=20=20=20=20= ;;=20Try=20with=20a=20competing=20insertion=20that=20uses=20the=20= `find-file-hook'.=0A+=20=20=20=20=20=20=20=20(dolist=20(auto-ins=20'(nil=20= t))=0A+=20=20=20=20=20=20=20=20=20=20(let=20((find-file-hook=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(if=20auto-ins=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cons=20= 'elisp-mode-tests--insert-gibberish=20find-file-hook)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20find-file-hook)))=0A+=20=20=20=20=20= =20=20=20=20=20=20=20(save-current-buffer=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20(find-file=20file)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20(should=20(equal=20(buffer-string)=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(cond=20(auto-ins=20= "gibberish\n")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(enabled=20";;;=20-*-=20= lexical-binding:=20t=20-*-\n")=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(t=20= ""))))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20(should=20(equal=20= (buffer-modified-p)=20nil))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20= (kill-buffer))))))))=0A+=0A=20(provide=20'elisp-mode-tests)=0A=20;;;=20= elisp-mode-tests.el=20ends=20here=0A--=20=0A2.32.0=20(Apple=20Git-132)=0A= =0A= --Apple-Mail=_99AF7CD7-EDAA-4EEB-A008-E149862B67F9--