diff options
| author | Eli Zaretskii | 2023-04-28 08:40:56 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2023-04-28 08:40:56 +0300 |
| commit | d3ca0b3aa2ecdac799d6ef7dd50f613cb032d8e0 (patch) | |
| tree | 376421d694bf3b022ea67251a5fc02f54804e9ae | |
| parent | c6f15c2486253dbbcb466d12c4af7277c03c8288 (diff) | |
| download | emacs-d3ca0b3aa2ecdac799d6ef7dd50f613cb032d8e0.tar.gz emacs-d3ca0b3aa2ecdac799d6ef7dd50f613cb032d8e0.zip | |
; * lisp/progmodes/c-ts-mode.el: Fix comments and doc strings (bug#62951).
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 8f7a0f26b44..7a1ee66cb77 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -971,24 +971,25 @@ if `c-ts-mode-emacs-sources-support' is non-nil." | |||
| 971 | (or (treesit-add-log-current-defun) | 971 | (or (treesit-add-log-current-defun) |
| 972 | (c-ts-mode--defun-name (c-ts-mode--emacs-defun-at-point)))) | 972 | (c-ts-mode--defun-name (c-ts-mode--emacs-defun-at-point)))) |
| 973 | 973 | ||
| 974 | ;;; FOR_EACH_TAIL fix | 974 | ;;; Support for FOR_EACH_* macros |
| 975 | ;; | 975 | ;; |
| 976 | ;; FOR_EACH_TAIL (and FOR_EACH_TAIL_SAFE) followed by a unbracketed | 976 | ;; FOR_EACH_TAIL, FOR_EACH_TAIL_SAFE, FOR_EACH_FRAME etc., followed by |
| 977 | ;; body will mess up the parser, which parses the thing as a function | 977 | ;; an unbracketed body will mess up the parser, which parses the thing |
| 978 | ;; declaration. We "fix" it by adding a shadow parser, emacs-c (which | 978 | ;; as a function declaration. We "fix" it by adding a shadow parser |
| 979 | ;; is just c but under a different name). We use emacs-c to find each | 979 | ;; for a language 'emacs-c' (which is just 'c' but under a different |
| 980 | ;; FOR_EACH_TAIL with a unbracketed body, and set the ranges of the C | 980 | ;; name). We use 'emacs-c' to find each FOR_EACH_* macro with a |
| 981 | ;; parser so that it skips those FOR_EACH_TAIL's. Note that we only | 981 | ;; unbracketed body, and set the ranges of the C parser so that it |
| 982 | ;; ignore FOR_EACH_TAIL's with a unbracketed body. Those with a | 982 | ;; skips those FOR_EACH_*'s. Note that we only ignore FOR_EACH_*'s |
| 983 | ;; bracketed body parses more or less fine. | 983 | ;; with a unbracketed body. Those with a bracketed body parse more |
| 984 | ;; or less fine. | ||
| 984 | 985 | ||
| 985 | (defvar c-ts-mode--for-each-tail-regexp | 986 | (defvar c-ts-mode--for-each-tail-regexp |
| 986 | (rx "FOR_EACH_" (or "TAIL" "TAIL_SAFE" "ALIST_VALUE" | 987 | (rx "FOR_EACH_" (or "TAIL" "TAIL_SAFE" "ALIST_VALUE" |
| 987 | "LIVE_BUFFER" "FRAME")) | 988 | "LIVE_BUFFER" "FRAME")) |
| 988 | "A regexp matching all the FOR_EACH_TAIL variants.") | 989 | "A regexp matching all the variants of the FOR_EACH_* macro.") |
| 989 | 990 | ||
| 990 | (defun c-ts-mode--for-each-tail-body-matcher (_n _p bol &rest _) | 991 | (defun c-ts-mode--for-each-tail-body-matcher (_n _p bol &rest _) |
| 991 | "A matcher that matches the first line after a FOR_EACH_TAIL. | 992 | "A matcher that matches the first line after a FOR_EACH_* macro. |
| 992 | For BOL see `treesit-simple-indent-rules'." | 993 | For BOL see `treesit-simple-indent-rules'." |
| 993 | (when c-ts-mode-emacs-sources-support | 994 | (when c-ts-mode-emacs-sources-support |
| 994 | (save-excursion | 995 | (save-excursion |
| @@ -1005,10 +1006,10 @@ For BOL see `treesit-simple-indent-rules'." | |||
| 1005 | @for-each-tail) | 1006 | @for-each-tail) |
| 1006 | (:match ,c-ts-mode--for-each-tail-regexp | 1007 | (:match ,c-ts-mode--for-each-tail-regexp |
| 1007 | @_name)))) | 1008 | @_name)))) |
| 1008 | "Query that finds the FOR_EACH_TAIL with a unbracketed body.") | 1009 | "Query that finds a FOR_EACH_* macro with an unbracketed body.") |
| 1009 | 1010 | ||
| 1010 | (defvar-local c-ts-mode--for-each-tail-ranges nil | 1011 | (defvar-local c-ts-mode--for-each-tail-ranges nil |
| 1011 | "Ranges covering all the FOR_EACH_TAIL's in the buffer.") | 1012 | "Ranges covering all the FOR_EACH_* macros in the buffer.") |
| 1012 | 1013 | ||
| 1013 | (defun c-ts-mode--reverse-ranges (ranges beg end) | 1014 | (defun c-ts-mode--reverse-ranges (ranges beg end) |
| 1014 | "Reverse RANGES and return the new ranges between BEG and END. | 1015 | "Reverse RANGES and return the new ranges between BEG and END. |
| @@ -1031,7 +1032,7 @@ parser parse the whole buffer." | |||
| 1031 | (nreverse new-ranges)))) | 1032 | (nreverse new-ranges)))) |
| 1032 | 1033 | ||
| 1033 | (defun c-ts-mode--emacs-set-ranges (beg end) | 1034 | (defun c-ts-mode--emacs-set-ranges (beg end) |
| 1034 | "Set ranges for the C parser to skip some FOR_EACH_TAIL's. | 1035 | "Set ranges for the C parser to skip some FOR_EACH_* macros. |
| 1035 | BEG and END are described in `treesit-range-rules'." | 1036 | BEG and END are described in `treesit-range-rules'." |
| 1036 | (let* ((c-parser (treesit-parser-create 'c)) | 1037 | (let* ((c-parser (treesit-parser-create 'c)) |
| 1037 | (old-ranges c-ts-mode--for-each-tail-ranges) | 1038 | (old-ranges c-ts-mode--for-each-tail-ranges) |
| @@ -1150,7 +1151,7 @@ in your configuration." | |||
| 1150 | 1151 | ||
| 1151 | (when (treesit-ready-p 'c) | 1152 | (when (treesit-ready-p 'c) |
| 1152 | ;; Add a fake "emacs-c" language which is just C. Used for | 1153 | ;; Add a fake "emacs-c" language which is just C. Used for |
| 1153 | ;; skipping FOR_EACH_TAIL, see `c-ts-mode--emacs-set-ranges'. | 1154 | ;; skipping FOR_EACH_* macros, see `c-ts-mode--emacs-set-ranges'. |
| 1154 | (setf (alist-get 'emacs-c treesit-load-name-override-list) | 1155 | (setf (alist-get 'emacs-c treesit-load-name-override-list) |
| 1155 | '("libtree-sitter-c" "tree_sitter_c")) | 1156 | '("libtree-sitter-c" "tree_sitter_c")) |
| 1156 | ;; If Emacs source support is enabled, make sure emacs-c parser is | 1157 | ;; If Emacs source support is enabled, make sure emacs-c parser is |
| @@ -1173,7 +1174,7 @@ in your configuration." | |||
| 1173 | (setq-local treesit-defun-tactic 'top-level) | 1174 | (setq-local treesit-defun-tactic 'top-level) |
| 1174 | (treesit-major-mode-setup) | 1175 | (treesit-major-mode-setup) |
| 1175 | 1176 | ||
| 1176 | ;; Emacs source support: handle DEFUN and FOR_EACH_TAIL gracefully. | 1177 | ;; Emacs source support: handle DEFUN and FOR_EACH_* gracefully. |
| 1177 | (when c-ts-mode-emacs-sources-support | 1178 | (when c-ts-mode-emacs-sources-support |
| 1178 | (setq-local add-log-current-defun-function | 1179 | (setq-local add-log-current-defun-function |
| 1179 | #'c-ts-mode--emacs-current-defun-name) | 1180 | #'c-ts-mode--emacs-current-defun-name) |