From: Philipp Stephani Date: Fri, 29 Dec 2017 20:50:55 +0000 (+0100) Subject: Add new variable to force new-style backquote interpretation. X-Git-Tag: emacs-27.0.90~5922 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ddb74b2027802ab4416bd8cdb1757a209dd7a63b;p=emacs.git 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. --- diff --git a/etc/NEWS b/etc/NEWS index c5a4bc3344b..f6f36dfc852 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 da40e99a5e6..d675b563916 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 e2d4eaa63c7..693c6c09bf3 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)