From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dima Kogan Newsgroups: gmane.emacs.devel Subject: Re: Can we expand the valid location of "Local Variables" ? Date: Sun, 22 Mar 2020 16:08:56 -0700 Message-ID: <87h7ygoulz.fsf@dima.secretsauce.net> References: <87r1y0apzm.fsf@secretsauce.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="60989"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.2.0; emacs 28.0.50 Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 23 00:09:48 2020 Return-path: Envelope-to: ged-emacs-devel@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 1jG9j2-000FmE-B0 for ged-emacs-devel@m.gmane-mx.org; Mon, 23 Mar 2020 00:09:48 +0100 Original-Received: from localhost ([::1]:54774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG9j1-0002Gl-BU for ged-emacs-devel@m.gmane-mx.org; Sun, 22 Mar 2020 19:09:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58601) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG9iI-0001s6-81 for emacs-devel@gnu.org; Sun, 22 Mar 2020 19:09:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jG9iG-0006r7-3y for emacs-devel@gnu.org; Sun, 22 Mar 2020 19:09:02 -0400 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:40471) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jG9iF-0006oc-Mr for emacs-devel@gnu.org; Sun, 22 Mar 2020 19:09:00 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 5BB2F5C01A1; Sun, 22 Mar 2020 19:08:58 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 22 Mar 2020 19:08:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secretsauce.net; h=references:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; s=fm2; bh=+MNWa2mstwY4y5nT9/sT5HODbe Qag4cuQNvF1RVJd7w=; b=dDoBuAq9J9/YTnyB9qqCsz4T8iEp5MrbInYaT5K2mO SqOWqX+6MMsNZBfyYEgf5s4wYsYQTtm1mPQjKvWrmZmYSzelUyvPhOP5isEFQlBa 2cp/iPbUbXflzrW5dRdBrpiCF/5JSob0KBSYvxcySSZ29ThzWbQGFrcyjP2aOzd3 89E71C54u42KXrcMquhR1LO0ZqbUmj1unA1z94ALHacTzp9KqojHIP8jj0rI/xRO NlBxF9o85ouzSE9CrSr80COrAK9kxpbIzkGM+MC1opV3CxaOXJlNzpoJl8pmd4C5 07wxF/uO/vReUd5ATB5WAr8dMzQW4IefbTcbI3qLDxPA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=+MNWa2 mstwY4y5nT9/sT5HODbeQag4cuQNvF1RVJd7w=; b=M6tiT10KU2zYMnq7w+8BFd e8gdOvARpPPnAVcatcPP10oNtNgCqPovZ8hG1QPeZHbzR5AR5sf4hlH51AEDxkMJ db5R3+FkzT51+8TN7fGbas/2cn6pVNSYxDaeBH1dAqAkftI6V8KWviprbtfXGyHI Ox2DafABHe55OhdMbkTdpBNV/v3Vm9ITzPbQxl2NVhVsPCCJ1m1U6QXwEQfYXLtg GTkt6QgYQCgP2/FX3DgTf1sNPUeIRmE/rVlNP4n7khTvnA6vr3XrEbqIi/55PIEJ JFjP1CWk3gCcsorP9OAv4ENv+j35ebRYc/l0Nmgl7/fbBOfl7pXPQ0IwEZRHUH/w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudegiedgudejvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvffujgffkfggtgesmhdtreertdertdenucfhrhhomhepffhimhgr ucfmohhgrghnuceoughimhgrsehsvggtrhgvthhsrghutggvrdhnvghtqeenucffohhmrg hinhepsghlohgtkhdrohhrghenucfkphepuddtjedrvddutddrvddufedrvdegfeenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlihhsthhsse guihhmrgdrshgvtghrvghtshgruhgtvgdrnhgvth X-ME-Proxy: Original-Received: from shorty.local (107-210-213-243.lightspeed.irvnca.sbcglobal.net [107.210.213.243]) by mail.messagingengine.com (Postfix) with ESMTPA id 9671030624E4; Sun, 22 Mar 2020 19:08:57 -0400 (EDT) Original-Received: from dima by shorty.local with local (Exim 4.92.1) (envelope-from ) id 1jG9iC-0004Zl-73; Sun, 22 Mar 2020 16:08:56 -0700 In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.26 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:245702 Archived-At: --=-=-= Content-Type: text/plain I sent this out a week ago, but I guess the email didn't make it for some reason (I don't see it in the list archives, and nobody replied). Apologies if you get this twice. Stefan Monnier writes: >> Probably we'd want to make this into a variable? And the default maybe >> should be higher than 3000? > > I don't like having this 3000 hard-coded everywhere, so making > a variable makes sense. > > But encouraging large "Local Variables" blocks is a bad idea, IMO, so > I'd keep it at 3000 and I wouldn't care to document the var either. > I'd even be happy with a "--" in its name. > >> The use case where I hit this was in an .org file that was defining a >> presentation where I needed to control the export with an eval: (progn >> ...) block. Org wasn't doing quite what I needed it to, so the block had >> some advice definitions in it, and that pushed the thing over the 3000 >> byte limit. > > Of course, you can use a short > > eval: (progn (re-search-backward "^(progn ;;local-config") (eval (read (current-buffer)))) > > and then put an arbitrarily long Elisp chunk anywhere else in the buffer > with a leading `(progn ;;local-config`. Thanks for the suggestions, everyone. For my personal usage I think both including files to eval and specifying custom look-back-distance variables is a bit overkill. I think that 1. We should put the 3000 into a variable so that this isn't hard-coded. I'm attaching a patch. The name of the variable could probably be better, and it's not in the right file. I don't know where else to put it. Suggestions? And we need a NEWS entry, but I didn't want to write one before we talked about it. 2. As workarounds go, I think Stefan's suggestion above is the nicest. No custom variables or included files; just a directive to search backwards, and execute what it finds. I'll use that. Thanks for the pointer dima --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=files--local-variables-search-distance.patch commit 65b63cab97d968dade6ec73c8696f3ee1cce5473 Author: Dima Kogan Date: Sun Mar 15 21:46:35 2020 -0700 added files--local-variables-search-distance diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index e7e879065ed..d3b5e14cfe0 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1126,9 +1126,10 @@ Specifying File Variables Apart from using a @samp{-*-} line, you can define file local variables using a @dfn{local variables list} near the end of the file. -The start of the local variables list should be no more than 3000 -characters from the end of the file, and must be on the last page if -the file is divided into pages. +The start of the local variables list should be no more than +@code{files--local-variables-search-distance} characters from the end +of the file (3000 by default), and must be on the last page if the +file is divided into pages. If a file has both a local variables list and a @samp{-*-} line, Emacs processes @emph{everything} in the @samp{-*-} line first, and diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi index 1dab29b8a5a..b707cfec2fa 100644 --- a/doc/misc/calc.texi +++ b/doc/misc/calc.texi @@ -31060,13 +31060,13 @@ Assignments in Embedded Mode When Emacs loads a file into memory, it checks for a Local Variables section like this one at the end of the file. If it finds this -section, it does the specified things (in this case, running -@kbd{C-x * a} automatically) before editing of the file begins. -The Local Variables section must be within 3000 characters of the -end of the file for Emacs to find it, and it must be in the last -page of the file if the file has any page separators. -@xref{File Variables, , Local Variables in Files, emacs, the -Emacs manual}. +section, it does the specified things (in this case, running @kbd{C-x +* a} automatically) before editing of the file begins. The Local +Variables section must be within +@code{files--local-variables-search-distance} characters of the end of +the file (3000 by default) for Emacs to find it, and it must be in the +last page of the file if the file has any page separators. @xref{File +Variables, , Local Variables in Files, emacs, the Emacs manual}. Note that @kbd{C-x * a} does not update the formulas it finds. To do this, type, say, @kbd{M-1 C-x * u} after @w{@kbd{C-x * a}}. diff --git a/lisp/allout.el b/lisp/allout.el index dedad45f827..f52e27784bb 100644 --- a/lisp/allout.el +++ b/lisp/allout.el @@ -6326,7 +6326,10 @@ allout-file-vars-section-data (let (beg prefix suffix) (save-excursion (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) + 'move) (if (let ((case-fold-search t)) (not (search-forward "Local Variables:" nil t))) nil diff --git a/lisp/calendar/diary-lib.el b/lisp/calendar/diary-lib.el index da98e44926e..d5b0db1dfbb 100644 --- a/lisp/calendar/diary-lib.el +++ b/lisp/calendar/diary-lib.el @@ -2084,7 +2084,9 @@ diary-make-entry (goto-char (point-max)) (when (let ((case-fold-search t)) (search-backward "Local Variables:" - (max (- (point-max) 3000) (point-min)) + (max (- (point-max) + files--local-variables-search-distance) + (point-min)) t)) (beginning-of-line) (insert "\n") diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index d3d17fda7ad..e1b3cf319a9 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -4571,7 +4571,9 @@ custom-save-delete (case-fold-search t)) (save-excursion (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) 'move) (when (search-forward "Local Variables:" nil t) (setq pos (line-beginning-position)))) diff --git a/lisp/files-x.el b/lisp/files-x.el index 5d863626fa5..9aa64fd00be 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -169,7 +169,10 @@ modify-file-local-variable ;; Look for "Local variables:" line in last page. (widen) (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) + 'move) ;; Add "Local variables:" list if not found. (unless (let ((case-fold-search t)) diff --git a/lisp/files.el b/lisp/files.el index 8ce0187f5b7..4e173a2a674 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3720,7 +3720,9 @@ hack-local-variables ;; Look for "Local variables:" line in last page. (save-excursion (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) 'move) (when (let ((case-fold-search t)) (search-forward "Local Variables:" nil t)) diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el index cce5e06002a..5e3134feb9a 100644 --- a/lisp/international/latexenc.el +++ b/lisp/international/latexenc.el @@ -147,7 +147,9 @@ latexenc-find-file-coding-system ;; section? (unless latexenc-dont-use-TeX-master-flag (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) 'move) (search-forward "Local Variables:" nil t) (when (re-search-forward diff --git a/lisp/org/org-macs.el b/lisp/org/org-macs.el index 2a7ab66a339..dbebf1d5f66 100644 --- a/lisp/org/org-macs.el +++ b/lisp/org/org-macs.el @@ -186,7 +186,9 @@ org-preserve-local-variables (goto-char (point-max)) (let ((case-fold-search t)) (and (re-search-backward "^[ \t]*# +Local Variables:" - (max (- (point) 3000) 1) + (max (- (point-max) + files--local-variables-search-distance) + 1) t) (delete-and-extract-region (point) (point-max))))))) (unwind-protect (progn ,@body) diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index f92d3efdeb7..c28a2fd7e07 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -859,7 +859,10 @@ c-remove-any-local-eval-or-mode-variables ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables' ;; in files.el. (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) + 'move) (let (lv-point (prefix "") (suffix "")) (when (let ((case-fold-search t)) (search-forward "Local Variables:" nil t)) diff --git a/lisp/progmodes/dcl-mode.el b/lisp/progmodes/dcl-mode.el index ab3321f6868..3d82d878bf3 100644 --- a/lisp/progmodes/dcl-mode.el +++ b/lisp/progmodes/dcl-mode.el @@ -1749,7 +1749,9 @@ dcl-save-local-variable ;; Look for "Local variables:" line in last page. (save-excursion (goto-char (point-max)) - (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) + (search-backward "\n\^L" (max (- (point-max) + files--local-variables-search-distance) + (point-min)) 'move) (if (let ((case-fold-search t)) (search-forward "Local Variables:" nil t)) (let ((continue t) diff --git a/src/eval.c b/src/eval.c index 4559a0e1f66..687576fb681 100644 --- a/src/eval.c +++ b/src/eval.c @@ -4026,6 +4026,14 @@ get_backtrace (Lisp_Object array) void syms_of_eval (void) { + DEFVAR_INT ("files--local-variables-search-distance", files__local_variables_search_distance, + doc: /* How far to search for "Local Variables:" string at the end of a file + +When loading a file, emacs searches for a string "Local Variables:" at +the end of the buffer. This variable controls how far from the end of +the buffer we search. The default is 3000 characters. */); + files__local_variables_search_distance = 3000; + DEFVAR_INT ("max-specpdl-size", max_specpdl_size, doc: /* Limit on number of Lisp variable bindings and `unwind-protect's. If Lisp code tries to increase the total number past this amount, --=-=-=--