I have a multiply nested namespace:
namespace first {namespace second {namespace third { // emacs indents three times // I want to intend here } } }
so emacs indents to the third position. However I just want a single indentation.
Is it possible to accomplish this effect simply?
Just change the value of indent-line-function to the insert-tab function and configure tab insertion as 4 spaces.
To manually insert a tab in Emacs, use ctrl-Q TAB. control-Q causes the next key to be inserted rather than interpreted as a possible command.
When this is in effect, Emacs will indent like below instead: A lower-level way to achieve this is (c-set-offset 'substatement-open 0), where substatement-open is the braces’ syntactic context. Press ‘C-c C-o’ to see the syntax at point (and customize its indentation). A partial list of the better known C styles:
5.21 How do I make Emacs “typeover” or “overwrite” instead of inserting? M-x overwrite-mode (a minor mode). This toggles overwrite-mode on and off, so exiting from overwrite-mode is as easy as another M-x overwrite-mode . On some systems, Insert toggles overwrite-mode on and off.
People new to Emacs often feel like they just want <tab> to insert a tab. This is of course possible, but discouraged. Why make Emacs dumber than it is? Emacs can figure out how much indentation you need and do the right thing! Remember, often the indentation engines of major modes can be customized.
You can also set it within Emacs: Options → Customize Emacs → Top-level Customization Group → Programming → Languages → C. Here, change ‘C Basic Offset’ and save for future sessions. This will only affect buffers opened after setting, not the ones already open. Instead of just changing the basic offset, consider switching to a particular style.
Use an an absolute indentation column inside namespace:
(defconst my-cc-style '("gnu" (c-offsets-alist . ((innamespace . [4]))))) (c-add-style "my-cc-style" my-cc-style)
Then use c-set-style to use your own style.
Note that this only works in c++-mode, c-mode doesn't know 'innamespace'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With