emacs-diffs
[Top][All Lists]
Advanced

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

feature/android 562b2fca7d8: Merge remote-tracking branch 'origin/master


From: Po Lu
Subject: feature/android 562b2fca7d8: Merge remote-tracking branch 'origin/master' into feature/android
Date: Wed, 12 Apr 2023 19:32:57 -0400 (EDT)

branch: feature/android
commit 562b2fca7d824a01d759bc7ade0e54ddd8497a0b
Merge: 91da696bbc4 861cf3a5c9d
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Merge remote-tracking branch 'origin/master' into feature/android
---
 doc/misc/flymake.texi          |  17 ++++-
 lisp/emacs-lisp/byte-opt.el    |   3 +-
 lisp/emacs-lisp/bytecomp.el    |   9 ++-
 lisp/gnus/nnselect.el          |   3 +-
 lisp/progmodes/c-ts-mode.el    |  14 ++--
 lisp/progmodes/flymake.el      |  35 ++++++----
 lisp/progmodes/ruby-ts-mode.el |  18 ++++-
 lisp/treesit.el                | 152 +++++++++++++++++++++++++++--------------
 src/regex-emacs.c              |  43 ++++--------
 src/syntax.c                   |  50 ++++++--------
 src/syntax.h                   |  24 +++----
 11 files changed, 208 insertions(+), 160 deletions(-)

diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi
index 03d296a1d42..13616f39f16 100644
--- a/doc/misc/flymake.texi
+++ b/doc/misc/flymake.texi
@@ -1,8 +1,8 @@
 \input texinfo   @c -*- mode: texinfo; coding: utf-8 -*-
 @comment %**start of header
 @setfilename ../../info/flymake.info
-@set VERSION 1.2.2
-@set UPDATED November 2021
+@set VERSION 1.3.3
+@set UPDATED April 2023
 @settitle GNU Flymake @value{VERSION}
 @include docstyle.texi
 @syncodeindex pg cp
@@ -394,7 +394,7 @@ its @code{flymake-overlay-control} property:
 
 @item
 @cindex severity of diagnostic
-@code{flymake-severity} is a non-negative integer specifying the
+@code{severity} is a non-negative integer specifying the
 diagnostic's severity.  The higher the value, the more serious is the
 error.  If the overlay property @code{priority} is not specified in
 @code{flymake-overlay-control}, @code{flymake-severity} is used to set
@@ -409,6 +409,17 @@ type, in case the name of the symbol associated with it is 
very long.
 @vindex flymake-category
 @code{flymake-category} is a symbol whose property list is considered
 the default for missing values of any other properties.
+
+@item
+@cindex mode-line appearance of a diagnostic
+@code{mode-line-face} is a face specifier controlling the appearance
+of the indicator of this type of diagnostic in the mode line.
+
+@item
+@cindex summarized appearance of a diagnostic
+@code{echo-face} is a face specifier controlling the appearance of the
+summarized description of this diagnostic when reading diagnostic
+messages (@pxref{Finding diagnostics}).
 @end itemize
 
 @cindex predefined diagnostic types
diff --git a/lisp/emacs-lisp/byte-opt.el b/lisp/emacs-lisp/byte-opt.el
index dad3bd694a6..c9c94f51ef0 100644
--- a/lisp/emacs-lisp/byte-opt.el
+++ b/lisp/emacs-lisp/byte-opt.el
@@ -1642,7 +1642,7 @@ See Info node `(elisp) Integer Basics'."
          bool-vector-count-consecutive bool-vector-count-population
          bool-vector-subsetp
         boundp buffer-file-name buffer-local-variables buffer-modified-p
-        buffer-substring byte-code-function-p
+        buffer-substring
         capitalize car-less-than-car car cdr ceiling char-after char-before
         char-equal char-to-string char-width compare-strings
         window-configuration-equal-p concat coordinates-in-window-p
@@ -1702,6 +1702,7 @@ See Info node `(elisp) Integer Basics'."
        '(arrayp atom
         bobp bolp bool-vector-p
         buffer-list buffer-size buffer-string bufferp
+         byte-code-function-p
         car-safe case-table-p cdr-safe char-or-string-p characterp
         charsetp commandp cons consp
         current-buffer current-global-map current-indentation
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 1b28fcd5093..c84c70971b3 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3563,6 +3563,8 @@ lambda-expression."
                                ;;delq delete cl-delete
                                ;;nconc plist-put
                                )))
