emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master ddb74b2: Add new variable to force new-style backqu


From: Philipp Stephani
Subject: [Emacs-diffs] master ddb74b2: Add new variable to force new-style backquote interpretation.
Date: Sun, 7 Jan 2018 08:21:10 -0500 (EST)

branch: master
commit ddb74b2027802ab4416bd8cdb1757a209dd7a63b
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    Add new variable to force new-style backquote interpretation.
    
    * src/lread.c (syms_of_lread): Add new variable
    'force-new-style-backquotes'.
    (read_internal_start): Use it.
    
    * test/src/lread-tests.el (lread-tests--force-new-style-backquotes):
    New test.
    
    * etc/NEWS: Document new variable.
---
 etc/NEWS                |  3 ++-
 src/lread.c             | 21 ++++++++++++++++-----
 test/src/lread-tests.el |  8 ++++++++
 3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index c5a4bc3..f6f36df 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -188,7 +188,8 @@ support, you should set 'eldoc-documentation-function' 
instead of
 calling 'eldoc-message' directly.
 
 ** Old-style backquotes now generate an error.  They have been
-generating warnings for a decade.
+generating warnings for a decade.  To interpret old-style backquotes
+as new-style, bind the new variable 'force-new-style-backquotes' to t.
 
 
 * Lisp Changes in Emacs 27.1
diff --git a/src/lread.c b/src/lread.c
index da40e99..d675b56 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -147,10 +147,10 @@ static ptrdiff_t prev_saved_doc_string_length;
 /* This is the file position that string came from.  */
 static file_offset prev_saved_doc_string_position;
 
-/* True means inside a new-style backquote
-   with no surrounding parentheses.
-   Fread initializes this to false, so we need not specbind it
-   or worry about what happens to it when there is an error.  */
+/* True means inside a new-style backquote with no surrounding
+   parentheses.  Fread initializes this to the value of
+   `force_new_style_backquotes', so we need not specbind it or worry
+   about what happens to it when there is an error.  */
 static bool new_backquote_flag;
 
 /* A list of file names for files being loaded in Fload.  Used to
@@ -2187,7 +2187,7 @@ read_internal_start (Lisp_Object stream, Lisp_Object 
start, Lisp_Object end)
   Lisp_Object retval;
 
   readchar_count = 0;
-  new_backquote_flag = 0;
+  new_backquote_flag = force_new_style_backquotes;
   /* We can get called from readevalloop which may have set these
      already.  */
   if (! HASH_TABLE_P (read_objects_map)
@@ -5006,6 +5006,17 @@ Note that if you customize this, obviously it will not 
affect files
 that are loaded before your customizations are read!  */);
   load_prefer_newer = 0;
 
+  DEFVAR_BOOL ("force-new-style-backquotes", force_new_style_backquotes,
+               doc: /* Non-nil means to always use the current syntax for 
backquotes.
+If nil, `load' and `read' raise errors when encountering some
+old-style variants of backquote and comma.  If non-nil, these
+constructs are always interpreted as described in the Info node
+`(elisp)Backquotes', even if that interpretation is incompatible with
+previous versions of Emacs.  Setting this variable to non-nil makes
+Emacs compatible with the behavior planned for Emacs 28.  In Emacs 28,
+this variable will become obsolete.  */);
+  force_new_style_backquotes = false;
+
   /* Vsource_directory was initialized in init_lread.  */
 
   DEFSYM (Qcurrent_load_list, "current-load-list");
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index e2d4eaa..693c6c0 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -181,6 +181,14 @@ literals (Bug#20852)."
                      (list (concat (format-message "Loading `%s': " file-name)
                                    "old-style backquotes detected!")))))))
 
+(ert-deftest lread-tests--force-new-style-backquotes ()
+  (let ((data (should-error (read "(` (a b))"))))
+    (should (equal (cdr data)
+                   '("Loading `nil': old-style backquotes detected!"))))
+  (should (equal (let ((force-new-style-backquotes t))
+                   (read "(` (a b))"))
+                 '(`(a b)))))
+
 (ert-deftest lread-lread--substitute-object-in-subtree ()
   (let ((x (cons 0 1)))
     (setcar x x)



reply via email to

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