Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs - override indentation

Tags:

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?

like image 933
Anycorn Avatar asked Apr 12 '10 04:04

Anycorn


People also ask

How do I change the tab space in Emacs?

Just change the value of indent-line-function to the insert-tab function and configure tab insertion as 4 spaces.

How do you add tabs in Emacs?

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.

How do I indent in Emacs?

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:

How do I make Emacs typeover instead of insert?

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.

Is it possible to insert a tab in Emacs?

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.

How do I change the basic offset in Emacs?

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.


1 Answers

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'.

like image 70
Jürgen Hötzel Avatar answered Oct 25 '22 11:10

Jürgen Hötzel