summaryrefslogtreecommitdiff
path: root/lisp/progmodes/c-ts-mode.el
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-02-03 18:35:33 -0800
committerYuan Fu <casouri@gmail.com>2023-02-04 15:33:26 -0800
commitb80f36b88c76b8f8ce3f2e6f9bd56aa2ccbe7b39 (patch)
tree1e4a8f660ce45e3e267778badf76362174f2835c /lisp/progmodes/c-ts-mode.el
parent671e5d9fad5852165f4e63992c91cd6f8c715004 (diff)
downloademacs-b80f36b88c76b8f8ce3f2e6f9bd56aa2ccbe7b39.tar.gz
emacs-b80f36b88c76b8f8ce3f2e6f9bd56aa2ccbe7b39.tar.bz2
emacs-b80f36b88c76b8f8ce3f2e6f9bd56aa2ccbe7b39.zip
Make c-ts-mode-set-style's effect local (bug#61245)
Now c-ts-mode-set-style's effect is local, and there is a new function c-ts-mode-set-global-style that changes the global setting. * lisp/progmodes/c-ts-mode.el: (c-ts-mode--indent-style-setter): Use c-ts-mode-set-style. (c-ts-mode-indent-style) (c-ts-mode--prompt-for-style): Minor change in docstring. (c-ts-mode-set-global-style): New function (from c-ts-mode-set-style). (c-ts-mode-set-local-style): Remove function (became c-ts-mode-set-style). (c-ts-mode-set-style): Renamed from c-ts-mode-set-local-style. * test/lisp/progmodes/c-ts-mode-resources/indent-bsd.erts: * test/lisp/progmodes/c-ts-mode-resources/indent.erts: Use c-ts-mode-set-style.
Diffstat (limited to 'lisp/progmodes/c-ts-mode.el')
-rw-r--r--lisp/progmodes/c-ts-mode.el29
1 files changed, 17 insertions, 12 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 2a164af26ea..1a8ef79dac8 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -89,18 +89,19 @@
(defun c-ts-mode--indent-style-setter (sym val)
"Custom setter for `c-ts-mode-set-style'.
+
Apart from setting the default value of SYM to VAL, also change
-the value of SYM in `c-ts-mode' and `c++-ts-mode' buffers to VAL."
+the value of SYM in `c-ts-mode' and `c++-ts-mode' buffers to VAL.
+
+SYM should be `c-ts-mode-indent-style', and VAL should be a style
+symbol."
(set-default sym val)
(named-let loop ((res nil)
(buffers (buffer-list)))
(if (null buffers)
(mapc (lambda (b)
(with-current-buffer b
- (setq-local treesit-simple-indent-rules
- (treesit--indent-rules-optimize
- (c-ts-mode--get-indent-style
- (if (derived-mode-p 'c-ts-mode) 'c 'cpp))))))
+ (c-ts-mode-set-style val)))
res)
(let ((buffer (car buffers)))
(with-current-buffer buffer
@@ -112,8 +113,8 @@ the value of SYM in `c-ts-mode' and `c++-ts-mode' buffers to VAL."
"Style used for indentation.
The selected style could be one of GNU, K&R, LINUX or BSD. If
-one of the supplied styles doesn't suffice a function could be
-set instead. This function is expected return a list that
+one of the supplied styles doesn't suffice, a function could be
+set instead. This function is expected to return a list that
follows the form of `treesit-simple-indent-rules'."
:version "29.1"
:type '(choice (symbol :tag "Gnu" gnu)
@@ -134,7 +135,7 @@ MODE is either `c' or `cpp'."
`((,mode ,@style))))
(defun c-ts-mode--prompt-for-style ()
- "Prompt for a indent style and return the symbol for it."
+ "Prompt for an indent style and return the symbol for it."
(let ((mode (if (derived-mode-p 'c-ts-mode) 'c 'c++)))
(intern
(completing-read
@@ -142,16 +143,20 @@ MODE is either `c' or `cpp'."
(mapcar #'car (c-ts-mode--indent-styles mode))
nil t nil nil "gnu"))))
-(defun c-ts-mode-set-style (style)
+(defun c-ts-mode-set-global-style (style)
"Set the indent style of C/C++ modes globally to STYLE.
This changes the current indent style of every C/C++ buffer and
-the default C/C++ indent style in this Emacs session."
+the default C/C++ indent style for `c-ts-mode' and `c++-ts-mode'
+in this Emacs session."
(interactive (list (c-ts-mode--prompt-for-style)))
(c-ts-mode--indent-style-setter 'c-ts-mode-indent-style style))
-(defun c-ts-mode-set-local-style (style)
- "Set the C/C++ indent style of the current buffer to STYLE."
+(defun c-ts-mode-set-style (style)
+ "Set the C/C++ indent style of the current buffer to STYLE.
+
+To set the default indent style globally, use
+`c-ts-mode-set-global-style'."
(interactive (list (c-ts-mode--prompt-for-style)))
(if (not (derived-mode-p 'c-ts-mode 'c++-ts-mode))
(user-error "The current buffer is not in `c-ts-mode' nor `c++-ts-mode'")