+                   ;; Don't warn for arguments to `ignore'.
+                   (not (eq byte-compile--for-effect 'for-effect-no-warn))
                    (byte-compile-warning-enabled-p
                     'ignored-return-value (car form)))
               (byte-compile-warn-x
@@ -4446,11 +4448,8 @@ This function is never called when `lexical-binding' is 
nil."
 
 (defun byte-compile-ignore (form)
   (dolist (arg (cdr form))
-    ;; Compile args for value (to avoid warnings about unused values),
-    ;; emit a discard after each, and trust the LAP peephole optimiser
-    ;; to annihilate useless ops.
-    (byte-compile-form arg)
-    (byte-compile-discard))
+    ;; Compile each argument for-effect but suppress unused-value warnings.
+    (byte-compile-form arg 'for-effect-no-warn))
   (byte-compile-form nil))
 
 ;; Return the list of items in CONDITION-PARAM that match PRED-LIST.
diff --git a/lisp/gnus/nnselect.el b/lisp/gnus/nnselect.el
index af4dbdc35df..57a833de9bf 100644
--- a/lisp/gnus/nnselect.el
+++ b/lisp/gnus/nnselect.el
@@ -478,7 +478,8 @@ artlist; otherwise store the ARTLIST in the group 
parameters."
 
 (deffoo nnselect-request-move-article
     (article _group _server accept-form &optional last _internal-move-group)
-  (let* ((artgroup (nnselect-article-group article))
+  (let* ((nnimap-expunge 'immediately)
+         (artgroup (nnselect-article-group article))
         (artnumber (nnselect-article-number article))
         (to-newsgroup (nth 1 accept-form))
         (to-method (gnus-find-method-for-group to-newsgroup))
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 385e3918842..ece20e90a6f 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -921,15 +921,13 @@ the semicolon.  This function skips the semicolon."
                             "goto_statement"
                             "case_statement")))
 
+  ;; IMO it makes more sense to define what's NOT sexp, since sexp by
+  ;; spirit, especially when used for movement, is like "expression"
+  ;; or "syntax unit". --yuan
   (setq-local treesit-sexp-type-regexp
-              (regexp-opt '("preproc"
-                            "declarator"
-                            "qualifier"
-                            "type"
-                            "parameter"
-                            "expression"
-                            "literal"
-                            "string")))
+              ;; It more useful to include semicolons as sexp so that
+              ;; users can move to the end of a statement.
+              (rx (not (or "{" "}" "[" "]" "(" ")" ","))))
 
   ;; Nodes like struct/enum/union_specifier can appear in
   ;; function_definitions, so we need to find the top-level node.
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 1cd9f0a6b0c..c751e5bd432 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -4,7 +4,7 @@
 
 ;; Author: Pavel Kobyakov <pk_at_work@yahoo.com>
 ;; Maintainer: João Távora <joaotavora@gmail.com>
-;; Version: 1.3.2
+;; Version: 1.3.3
 ;; Keywords: c languages tools
 ;; Package-Requires: ((emacs "26.1") (eldoc "1.14.0") (project "0.7.1"))
 
@@ -371,11 +371,19 @@ diagnostics at BEG."
 (flymake--diag-accessor flymake-diagnostic-end flymake--diag-end end)
 (flymake--diag-accessor flymake-diagnostic-buffer flymake--diag-locus locus)
 
-(defun flymake-diagnostic-oneliner (diag)
-  "Get truncated one-line text string for diagnostic DIAG."
-  (let ((txt (flymake-diagnostic-text diag)))
-    (substring txt 0 (cl-loop for i from 0 for a across txt
-                              when (eq a ?\n) return i))))
+(defun flymake-diagnostic-oneliner (diag &optional nopaintp)
+  "Get truncated one-line text string for diagnostic DIAG.
+This is useful for displaying the DIAG's text to the user in
+confined spaces, such as the echo are.  Unless NOPAINTP is t,
+propertize returned text with the `echo-face' property of DIAG's
+type."
+  (let* ((txt (flymake-diagnostic-text diag))
+         (txt (substring txt 0 (cl-loop for i from 0 for a across txt
+                                        when (eq a ?\n) return i))))
+    (if nopaintp txt
+      (propertize txt 'face
+                  (flymake--lookup-type-property
+                   (flymake-diagnostic-type diag) 'echo-face 
'flymake-error)))))
 
 (cl-defun flymake--overlays (&key beg end filter compare key)
   "Get flymake-related overlays.
@@ -577,18 +585,21 @@ Node `(Flymake)Flymake error types'"
 (put 'flymake-error 'flymake-bitmap 'flymake-error-bitmap)
 (put 'flymake-error 'severity (warning-numeric-level :error))
 (put 'flymake-error 'mode-line-face 'compilation-error)
+(put 'flymake-error 'echo-face 'error)
 (put 'flymake-error 'flymake-type-name "error")
 
 (put 'flymake-warning 'face 'flymake-warning)
 (put 'flymake-warning 'flymake-bitmap 'flymake-warning-bitmap)
 (put 'flymake-warning 'severity (warning-numeric-level :warning))
 (put 'flymake-warning 'mode-line-face 'compilation-warning)
+(put 'flymake-warning 'echo-face 'warning)
 (put 'flymake-warning 'flymake-type-name "warning")
 
 (put 'flymake-note 'face 'flymake-note)
 (put 'flymake-note 'flymake-bitmap 'flymake-note-bitmap)
 (put 'flymake-note 'severity (warning-numeric-level :debug))
 (put 'flymake-note 'mode-line-face 'compilation-info)
+(put 'flymake-note 'echo-face 'compilation-info)
 (put 'flymake-note 'flymake-type-name "note")
 
 (defun flymake--lookup-type-property (type prop &optional default)
@@ -736,7 +747,7 @@ Return nil or the overlay created."
         (lambda (window _ov pos)
           (with-selected-window window
             (mapconcat
-             #'flymake-diagnostic-text
+             #'flymake-diagnostic-oneliner
              (flymake-diagnostics pos)
              "\n"))))
       (default-maybe 'severity (warning-numeric-level :error))
@@ -1263,13 +1274,7 @@ Intended for `eldoc-documentation-functions' (which 
see)."
   (when-let ((diags (flymake-diagnostics (point))))
     (funcall report-doc
              (mapconcat #'flymake-diagnostic-text diags "\n")
-             :echo (mapconcat (lambda (d)
-                                (propertize (flymake-diagnostic-oneliner d)
-                                            'face
-                                            (flymake--lookup-type-property
-                                             (flymake-diagnostic-type d)
-                                             'face
-                                             'flymake-error)))
+             :echo (mapconcat #'flymake-diagnostic-oneliner
                               diags "\n"))))
 
 (defun flymake-goto-next-error (&optional n filter interactive)
@@ -1595,7 +1600,7 @@ filename of the diagnostic relative to that directory."
                                                     "\\1\\2" bname)
                         "(anon)")
                       'help-echo (format "From `%s' backend" backend))
-                    (,(flymake-diagnostic-oneliner diag)
+                    (,(flymake-diagnostic-oneliner diag t)
                      mouse-face highlight
                      help-echo "mouse-2: visit this diagnostic"
                      face nil
diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el
index ddf2ee98c3b..7a00977f14a 100644
--- a/lisp/progmodes/ruby-ts-mode.el
+++ b/lisp/progmodes/ruby-ts-mode.el
@@ -1086,6 +1086,15 @@ leading double colon is not added."
            (put-text-property pos (1+ pos) 'syntax-table
                               (string-to-syntax "!"))))))))
 
+(defun ruby-ts--sexp-p (node)
+  ;; Skip parenless calls (implicit parens are both non-obvious to the
+  ;; user, and might take over when we want to just over some physical
+  ;; parens/braces).
+  (or (not (equal (treesit-node-type node)
+                  "argument_list"))
+      (equal (treesit-node-type (treesit-node-child node 0))
+             "(")))
+
 (defvar-keymap ruby-ts-mode-map
   :doc "Keymap used in Ruby mode"
   :parent prog-mode-map
@@ -1114,8 +1123,10 @@ leading double colon is not added."
   (setq-local treesit-defun-type-regexp ruby-ts--method-regex)
 
   (setq-local treesit-sexp-type-regexp
-              (rx bol
-                  (or "class"
+              (cons (rx
+                     bol
+                     (or
+                      "class"
                       "module"
                       "method"
                       "array"
@@ -1147,7 +1158,8 @@ leading double colon is not added."
                       "instance_variable"
                       "global_variable"
                       )
-                  eol))
+                     eol)
+                    #'ruby-ts--sexp-p))
 
   ;; AFAIK, Ruby can not nest methods
   (setq-local treesit-defun-prefer-top-level nil)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 4c4ba4ad6ac..3932920a962 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1783,15 +1783,17 @@ however, smaller in scope than sentences.  This is used 
by
 `treesit-forward-sexp' and friends.")
 
 (defun treesit-forward-sexp (&optional arg)
+  "Tree-sitter implementation for `forward-sexp-function'.
+ARG is described in the docstring of `forward-sexp-function'."
   (interactive "^p")
   (or arg (setq arg 1))
   (funcall
    (if (> arg 0) #'treesit-end-of-thing #'treesit-beginning-of-thing)
-   treesit-sexp-type-regexp (abs arg)))
+   treesit-sexp-type-regexp (abs arg) 'restricted))
 
 (defun treesit-transpose-sexps (&optional arg)
   "Tree-sitter `transpose-sexps' function.
-Arg is the same as in `transpose-sexps'.
+ARG is the same as in `transpose-sexps'.
 
 Locate the node closest to POINT, and transpose that node with
 its sibling node ARG nodes away.
@@ -1896,33 +1898,53 @@ Basically,
       pattern
     (cons pattern nil)))
 
-(defun treesit-beginning-of-thing (pattern &optional arg)
+(defun treesit-beginning-of-thing (pattern &optional arg tactic)
   "Like `beginning-of-defun', but generalized into things.
 
 PATTERN is like `treesit-defun-type-regexp', ARG
 is the same as in `beginning-of-defun'.
 
+TACTIC determines how does this function move between things.  It
+can be `nested', `top-level', `restricted', or nil.  `nested'
+means normal nested navigation: try to move to siblings first,
+and if there aren't enough siblings, move to the parent and its
+siblings.  `top-level' means only consider top-level things, and
+nested things are ignored.  `restricted' means movement is
+restricted inside the thing that encloses POS (i.e., parent),
+should there be one.  If omitted, TACTIC is considered to be
+`nested'.
+
 Return non-nil if successfully moved, nil otherwise."
   (pcase-let* ((arg (or arg 1))
                (`(,regexp . ,pred) (treesit--thing-unpack-pattern
                                     pattern))
                (dest (treesit--navigate-thing
-                      (point) (- arg) 'beg regexp pred)))
+                      (point) (- arg) 'beg regexp pred tactic)))
     (when dest
       (goto-char dest))))
 
-(defun treesit-end-of-thing (pattern &optional arg)
+(defun treesit-end-of-thing (pattern &optional arg tactic)
   "Like `end-of-defun', but generalized into things.
 
 PATTERN is like `treesit-defun-type-regexp', ARG is the same as
 in `end-of-defun'.
 
+TACTIC determines how does this function move between things.  It
+can be `nested', `top-level', `restricted', or nil.  `nested'
+means normal nested navigation: try to move to siblings first,
+and if there aren't enough siblings, move to the parent and its
+siblings.  `top-level' means only consider top-level things, and
+nested things are ignored.  `restricted' means movement is
+restricted inside the thing that encloses POS (i.e., parent),
+should there be one.  If omitted, TACTIC is considered to be
+`nested'.
+
 Return non-nil if successfully moved, nil otherwise."
   (pcase-let* ((arg (or arg 1))
                (`(,regexp . ,pred) (treesit--thing-unpack-pattern
                                     pattern))
                (dest (treesit--navigate-thing
-                      (point) arg 'end regexp pred)))
+                      (point) arg 'end regexp pred tactic)))
     (when dest
       (goto-char dest))))
 
@@ -1943,7 +1965,8 @@ and `treesit-defun-skipper'."
     (catch 'done
       (dotimes (_ 2)
 
-        (when (treesit-beginning-of-thing treesit-defun-type-regexp arg)
+        (when (treesit-beginning-of-thing
+               treesit-defun-type-regexp arg treesit-defun-tactic)
           (when treesit-defun-skipper
             (funcall treesit-defun-skipper)
             (setq success t)))
@@ -1971,7 +1994,8 @@ this function depends on `treesit-defun-type-regexp' and
     (catch 'done
       (dotimes (_ 2) ; Not making progress is better than infloop.
 
-        (when (treesit-end-of-thing treesit-defun-type-regexp arg)
+        (when (treesit-end-of-thing
+               treesit-defun-type-regexp arg treesit-defun-tactic)
           (when treesit-defun-skipper
             (funcall treesit-defun-skipper)))
 
@@ -2144,7 +2168,7 @@ REGEXP and PRED are the same as in 
`treesit-thing-at-point'."
 ;;    -> Obviously we don't want to go to parent's end, instead, we
 ;;       want to go to parent's prev-sibling's end.  Again, we recurse
 ;;       in the function to do that.
-(defun treesit--navigate-thing (pos arg side regexp &optional pred recursing)
+(defun treesit--navigate-thing (pos arg side regexp &optional pred tactic 
recursing)
   "Navigate thing ARG steps from POS.
 
 If ARG is positive, move forward that many steps, if negative,
@@ -2157,6 +2181,16 @@ across, return nil.
 
 REGEXP and PRED are the same as in `treesit-thing-at-point'.
 
+TACTIC determines how does this function move between things.  It
+can be `nested', `top-level', `restricted', or nil.  `nested'
+means normal nested navigation: try to move to siblings first,
+and if there aren't enough siblings, move to the parent and its
+siblings.  `top-level' means only consider top-level things, and
+nested things are ignored.  `restricted' means movement is
+restricted inside the thing that encloses POS (i.e., parent),
+should there be one.  If omitted, TACTIC is considered to be
+`nested'.
+
 RECURSING is an internal parameter, if non-nil, it means this
 function is called recursively."
   (pcase-let*
@@ -2178,53 +2212,57 @@ function is called recursively."
           ;; When PARENT is nil, nested and top-level are the same, if
           ;; there is a PARENT, make PARENT to be the top-level parent
           ;; and pretend there is no nested PREV and NEXT.
-          (when (and (eq treesit-defun-tactic 'top-level)
+          (when (and (eq tactic 'top-level)
                      parent)
             (setq parent (treesit--top-level-thing
                           parent regexp pred)
                   prev nil
                   next nil))
-          ;; Move...
-          (if (> arg 0)
-              ;; ...forward.
-              (if (and (eq side 'beg)
-                       ;; Should we skip the defun (recurse)?
-                       (cond (next (and (not recursing) ; [1] (see below)
-                                        (eq pos (funcall advance next))))
-                             (parent t))) ; [2]
-                  ;; Special case: go to next beg-of-defun, but point
-                  ;; is already on beg-of-defun.  Set POS to the end
-                  ;; of next-sib/parent defun, and run one more step.
-                  ;; If there is a next-sib defun, we only need to
-                  ;; recurse once, so we don't need to recurse if we
-                  ;; are already recursing [1]. If there is no
-                  ;; next-sib but a parent, keep stepping out
-                  ;; (recursing) until we got out of the parents until
-                  ;; (1) there is a next sibling defun, or (2) no more
-                  ;; parents [2].
-                  ;;
-                  ;; If point on beg-of-defun but we are already
-                  ;; recurring, that doesn't count as special case,
-                  ;; because we have already made progress (by moving
-                  ;; the end of next before recurring.)
+          ;; If TACTIC is `restricted', the implementation is very simple.
+          (if (eq tactic 'restricted)
+              (setq pos (funcall advance (if (> arg 0) next prev)))
+            ;; For `nested', it's a bit more work:
+            ;; Move...
+            (if (> arg 0)
+                ;; ...forward.
+                (if (and (eq side 'beg)
+                         ;; Should we skip the defun (recurse)?
+                         (cond (next (and (not recursing) ; [1] (see below)
+                                          (eq pos (funcall advance next))))
+                               (parent t))) ; [2]
+                    ;; Special case: go to next beg-of-defun, but point
+                    ;; is already on beg-of-defun.  Set POS to the end
+                    ;; of next-sib/parent defun, and run one more step.
+                    ;; If there is a next-sib defun, we only need to
+                    ;; recurse once, so we don't need to recurse if we
+                    ;; are already recursing [1]. If there is no
+                    ;; next-sib but a parent, keep stepping out
+                    ;; (recursing) until we got out of the parents until
+                    ;; (1) there is a next sibling defun, or (2) no more
+                    ;; parents [2].
+                    ;;
+                    ;; If point on beg-of-defun but we are already
+                    ;; recurring, that doesn't count as special case,
+                    ;; because we have already made progress (by moving
+                    ;; the end of next before recurring.)
+                    (setq pos (or (treesit--navigate-thing
+                                   (treesit-node-end (or next parent))
+                                   1 'beg regexp pred tactic t)
+                                  (throw 'term nil)))
+                  ;; Normal case.
+                  (setq pos (funcall advance (or next parent))))
+              ;; ...backward.
+              (if (and (eq side 'end)
+                       (cond (prev (and (not recursing)
+                                        (eq pos (funcall advance prev))))
+                             (parent t)))
+                  ;; Special case: go to prev end-of-defun.
                   (setq pos (or (treesit--navigate-thing
-                                 (treesit-node-end (or next parent))
-                                 1 'beg regexp pred t)
+                                 (treesit-node-start (or prev parent))
+                                 -1 'end regexp pred tactic t)
                                 (throw 'term nil)))
                 ;; Normal case.
-                (setq pos (funcall advance (or next parent))))
-            ;; ...backward.
-            (if (and (eq side 'end)
-                     (cond (prev (and (not recursing)
-                                      (eq pos (funcall advance prev))))
-                           (parent t)))
-                ;; Special case: go to prev end-of-defun.
-                (setq pos (or (treesit--navigate-thing
-                               (treesit-node-start (or prev parent))
-                               -1 'end regexp pred t)
-                              (throw 'term nil)))
-              ;; Normal case.
-              (setq pos (funcall advance (or prev parent)))))
+                (setq pos (funcall advance (or prev parent))))))
           ;; A successful step! Decrement counter.
           (cl-decf counter))))
     ;; Counter equal to 0 means we successfully stepped ARG steps.
@@ -2984,6 +3022,9 @@ See `treesit-language-source-alist' for details."
             (buffer-local-value 'url-http-response-status buffer)
             200)))))
 
+(defvar treesit--install-language-grammar-out-dir-history nil
+  "History for OUT-DIR for `treesit-install-language-grammar'.")
+
 ;;;###autoload
 (defun treesit-install-language-grammar (lang)
   "Build and install the tree-sitter language grammar library for LANG.
@@ -3005,11 +3046,20 @@ executable programs, such as the C/C++ compiler and 
linker."
   (when-let ((recipe
               (or (assoc lang treesit-language-source-alist)
                   (treesit--install-language-grammar-build-recipe
-                   lang))))
+                   lang)))
+             (default-out-dir
+              (or (car treesit--install-language-grammar-out-dir-history)
+                  (locate-user-emacs-file "tree-sitter")))
+             (out-dir
+              (read-string
+               (format "Install to (default: %s): "
+                       default-out-dir)
+               nil
+               'treesit--install-language-grammar-out-dir-history
+               default-out-dir)))
     (condition-case err
         (apply #'treesit--install-language-grammar-1
-               ;; The nil is OUT-DIR.
-               (cons nil recipe))
+               (cons out-dir recipe))
       (error
        (display-warning
         'treesit
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index 2571812cb39..746779490ad 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -47,13 +47,6 @@
 /* Make syntax table lookup grant data in gl_state.  */
 #define SYNTAX(c) syntax_property (c, 1)
 
-/* Convert the pointer to the char to BEG-based offset from the start.  */
-#define PTR_TO_OFFSET(d) POS_AS_IN_BUFFER (POINTER_TO_OFFSET (d))
-/* Strings are 0-indexed, buffers are 1-indexed; pun on the boolean
-   result to get the right base index.  */
-#define POS_AS_IN_BUFFER(p)                                    \
-  ((p) + (NILP (gl_state.object) || BUFFERP (gl_state.object)))
-
 #define RE_MULTIBYTE_P(bufp) ((bufp)->multibyte)
 #define RE_TARGET_MULTIBYTE_P(bufp) ((bufp)->target_multibyte)
 #define RE_STRING_CHAR(p, multibyte) \
@@ -3258,12 +3251,7 @@ re_search_2 (struct re_pattern_buffer *bufp, const char 
*str1, ptrdiff_t size1,
   /* See whether the pattern is anchored.  */
   anchored_start = (bufp->buffer[0] == begline);
 
-  gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */
-  {
-    ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER 
(startpos));
-
-    SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
-  }
+  RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, startpos);
 
   /* Loop through the string, looking for a place to start matching.  */
   for (;;)
@@ -3871,10 +3859,7 @@ re_match_2 (struct re_pattern_buffer *bufp,
 {
   ptrdiff_t result;
 
-  ptrdiff_t charpos;
-  gl_state.object = re_match_object; /* Used by SYNTAX_TABLE_BYTE_TO_CHAR. */
-  charpos = SYNTAX_TABLE_BYTE_TO_CHAR (POS_AS_IN_BUFFER (pos));
-  SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, charpos, 1);
+  RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (re_match_object, pos);
 
   result = re_match_2_internal (bufp, (re_char *) string1, size1,
                                (re_char *) string2, size2,
@@ -4806,8 +4791,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
                int c1, c2;
                int s1, s2;
                int dummy;
-                ptrdiff_t offset = PTR_TO_OFFSET (d);
-                ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
+                ptrdiff_t offset = POINTER_TO_OFFSET (d);
+                ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
                UPDATE_SYNTAX_TABLE (charpos);
                GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
                nchars++;
@@ -4846,8 +4831,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
              int c1, c2;
              int s1, s2;
              int dummy;
-             ptrdiff_t offset = PTR_TO_OFFSET (d);
-             ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+             ptrdiff_t offset = POINTER_TO_OFFSET (d);
+             ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset);
              UPDATE_SYNTAX_TABLE (charpos);
              PREFETCH ();
              GET_CHAR_AFTER (c2, d, dummy);
@@ -4889,8 +4874,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
              int c1, c2;
              int s1, s2;
              int dummy;
-              ptrdiff_t offset = PTR_TO_OFFSET (d);
-              ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
+              ptrdiff_t offset = POINTER_TO_OFFSET (d);
+              ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
              UPDATE_SYNTAX_TABLE (charpos);
              GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
              nchars++;
@@ -4931,8 +4916,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
                 is the character at D, and S2 is the syntax of C2.  */
              int c1, c2;
              int s1, s2;
-             ptrdiff_t offset = PTR_TO_OFFSET (d);
-             ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+             ptrdiff_t offset = POINTER_TO_OFFSET (d);
+             ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset);
              UPDATE_SYNTAX_TABLE (charpos);
              PREFETCH ();
              c2 = RE_STRING_CHAR (d, target_multibyte);
@@ -4972,8 +4957,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
                 is the character at D, and S2 is the syntax of C2.  */
              int c1, c2;
              int s1, s2;
-              ptrdiff_t offset = PTR_TO_OFFSET (d);
-              ptrdiff_t charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
+              ptrdiff_t offset = POINTER_TO_OFFSET (d);
+              ptrdiff_t charpos = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset) - 1;
              UPDATE_SYNTAX_TABLE (charpos);
              GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
              nchars++;
@@ -5008,8 +4993,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
                         mcnt);
            PREFETCH ();
            {
-             ptrdiff_t offset = PTR_TO_OFFSET (d);
-             ptrdiff_t pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+             ptrdiff_t offset = POINTER_TO_OFFSET (d);
+             ptrdiff_t pos1 = RE_SYNTAX_TABLE_BYTE_TO_CHAR (offset);
              UPDATE_SYNTAX_TABLE (pos1);
            }
            {
diff --git a/src/syntax.c b/src/syntax.c
index 79e16f652f3..e9e04e2d638 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -250,7 +250,6 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
   gl_state.b_property = BEGV;
   gl_state.e_property = ZV + 1;
   gl_state.object = Qnil;
-  gl_state.offset = 0;
   if (parse_sexp_lookup_properties)
     {
       if (count > 0)
@@ -266,46 +265,38 @@ SETUP_SYNTAX_TABLE (ptrdiff_t from, ptrdiff_t count)
 /* Same as above, but in OBJECT.  If OBJECT is nil, use current buffer.
    If it is t (which is only used in fast_c_string_match_ignore_case),
    ignore properties altogether.
-
-   This is meant for regex-emacs.c to use.  For buffers, regex-emacs.c
-   passes arguments to the UPDATE_SYNTAX_TABLE functions which are
-   relative to BEGV.  So if it is a buffer, we set the offset field to
-   BEGV.  */
+   FROMBYTE is an regexp-byteoffset.  */
 
 void
-SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
-                              ptrdiff_t from, ptrdiff_t count)
+RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object object,
+                                 ptrdiff_t frombyte)
 {
   SETUP_BUFFER_SYNTAX_TABLE ();
   gl_state.object = object;
   if (BUFFERP (gl_state.object))
     {
       struct buffer *buf = XBUFFER (gl_state.object);
-      gl_state.b_property = 1;
-      gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1;
-      gl_state.offset = BUF_BEGV (buf) - 1;
+      gl_state.b_property = BEG;
+      gl_state.e_property = BUF_ZV (buf);
     }
   else if (NILP (gl_state.object))
     {
-      gl_state.b_property = 1;
-      gl_state.e_property = ZV - BEGV + 1;
-      gl_state.offset = BEGV - 1;
+      gl_state.b_property = BEG;
+      gl_state.e_property = ZV; /* FIXME: Why not +1 like in 
SETUP_SYNTAX_TABLE? */
     }
   else if (EQ (gl_state.object, Qt))
     {
       gl_state.b_property = 0;
       gl_state.e_property = PTRDIFF_MAX;
-      gl_state.offset = 0;
     }
   else
     {
       gl_state.b_property = 0;
       gl_state.e_property = 1 + SCHARS (gl_state.object);
-      gl_state.offset = 0;
     }
   if (parse_sexp_lookup_properties)
-    update_syntax_table (from + gl_state.offset - (count <= 0),
-                        count, 1, gl_state.object);
+    update_syntax_table (RE_SYNTAX_TABLE_BYTE_TO_CHAR (frombyte),
+                        1, 1, gl_state.object);
 }
 
 /* Update gl_state to an appropriate interval which contains CHARPOS.  The
@@ -341,8 +332,8 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
       if (!i)
        return;
       i = gl_state.forward_i;
-      gl_state.b_property = i->position - gl_state.offset;
-      gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+      gl_state.b_property = i->position;
+      gl_state.e_property = INTERVAL_LAST_POS (i);
     }
   else
     {
@@ -362,7 +353,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            {
              invalidate = false;
              gl_state.forward_i = i;
-             gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+             gl_state.e_property = INTERVAL_LAST_POS (i);
            }
         }
       else if (charpos >= INTERVAL_LAST_POS (i)) /* Move right.  */
@@ -375,7 +366,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            {
              invalidate = false;
              gl_state.backward_i = i;
-             gl_state.b_property = i->position - gl_state.offset;
+             gl_state.b_property = i->position;
            }
         }
     }
@@ -391,12 +382,12 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
       if (count > 0)
        {
          gl_state.backward_i = i;
-         gl_state.b_property = i->position - gl_state.offset;
+         gl_state.b_property = i->position;
        }
       else
        {
          gl_state.forward_i = i;
-         gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
+         gl_state.e_property = INTERVAL_LAST_POS (i);
        }
     }
 
@@ -426,13 +417,13 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
        {
          if (count > 0)
            {
-             gl_state.e_property = i->position - gl_state.offset;
+             gl_state.e_property = i->position;
              gl_state.forward_i = i;
            }
          else
            {
              gl_state.b_property
-               = i->position + LENGTH (i) - gl_state.offset;
+               = i->position + LENGTH (i);
              gl_state.backward_i = i;
            }
          return;
@@ -442,7 +433,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
          if (count > 0)
            {
              gl_state.e_property
-               = i->position + LENGTH (i) - gl_state.offset
+               = i->position + LENGTH (i)
                /* e_property at EOB is not set to ZV but to ZV+1, so that
                   we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
                   having to check eob between the two.  */
@@ -451,7 +442,7 @@ update_syntax_table (ptrdiff_t charpos, EMACS_INT count, 
bool init,
            }
          else
            {
-             gl_state.b_property = i->position - gl_state.offset;
+             gl_state.b_property = i->position;
              gl_state.backward_i = i;
            }
          return;
@@ -2201,8 +2192,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, 
Lisp_Object lim)
            while (!parse_sexp_lookup_properties
                   || pos < gl_state.e_property);
 
-           update_syntax_table_forward (pos + gl_state.offset,
-                                        false, gl_state.object);
+           update_syntax_table_forward (pos, false, gl_state.object);
          }
       }
     else
diff --git a/src/syntax.h b/src/syntax.h
index 9eb8701628b..01982be25a0 100644
--- a/src/syntax.h
+++ b/src/syntax.h
@@ -85,8 +85,6 @@ struct gl_state_s
                                           and possibly at the
                                           intervals too, depending
                                           on:  */
-  /* Offset for positions specified to UPDATE_SYNTAX_TABLE.  */
-  ptrdiff_t offset;
 };
 
 extern struct gl_state_s gl_state;
@@ -147,28 +145,27 @@ extern bool syntax_prefix_flag_p (int c);
 
 extern unsigned char const syntax_spec_code[0400];
 
-/* Convert the byte offset BYTEPOS into a character position,
-   for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT.
+/* Convert the regexp's BYTEOFFSET into a character position,
+   for the object recorded in gl_state with RE_SETUP_SYNTAX_TABLE_FOR_OBJECT.
 
    The value is meant for use in code that does nothing when
    parse_sexp_lookup_properties is false, so return 0 in that case,
    for speed.  */
 
 INLINE ptrdiff_t
-SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos)
+RE_SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t byteoffset)
 {
   return (! parse_sexp_lookup_properties
          ? 0
          : STRINGP (gl_state.object)
-         ? string_byte_to_char (gl_state.object, bytepos)
+         ? string_byte_to_char (gl_state.object, byteoffset)
          : BUFFERP (gl_state.object)
          ? ((buf_bytepos_to_charpos
              (XBUFFER (gl_state.object),
-              (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1)))
-            - BUF_BEGV (XBUFFER (gl_state.object)) + 1)
+              (byteoffset + BUF_BEGV_BYTE (XBUFFER (gl_state.object))))))
          : NILP (gl_state.object)
-         ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) - BEGV + 1
-         : bytepos);
+         ? BYTE_TO_CHAR (byteoffset + BEGV_BYTE)
+         : byteoffset);
 }
 
 /* Make syntax table state (gl_state) good for CHARPOS, assuming it is
@@ -178,8 +175,7 @@ INLINE void
 UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos)
 { /* Performs just-in-time syntax-propertization.  */
   if (parse_sexp_lookup_properties && charpos >= gl_state.e_property)
-    update_syntax_table_forward (charpos + gl_state.offset,
-                                false, gl_state.object);
+    update_syntax_table_forward (charpos, false, gl_state.object);
 }
 
 /* Make syntax table state (gl_state) good for CHARPOS, assuming it is
@@ -189,7 +185,7 @@ INLINE void
 UPDATE_SYNTAX_TABLE_BACKWARD (ptrdiff_t charpos)
 {
   if (parse_sexp_lookup_properties && charpos < gl_state.b_property)
-    update_syntax_table (charpos + gl_state.offset, -1, false, 
gl_state.object);
+    update_syntax_table (charpos, -1, false, gl_state.object);
 }
 
 /* Make syntax table good for CHARPOS.  */
@@ -212,7 +208,7 @@ SETUP_BUFFER_SYNTAX_TABLE (void)
 }
 
 extern ptrdiff_t scan_words (ptrdiff_t, EMACS_INT);
-extern void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t, ptrdiff_t);
+extern void RE_SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t);
 
 INLINE_HEADER_END
 



reply via email to

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