In my lisp code, I need to switch to cc-mode, do something and back to original mode (text mode). How to do that ?
-
You can simply call those functions; but... why do you need to do that? If you elaborate, other solutions might become clear.– philsAug 15, 2022 at 2:00
-
in particular, I want to call (indent-region) on a block of C code to format it, but the document is not a C source file.– emacs-user-2021Aug 15, 2022 at 4:11
-
You should add that information to the question. Be specific!– db48xAug 15, 2022 at 5:57
-
I wonder if this is a duplicate question. This is essentially just asking how to switch to a different major mode temporarily.– DrewAug 15, 2022 at 16:48
1 Answer
Any time you want to compose function calls in a sequence, you just put them one after the other inside of a function, like this:
(defun do-the-thing ()
(interactive)
(cc-mode)
(indent-region)
(normal-mode))
There are a few cases where you need to use progn
instead, but we’ll leave that for the advanced course.
-
Unfortunatly,calling it it gave me error: "Symbol’s function definition is void: cc-mode" Aug 18, 2022 at 3:52
-
Use whatever mode you want the buffer to be in. Several modes, such as
c-mode
andc++-mode
andjava-mode
and so on are derived fromcc-mode
. Let me know which one you want and I will edit the answer.– db48xAug 18, 2022 at 4:03