0

In my lisp code, I need to switch to cc-mode, do something and back to original mode (text mode). How to do that ?

4
  • You can simply call those functions; but... why do you need to do that? If you elaborate, other solutions might become clear.
    – phils
    Aug 15 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. Aug 15 at 4:11
  • You should add that information to the question. Be specific!
    – db48x
    Aug 15 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.
    – Drew
    Aug 15 at 16:48

1 Answer 1

1

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.

2
  • Unfortunatly,calling it it gave me error: "Symbol’s function definition is void: cc-mode" Aug 18 at 3:52
  • Use whatever mode you want the buffer to be in. Several modes, such as c-mode and c++-mode and java-mode and so on are derived from cc-mode. Let me know which one you want and I will edit the answer.
    – db48x
    Aug 18 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.