emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] comment-cache 223d16f 2/3: Apply `comment-depth' text


From: Stefan Monnier
Subject: Re: [Emacs-diffs] comment-cache 223d16f 2/3: Apply `comment-depth' text properties when calling `back_comment'.
Date: Tue, 08 Mar 2016 20:54:47 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> While the patch below is just a proof-of-concept prototype, I can't

Indeed it was and while it seemed to somewhat work it was severely broken.
I've just been testing the patch below, and I'm a bit more confident
that it does what I want.
Testing its performance (by scrolling src/regex.c backward with
page-up) I get:
- 20s with comment-use-syntax-ppss=nil
- 17s with comment-use-syntax-ppss=t
and setting open-paren-in-column-0-is-defun-start has no effect
(i.e. 20s in either case).
[ Don't take those numbers too seriously, this is testing a build with
  full debug checking and such.  The only actual result is that there
  *is* a difference.  ]


        Stefan


diff --git a/src/syntax.c b/src/syntax.c
index 249d0d5..9c5a2a8 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -570,9 +570,6 @@ dec_bytepos (ptrdiff_t bytepos)
 /* Return a defun-start position before POS and not too far before.
    It should be the last one before POS, or nearly the last.
 
-   When open_paren_in_column_0_is_defun_start is nonzero,
-   only the beginning of the buffer is treated as a defun-start.
-
    We record the information about where the scan started
    and what its result was, so that another call in the same area
    can return the same value very quickly.
@@ -597,7 +594,27 @@ find_defun_start (ptrdiff_t pos, ptrdiff_t pos_byte)
       && MODIFF == find_start_modiff)
     return find_start_value;
 
-  if (!open_paren_in_column_0_is_defun_start)
+  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 (NILP (Vopen_paren_in_column_0_is_defun_start))
     {
       find_start_value = BEGV;
       find_start_value_byte = BEGV_BYTE;
@@ -863,7 +880,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
+         if (EQ (Vopen_paren_in_column_0_is_defun_start, Qt)
              && (from == stop
                  || (temp_byte = dec_bytepos (from_byte),
                      FETCH_CHAR (temp_byte) == '\n')))
@@ -3647,6 +3664,11 @@ void
 syms_of_syntax (void)
 {
   DEFSYM (Qsyntax_table_p, "syntax-table-p");
+  DEFSYM (Qsyntax_ppss, "syntax-ppss-for-syntax.c");
+  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 = Qnil;
 
   staticpro (&Vsyntax_code_object);
 
@@ -3687,10 +3709,10 @@ See the info node `(elisp)Syntax Properties' for a 
description of the
               doc: /* Non-nil means `scan-sexps' treats all multibyte 
characters as symbol.  */);
   multibyte_syntax_as_symbol = 0;
 
-  DEFVAR_BOOL ("open-paren-in-column-0-is-defun-start",
-              open_paren_in_column_0_is_defun_start,
+  DEFVAR_LISP ("open-paren-in-column-0-is-defun-start",
+              Vopen_paren_in_column_0_is_defun_start,
               doc: /* Non-nil means an open paren in column 0 denotes the 
start of a defun.  */);
-  open_paren_in_column_0_is_defun_start = 1;
+  Vopen_paren_in_column_0_is_defun_start = Qt;
 
 
   DEFVAR_LISP ("find-word-boundary-function-table",



reply via email to

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