diff options
| author | Juri Linkov | 2024-11-29 09:35:13 +0200 |
|---|---|---|
| committer | Juri Linkov | 2024-11-29 09:35:13 +0200 |
| commit | a52ad71cc5d036f1973ff2e504e45992fec3fc04 (patch) | |
| tree | 2e2484c09ae17a29af95cc7e06874508addc8987 | |
| parent | e54c218d661c2d2f6f693342d2cf78d4be754d65 (diff) | |
| download | emacs-a52ad71cc5d036f1973ff2e504e45992fec3fc04.tar.gz emacs-a52ad71cc5d036f1973ff2e504e45992fec3fc04.zip | |
* lisp/progmodes/c-ts-mode.el: Improve logic of outlines (bug#74448).
(c-ts-mode--outline-predicate): Instead of checking only for
function_declarator nodes at the beginning of line (like in
GNU coding style) handle other coding styles that start the
function line with either storage class (e.g. static) or type.
Suggested by Filippo Argiolas <filippo.argiolas@gmail.com>
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index c815ee35501..9bbb78e0862 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -973,9 +973,14 @@ Return nil if NODE is not a defun node or doesn't have a name." | |||
| 973 | 973 | ||
| 974 | (defun c-ts-mode--outline-predicate (node) | 974 | (defun c-ts-mode--outline-predicate (node) |
| 975 | "Match outlines on lines with function names." | 975 | "Match outlines on lines with function names." |
| 976 | (or (and (equal (treesit-node-type node) "function_declarator") | 976 | (or (when-let* ((decl (treesit-node-child-by-field-name |
| 977 | (equal (treesit-node-type (treesit-node-parent node)) | 977 | (treesit-node-parent node) "declarator")) |
| 978 | "function_definition")) | 978 | (node-pos (treesit-node-start node)) |
| 979 | (decl-pos (treesit-node-start decl)) | ||
| 980 | (eol (save-excursion (goto-char node-pos) (line-end-position)))) | ||
| 981 | (and (equal (treesit-node-type decl) "function_declarator") | ||
| 982 | (<= node-pos decl-pos) | ||
| 983 | (< decl-pos eol))) | ||
| 979 | ;; DEFUNs in Emacs sources. | 984 | ;; DEFUNs in Emacs sources. |
| 980 | (and c-ts-mode-emacs-sources-support | 985 | (and c-ts-mode-emacs-sources-support |
| 981 | (c-ts-mode--emacs-defun-p node)))) | 986 | (c-ts-mode--emacs-defun-p node)))) |