emacs-diffs
[Top][All Lists]
Advanced

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

master fa70076974 1/5: Merge from origin/emacs-29


From: Stefan Kangas
Subject: master fa70076974 1/5: Merge from origin/emacs-29
Date: Thu, 15 Dec 2022 15:34:51 -0500 (EST)

branch: master
commit fa70076974b5f9ed21438946fb6a1a8bf76b7c5a
Merge: db69249b76 fafcf02c85
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    Merge from origin/emacs-29
    
    fafcf02c856 Fix syntax tables of tree-sitter modes (bug#59807)
    91b8d9b7db4 ; * admin/notes/tree-sitter/build-module/build.sh: Minor ...
    1b0e282a7f8 ; Comment and stylistic change in treesit.el
    489b02d03cf * doc/misc/Makefile.in (need_emacsver): Add use-package.
---
 admin/notes/tree-sitter/build-module/build.sh |  8 +--
 doc/misc/Makefile.in                          |  3 +-
 lisp/progmodes/js.el                          |  3 +-
 lisp/progmodes/python.el                      |  1 +
 lisp/progmodes/sh-script.el                   |  1 +
 lisp/treesit.el                               | 70 ++++++++++++++++++---------
 6 files changed, 58 insertions(+), 28 deletions(-)

diff --git a/admin/notes/tree-sitter/build-module/build.sh 
b/admin/notes/tree-sitter/build-module/build.sh
index d020ee92c3..4195ea58c3 100755
--- a/admin/notes/tree-sitter/build-module/build.sh
+++ b/admin/notes/tree-sitter/build-module/build.sh
@@ -14,17 +14,17 @@ echo "Building ${lang}"
 
 ### Retrieve sources
 
-namespace="tree-sitter"
+org="tree-sitter"
 repo="tree-sitter-${lang}"
 sourcedir="tree-sitter-${lang}/src"
 grammardir="tree-sitter-${lang}"
 
 case "${lang}" in
     "dockerfile")
-        namespace="camdencheek"
+        org="camdencheek"
         ;;
     "cmake")
-        namespace="uyha"
+        org="uyha"
         ;;
     "typescript")
         sourcedir="tree-sitter-typescript/typescript/src"
@@ -37,7 +37,7 @@ case "${lang}" in
         ;;
 esac
 
-git clone "https://github.com/${namespace}/${repo}.git"; \
+git clone "https://github.com/${org}/${repo}.git"; \
     --depth 1 --quiet
 cp "${grammardir}"/grammar.js "${sourcedir}"
 # We have to go into the source directory to compile, because some
diff --git a/doc/misc/Makefile.in b/doc/misc/Makefile.in
index 49cd8e13b0..60b14172c3 100644
--- a/doc/misc/Makefile.in
+++ b/doc/misc/Makefile.in
@@ -186,7 +186,8 @@ $(foreach ifile,$(filter-out 
info.info,$(INFO_TARGETS)),$(eval $(call info_templ
 ## Extra dependencies.
 
 ## FIXME Updating this list manually is unreliable.
-need_emacsver = calc cl dired-x efaq efaq-w32 erc forms ido newsticker reftex 
remember woman
+need_emacsver = calc cl dired-x efaq efaq-w32 erc forms ido    \
+       newsticker reftex remember use-package woman
 need_emacsver_prefix = $(addprefix ${buildinfodir}/,${need_emacsver})
 
 $(need_emacsver_prefix:=.info) $(need_emacsver:=.dvi) $(need_emacsver:=.pdf) 
$(need_emacsver:=.html) : ${emacsdir}/emacsver.texi
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 88d0c373bb..13dce853bc 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -686,7 +686,7 @@ This variable is like `sgml-attribute-offset'."
     (modify-syntax-entry ?$ "_" table)
     (modify-syntax-entry ?` "\"" table)
     table)
-  "Syntax table for `js-mode'.")
+  "Syntax table for `js-mode' and `js-ts-mode'.")
 
 (defvar-local js--quick-match-re nil
   "Autogenerated regexp used by `js-mode' to match buffer constructs.")
@@ -3843,6 +3843,7 @@ Currently there are `js-mode' and `js-ts-mode'."
 
 \\<js-ts-mode-map>"
   :group 'js
