summaryrefslogtreecommitdiff
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2022-12-28 21:40:59 +0100
committerStefan Kangas <stefankangas@gmail.com>2022-12-28 21:40:59 +0100
commitdce6791e9934d029ffae45793a5d05096346be0c (patch)
tree387d999b6d6af1d72dfc3416e49d445329139ed9 /lisp/textmodes
parent7e98b8a0fa67f51784024fac3199d774dfa77192 (diff)
parentdb96b1282f90ee40560f81e8b715fe785badbb6e (diff)
downloademacs-dce6791e9934d029ffae45793a5d05096346be0c.tar.gz
emacs-dce6791e9934d029ffae45793a5d05096346be0c.tar.bz2
emacs-dce6791e9934d029ffae45793a5d05096346be0c.zip
Merge from origin/emacs-29
db96b1282f9 * lisp/help.el: Use 'C-h C-q' to toggle 'help-quick' wind... 489865c21e4 ; Improve markup of long key sequences d42c2668cf3 ; * etc/NEWS: Fix wording of a recently edited entry. 7a0eaee1980 * lisp/isearch.el: Small fixes. b69bffeec05 * lisp/vc/diff-mode.el (diff-minor-mode-prefix): Replace ... 9263847ab76 ; * etc/NEWS: Move the paragraph with 'C-u RET' closer to... 62fb2dc37da * doc/emacs/display.texi (Text Scale): Improve section ab... 70480d3b6b7 * lisp/repeat.el (repeat-echo-function): Suggest 'add-fun... fd48201ffe7 * lisp/tab-line.el (tab-line-cache-key-default): More cac... b1646602602 * etc/package-keyring.gpg: Update with new key c0be51389eb ; Yet another declare-function to avoid treesit-related w... 8676bec51de ; * lisp/treesit.el (treesit--simple-imenu-1): Doc fix; w... 2ddc480f441 Warn of absent networks module in ERC 19d00fab9aa Avoid "already compiled" warning in erc-compat 2d8f7b66bcc ; Fix one more treesit byte-compilation warning. 2d0a9214863 ; Avoid treesit-related byte-compiler warnings 8503b370be1 (python--treesit-settings): Remove duplicate matcher b464e6c490b Make last change of w32 GUI dialogs conditional and rever... eedc9d79aed Fix tree-sitter typos 248c13dcfe1 Update tree-sitter major modes to use the new Imenu facility b39dc7ab27a Add tree-sitter helper functions for Imenu ba1ddea9dab Fix treesit--things-around (bug#60355) 7512b9025a1 ; * lisp/treesit.el (treesit-traverse-parent): Remove alias. 5326b041982 Improve treesit-node-top-level and treesit-parent-until 637f5b164f2 ; Add "src" to the heuristic sub-directory heuristic 8ab6df0c9fd ; * lisp/epa-ks.el (epa-ks-do-key-to-fetch): Fix 'when' u... 2b55a48d3e3 * src/w32menu.c (simple_dialog_show): Use MB_YESNOCANCEL ... 8b8b7915679 ; Improve documentation of TAB/SPC indentation 624e3822110 ; Improve doc strings of some new faces 41f12e1019b ; * lisp/elide-head.el (elide-head): Doc fix to silence c... e3b4cd0ac1d ; * lisp/htmlfontify.el (hfy-text-p): Fix whitespace. 1b4dc4691c1 Fix htmlfontify.el command injection vulnerability. 1fe4b98b4d5 Improve support for Scheme R6RS and R7RS libraries (bug#5... 2347f37f677 ; * test/src/treesit-tests.el: remove dead store (bytecom... a6d961ae2fd Add a new tree-sitter query predicate 'pred' 835a80dcc48 ; Fix tree-sitter defun tests a14821d6151 Improve gnutls-min-prime-bits docstring b14bbd108e4 Improve handling of tab-bar height. 669160d47b2 ; * nt/INSTALL.W64: More fixes and updates. 26b2ec7cb8c Simplify last change (bug#60311) 082fc6e3088 Fix 'json-available-p' on MS-Windows 6c86faec29e loaddefs-gen: Group results by absolute file name d90d7d15f2f ; Fix vindexes in parsing.texi eb268728376 Fix imenu for c-ts-mode (bug#60296) 8f68b6497ee Clean up python-ts-mode font-lock features 28f26b11a1e Add comment indent and filling to other tree-sitter major... c6b02826450 ; Remove unused function in c-ts-mode 6e52a9fcadc ; * doc/lispref/modes.texi (Parser-based Font Lock): Mino... 2bcd1e9a99d ; * doc/lispref/parsing.texi (Retrieving Nodes): Add notice. 7c7950fe006 Add maintainer stub for tree-sitter files cf327766226 ; * doc/lispref/parsing.texi (Using Parser): Remove delet... # Conflicts: # etc/NEWS # lisp/progmodes/c-ts-mode.el # lisp/progmodes/typescript-ts-mode.el # lisp/treesit.el
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/css-mode.el32
-rw-r--r--lisp/textmodes/toml-ts-mode.el42
2 files changed, 10 insertions, 64 deletions
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 99ef4f10a06..204331ec72f 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1425,33 +1425,6 @@ Return nil if there is no name or if NODE is not a defun node."
(treesit-node-start node)
(treesit-node-start block)))))))
-(defun css--treesit-imenu-1 (node)
- "Helper for `css--treesit-imenu'.
-Find string representation for NODE and set marker, then recurse
-the subtrees."
- (let* ((ts-node (car node))
- (subtrees (mapcan #'css--treesit-imenu-1 (cdr node)))
- (name (when ts-node
- (or (treesit-defun-name ts-node)
- "Anonymous")))
- (marker (when ts-node
- (set-marker (make-marker)
- (treesit-node-start ts-node)))))
- (cond
- ((or (null ts-node) (null name)) subtrees)
- (subtrees
- `((,name ,(cons name marker) ,@subtrees)))
- (t
- `((,name . ,marker))))))
-
-(defun css--treesit-imenu ()
- "Return Imenu alist for the current buffer."
- (let* ((node (treesit-buffer-root-node))
- (tree (treesit-induce-sparse-tree
- node (rx (or "rule_set" "media_statement"))
- nil 1000)))
- (css--treesit-imenu-1 tree)))
-
;;; Completion
(defun css--complete-property ()
@@ -1847,8 +1820,9 @@ can also be used to fill comments.
'((selector comment query keyword)
(property constant string)
(error variable function operator bracket)))
- (setq-local imenu-create-index-function #'css--treesit-imenu)
- (setq-local which-func-functions nil)
+ (setq-local treesit-simple-imenu-settings
+ `( nil ,(rx bos (or "rule_set" "media_statement") eos)
+ nil nil))
(treesit-major-mode-setup)))
;;;###autoload
diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el
index 790de2133e8..cbdc758d4b3 100644
--- a/lisp/textmodes/toml-ts-mode.el
+++ b/lisp/textmodes/toml-ts-mode.el
@@ -32,6 +32,8 @@
(declare-function treesit-parser-create "treesit.c")
(declare-function treesit-induce-sparse-tree "treesit.c")
(declare-function treesit-node-start "treesit.c")
+(declare-function treesit-node-type "treesit.c")
+(declare-function treesit-node-child "treesit.c")
(declare-function treesit-node-child-by-field-name "treesit.c")
(defcustom toml-ts-mode-indent-offset 2
@@ -112,39 +114,8 @@
Return nil if there is no name or if NODE is not a defun node."
(pcase (treesit-node-type node)
((or "table" "table_array_element")
- (car (cdr (treesit-node-children node))))))
-
-(defun toml-ts-mode--imenu-1 (node)
- "Helper for `toml-ts-mode--imenu'.
-Find string representation for NODE and set marker, then recurse
-the subtrees."
- (let* ((ts-node (car node))
- (subtrees (mapcan #'toml-ts-mode--imenu-1 (cdr node)))
- (name (or (treesit-defun-name ts-node)
- "Root table"))
- (marker (when ts-node
- (set-marker (make-marker)
- (treesit-node-start ts-node)))))
- (cond
- ((null ts-node) subtrees)
- (subtrees
- `((,name ,(cons name marker) ,@subtrees)))
- (t
- `((,name . ,marker))))))
-
-(defun toml-ts-mode--imenu ()
- "Return Imenu alist for the current buffer."
- (let* ((node (treesit-buffer-root-node))
- (table-tree (treesit-induce-sparse-tree
- node "^table$" nil 1000))
- (table-array-tree (treesit-induce-sparse-tree
- node "^table_array_element$" nil 1000))
- (table-index (toml-ts-mode--imenu-1 table-tree))
- (table-array-index (toml-ts-mode--imenu-1 table-array-tree)))
- (append
- (when table-index `(("Headers" . ,table-index)))
- (when table-array-index `(("Arrays" . ,table-array-index))))))
-
+ (or (treesit-node-text (treesit-node-child node 1) t)
+ "Root table"))))
;;;###autoload
(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode))
@@ -179,8 +150,9 @@ the subtrees."
(delimiter error)))
;; Imenu.
- (setq-local imenu-create-index-function #'toml-ts-mode--imenu)
- (setq-local which-func-functions nil) ;; Piggyback on imenu
+ (setq-local treesit-simple-imenu-settings
+ '(("Header" "\\`table\\'" nil nil)
+ ("Array" "\\`table_array_element\\'" nil nil)))
(treesit-major-mode-setup)))