emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can we expand the valid location of "Local Variables" ?


From: Dima Kogan
Subject: Re: Can we expand the valid location of "Local Variables" ?
Date: Sun, 22 Mar 2020 16:08:56 -0700
User-agent: mu4e 1.2.0; emacs 28.0.50

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 <address@hidden> 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

commit 65b63cab97d968dade6ec73c8696f3ee1cce5473
Author: Dima Kogan <address@hidden>
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,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]