[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 9371d488be 2/2: Merge branch 'emacs-29' of git.savannah.gnu.org
From: |
Eli Zaretskii |
Subject: |
emacs-29 9371d488be 2/2: Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/emacs into emacs-29 |
Date: |
Thu, 29 Dec 2022 04:11:59 -0500 (EST) |
branch: emacs-29
commit 9371d488be62a37788b499a7e44b1f5db158e212
Merge: 9d814bea46 784e509bde
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/emacs into emacs-29
---
lisp/progmodes/c-ts-mode.el | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 8ba6cdee42..82458ba5ad 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -118,7 +118,7 @@ MODE is either `c' or `cpp'."
`(((parent-is "translation_unit") parent-bol 0)
((node-is ")") parent 1)
((node-is "]") parent-bol 0)
- ((node-is "}") (and parent parent-bol) 0)
+ ((node-is "}") c-ts-mode--bracket-children-anchor 0)
((node-is "else") parent-bol 0)
((node-is "case") parent-bol 0)
((node-is "preproc_arg") no-indent)
@@ -133,7 +133,8 @@ MODE is either `c' or `cpp'."
((match "#endif" "preproc_if") point-min 0)
((match "preproc_function_def" "compound_statement") point-min 0)
((match "preproc_call" "compound_statement") point-min 0)
- ((parent-is "compound_statement") (and parent parent-bol)
c-ts-mode-indent-offset)
+ ((parent-is "compound_statement")
+ c-ts-mode--bracket-children-anchor c-ts-mode-indent-offset)
((parent-is "function_definition") parent-bol 0)
((parent-is "conditional_expression") first-sibling 0)
((parent-is "assignment_expression") parent-bol
c-ts-mode-indent-offset)
@@ -189,6 +190,21 @@ MODE is either `c' or `cpp'."
('linux (alist-get 'linux (c-ts-mode--indent-styles mode)))))))
`((,mode ,@style))))
+(defun c-ts-mode--bracket-children-anchor (_n parent &rest _)
+ "This anchor is used for children of a compound_statement.
+So anything inside a {} block. PARENT should be the
+compound_statement. This anchor looks at the {, if itson its own
+line, anchor at it, if it has stuff before it, anchor at the
+beginning of grandparent."
+ (save-excursion
+ (goto-char (treesit-node-start parent))
+ (let ((bol (line-beginning-position)))
+ (skip-chars-backward " \t")
+ (treesit-node-start
+ (if (< bol (point))
+ (treesit-node-parent parent)
+ parent)))))
+
(defun c-ts-mode--looking-at-star (&rest _)
"A tree-sitter simple indent matcher.
Matches if there is a \"*\" after point (ignoring whitespace in
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-29 9371d488be 2/2: Merge branch 'emacs-29' of git.savannah.gnu.org:/srv/git/emacs into emacs-29,
Eli Zaretskii <=