emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 14b9558: * src/syntax.c (find_defun_start): Use syn


From: Stefan Monnier
Subject: [Emacs-diffs] master 14b9558: * src/syntax.c (find_defun_start): Use syntax-ppss
Date: Tue, 12 Dec 2017 23:03:06 -0500 (EST)

branch: master
commit 14b95587520959c5b54356547a0a69932a9bb480
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * src/syntax.c (find_defun_start): Use syntax-ppss
    
    (syms_of_syntax): New variable comment-use-syntax-ppss.
---
 etc/NEWS     |  6 ++++++
 src/syntax.c | 26 ++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 7376fc4..bec7753 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -164,6 +164,12 @@ generating warnings for a decade.
 
 * Lisp Changes in Emacs 27.1
 
+** Internal parsing commands now use syntax-ppss and disregard
+open-paren-in-column-0-is-defun-start.  This affects mostly things like
+forward-comment, scan-sexps, and forward-sexp when parsing backward.
+The new variable 'comment-use-syntax-ppss' can be set to nil to recover the old
+behavior if needed.
+
 ---
 ** The 'file-system-info' function is now available on all platforms.
 instead of just Microsoft platforms.  This fixes a 'get-free-disk-space'
diff --git a/src/syntax.c b/src/syntax.c
index 80603b4..91c46f7 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -605,6 +605,26 @@ find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte)
       && MODIFF == find_start_modiff)
     return find_start_value;
 
+  if (!NILP (Vcomment_use_syntax_ppss))
+    {
+      EMACS_INT modiffs = CHARS_MODIFF;
+      Lisp_Object ppss = call1 (Qsyntax_ppss, make_number (pos));
+      if (modiffs != CHARS_MODIFF)
+       error ("syntax-ppss modified the buffer!");
+      TEMP_SET_PT_BOTH (opoint, opoint_byte);
+      Lisp_Object boc = Fnth (make_number (8), ppss);
+      if (NUMBERP (boc))
+        {
+          find_start_value = XINT (boc);
+          find_start_value_byte = CHAR_TO_BYTE (find_start_value);
+        }
+      else
+        {
+          find_start_value = pos;
+          find_start_value_byte = pos_byte;
+        }
+      goto found;
+    }
   if (!open_paren_in_column_0_is_defun_start)
     {
       find_start_value = BEGV;
@@ -874,6 +894,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, 
ptrdiff_t stop,
        case Sopen:
          /* Assume a defun-start point is outside of strings.  */
          if (open_paren_in_column_0_is_defun_start
+              && NILP (Vcomment_use_syntax_ppss)
              && (from == stop
                  || (temp_byte = dec_bytepos (from_byte),
                      FETCH_CHAR (temp_byte) == '\n')))
@@ -3689,6 +3710,11 @@ void
 syms_of_syntax (void)
 {
   DEFSYM (Qsyntax_table_p, "syntax-table-p");
+  DEFSYM (Qsyntax_ppss, "syntax-ppss");
+  DEFVAR_LISP ("comment-use-syntax-ppss",
+              Vcomment_use_syntax_ppss,
+              doc: /* Non-nil means `forward-comment' can use `syntax-ppss' 
internally.  */);
+  Vcomment_use_syntax_ppss = Qt;
 
   staticpro (&Vsyntax_code_object);
 



reply via email to

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