+  :syntax-table js-mode-syntax-table
   (when (treesit-ready-p 'javascript)
     ;; Borrowed from `js-mode'.
     (setq-local prettify-symbols-alist js--prettify-symbols-alist)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 0e0898ffe2..ee05862550 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -6619,6 +6619,7 @@ implementations: `python-mode' and `python-ts-mode'."
   "Major mode for editing Python files, using tree-sitter library.
 
 \\{python-ts-mode-map}"
+  :syntax-table python-mode-syntax-table
   (when (treesit-ready-p 'python)
     (treesit-parser-create 'python)
     (setq-local treesit-font-lock-feature-list
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 1605e40347..458697dd22 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1611,6 +1611,7 @@ with your script for an edit-interpret-debug cycle."
   "Major mode for editing Bash shell scripts.
 This mode automatically falls back to `sh-mode' if the buffer is
 not written in Bash or sh."
+  :syntax-table sh-mode-syntax-table
   (when (treesit-ready-p 'bash)
     (setq-local treesit-font-lock-feature-list
                 '(( comment function)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 913a1d8c5b..ba81f55bb7 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1584,9 +1584,12 @@ defuns, if the value is `nested', Emacs recognizes 
nested defuns.")
 
 (defvar-local treesit-defun-skipper #'treesit-default-defun-skipper
   "A function called after tree-sitter navigation moved a step.
+
 It is called with no arguments.  By default, this function tries
 to move to the beginning of a line, either by moving to the empty
-newline after a defun, or the beginning of a defun.")
+newline after a defun, or the beginning of a defun.
+
+If the value is nil, no skipping is performed.")
 
 (defvar-local treesit-defun-prefer-top-level nil
   "When non-nil, Emacs prefers top-level defun.
@@ -1769,6 +1772,33 @@ REGEXP and PRED are the same as in 
`treesit-defun-type-regexp'."
              do (setq node cursor))
     node))
 
+;; The basic idea for nested defun navigation is that we first try to
+;; move across sibling defuns in the same level, if no more siblings
+;; exist, we move to parents's beg/end, rinse and repeat.  We never
+;; move into a defun, only outwards.
+;;
+;; Let me describe roughly what does this function do: there are four
+;; possible operations: prev-beg, next-end, prev-end, next-beg, and
+;; each of (prev-sibling next-sibling and parent) could exist or not
+;; exist.  So there are 4 times 8 = 32 situations.
+;;
+;; I'll only describe the situation when we go backward (prev-beg &
+;; prev-end), and consider only prev-sibling & parent. Deriving the
+;; reverse situations is left as an exercise for the reader.
+;;
+;; prev-beg (easy case):
+;; 1. prev-sibling or parent exists
+;;    -> go the prev-sibling/parent's beg
+;;
+;; prev-end (tricky):
+;; 1. prev-sibling exists
+;;    -> If you think about it, we are already at prev-sibling's end!
+;;       So we need to go one step further, either to
+;;       prev-prev-sibling's end, or parent's prev-sibling's end, etc.
+;; 2. prev-sibling is nil but parent exists
+;;    -> 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-defun (pos arg side &optional recursing)
   "Navigate defun ARG steps from POS.
 
@@ -1802,9 +1832,9 @@ function is called recursively."
         (pcase-let
             ((`(,prev ,next ,parent)
               (treesit--defuns-around pos regexp pred)))
-          ;; When PARENT is nil, nested and top-level are the same,
-          ;; there there is a PARENT, make PARENT to be the top-level
-          ;; parent and pretend there is no nested PREV and NEXT.
+          ;; 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)
                      parent)
             (setq parent (treesit--top-level-defun
@@ -1820,19 +1850,18 @@ function is called recursively."
                              (parent t) ; [2]
                              (t nil)))
                   ;; Special case: go to next beg-of-defun.  Set POS
-                  ;; to the end of next/parent defun, and run one more
-                  ;; step.  If there is a next defun, step over it, so
-                  ;; we only need to recurse once, so we don't need to
-                  ;; recurse if we are already recursing [1]. If there
-                  ;; is no next but a parent, keep stepping out
+                  ;; 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].
-                  (setq pos
-                        (or (treesit--navigate-defun
-                             (treesit-node-end (or next parent))
-                             1 'beg t)
-                            (throw 'term nil)))
+                  (setq pos (or (treesit--navigate-defun
+                                 (treesit-node-end (or next parent))
+                                 1 'beg t)
+                                (throw 'term nil)))
                 ;; Normal case.
                 (setq pos (funcall advance (or next parent))))
             ;; ...backward.
@@ -1841,19 +1870,16 @@ function is called recursively."
                            (parent t)
                            (t nil)))
                 ;; Special case: go to prev end-of-defun.
-                (setq pos
-                      (or (treesit--navigate-defun
-                           (treesit-node-start (or prev parent))
-                           -1 'end t)
-                          (throw 'term nil)))
+                (setq pos (or (treesit--navigate-defun
+                               (treesit-node-start (or prev parent))
+                               -1 'end t)
+                              (throw 'term nil)))
               ;; Normal case.
               (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.
-    (if (eq counter 0)
-        pos
-      nil)))
+    (if (eq counter 0) pos nil)))
 
 ;;; Activating tree-sitter
 



reply via email to

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