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,