Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [indentation]

Indenting is used to organize code by indicating blocks, closures, conditionals, and other constructs. It makes code easier to read, and in some languages is used to handle control flow.

16
votes
2answers
7k views

Completely disable all auto-indentation

How do I completely disable all auto-indentation in Emacs? I need to disable it at least for Fundamental mode, but I'm fine with it being disabled globally for the current session. Please read the ...
34
votes
2answers
18k views

How to disable auto-indentation of new lines?

I've recently upgraded emacs to version 24.4.1 and something has changed in the indentation of new lines. When I hit enter I expect just "bare" new line character at point where cursor was present, in ...
14
votes
1answer
2k views

Correct indentation for wrapped lines

I have the following wrapped text, especially when you use a lot of windows: I'm wondering if the indentation of wrapped text could be changed like in Vim: ) When figuring out, it seems the ...
15
votes
1answer
2k views

How to indent items in LaTeX/AUCTeX itemize environments?

Q: how can I get "proper" indentation of LaTeX itemize environments in auctex? Here's where I'd like to be with an item in an itemize environment: \item line is indented two spaces relative to the ...
6
votes
3answers
749 views

Customizing c-mode indentation behavior in Emacs 24.4

Before Emacs 24.4, indentation in c-mode happened after typing things like ;, , and so on and I like this behavior. But in Emacs 24.4, c-mode also indents on RET. This causes a lot of problems for me ...
18
votes
4answers
1k views

Automatically re-indenting elisp code when adding or removing code before an indented block

Say I have a elisp code like: (+ 2 3▮(+ 3 4)) Is there a way to automatically re-indent the sexp after the cursor, when I add or remove symbols? So after pressing SPC 4 SPC, I would ...
10
votes
1answer
3k views

python auto indent problem

I'm using Emacs 24.4. When writing Python code, Emacs behaves strangely with respect to indentation. For example: for i in range(10): print(i) for i in range(10) When I input :, Emacs adds a ...
8
votes
1answer
320 views

formatting constexpr if in c++-mode

I recently started using C++17, which brings constexpr if. This however screws up c++-modes default indentation. // emacs 25.3.2 with --no-init if constexpr (n == 1) { // Why? } else if ...
5
votes
1answer
408 views

Whitespace-mode tab mark disturb my indentation

I encounter this issue when i set whitespace-style to (face tabs trailing tab-mark) and turn on whitespace-mode. When whitespace-mode is turned off, everything looks well: When whitespace-mode is ...
2
votes
1answer
631 views

Python docstrings only allow two indent levels

I am trying to write a docstring that follows Google's style guide such that it looks something like: def testFunction(a, b): """ Args: a (str): b (str): Returns: ...
5
votes
2answers
674 views

Change the behaviour of RET (with electric indent) to only indent the new line, not the previous one

https://stackoverflow.com/questions/27077770/how-do-i-disable-electric-indent-on-ret-but-still-keep-other-electric-characters asks and answers how to disable electric indent when pressing RET. All ...
5
votes
4answers
1k views

Confusion by the usage of indent-tabs-mode nil

I use (setq-default indent-tabs-mode nil) in my init file so to avoid using TABs but when I write some files (like C++ files) then it allows me to insert TABs if I am in an if-statement for example. ...
4
votes
1answer
192 views

How can I configure AUCTeX to use tab characters for leading indentation?

I configure indent-tabs-mode to t so that tab characters are used for indentation by default. AUCTeX apparently changes the value of indent-tabs-mode to nil and uses some other system for handling ...
12
votes
2answers
4k views

Better indentation and navigation in assembly source code

When I write C or Java code it's extremely regular, but with assembly (asm-mode), it's so disorganized. I'm using auto-complete and yasnippet. I created snippets and am using them, but the code ...
10
votes
3answers
2k views

How to auto-format the source code block in org-mode

When I'm using org-mode to take notes about a book, sometimes I'll copy/paste some code snippets into the note file. After pasting it, I'll 1. `C-c '` to call `org-edit-special` 2. `C-x h` to mark ...
7
votes
2answers
1k views

Modifying the indentation of some Emacs Lisp forms

I would like some Emacs Lisp forms to be indented like Common Lisp. For instance, in Emacs Lisp, if is indented like this: (if COND THEN ELSE) whilst I would prefer it like this: (if COND ...
11
votes
1answer
1k views

Coloring indentation levels

Consider the following two snapshots: The first below is coming from Emacs on Python mode (with Jedi & Elpy) This second one below comes from manually photoshopping the previous one to make it ...
8
votes
3answers
737 views

Ruby always indent 2 spaces?

I would like to use 2-space indents all the time like: sidekiq_options({ retry: true }) I've tried setting .emacs.d/init.el to: (setq-default indent-tabs-mode nil) (setq-default tab-width 2) (...
7
votes
1answer
3k views

“Format Code” like in Eclipse

In Eclipse, I can hit CTRL + SHIFT + F which not only corrects the indentation but also whitespace (for example: c=a +b ; is corrected to c = a + b;) and the line length. I am looking for a similar ...
3
votes
2answers
621 views

How can I disable indentation rules within docstrings in python-mode?

When writing within docstrings in python-mode, I'm only able to tab/indent deeper than the leading edge of the string. For example: def foo(): """ | | << the only places I can "tab" to. ...
4
votes
1answer
1k views

Trouble adjusting tab-width

When I write Python code, I personally prefer indenting with 4 spaces instead of a tab. However, in my day job I work with a codebase that uses only tabs. When I open one of these files in emacs, ...
3
votes
1answer
583 views

Return heavily indents previous line

If I'm editing certain filetypes then sometimes when I hit return at the end of a line the cursor will move to the next line and the previous line will suddenly be heavily indented. This behavior ...
3
votes
1answer
87 views

Indenting specific environment deeper in AUCTeX

Is it possible to encourage AUCTeX to indent specific environment contents deeper than other environments? My specific case is getting the following indentation for chorus: \begin{song} \begin{verse} ...
0
votes
1answer
202 views

How to Self Insert Tab When Editing String In go-mode?

The title contains the crux of my question. In go-mode, tabs and auto-indentation generally works well, except when I am editing strings. When inside of a string, I'd like the tab key to self-insert. ...
12
votes
1answer
256 views

View code with different indentation than saved to disk

I work on some projects with indentation styles that I find really irritating. I'd like to view the code with a certain indentation style, but always save to disk with the prescribed indentation ...
10
votes
2answers
4k views

Make web-mode always indent with spaces

I am using emacs web-mode, and the tabbing in JS files seems to be acting strangely. I have tab set to indent 2 spaces, but when the indent reaches 8 spaces, web-mode turns them into a tab, and then ...
9
votes
2answers
985 views

Customizing indentation in makefile mode?

In my makefiles, I prefer the following indentation for continuation lines: FILES:= \ file1.cpp \ file2.cpp \ fileYetAnother.cpp LIBS:= \ ...
7
votes
2answers
687 views

Why does Emacs indent my Lisp LOOP construct weirdly?

I'm using Emacs and SLIME to edit Lisp code. By default, Emacs indents my Lisp LOOP constructs like this: (loop for x across dna1 for y across dna2 count (not (eql x y))) But I expect it to ...
5
votes
2answers
181 views

copy region without leading indentation

I often find myself copying a region of code that is deep inside the indented structure. Since I don't want it to end up in a codeblock with superfluous indentation (given that the context is missing),...
4
votes
1answer
609 views

How to turn off alignment-indent after line continuation in Shell-script mode?

In Shell-script[sh] mode, Emacs defaults to this style of indentation: /this/is/an/example/command/broken/over_multiple_lines which \ causes \ ...
4
votes
3answers
495 views

Dumb indentation

I want to force Emacs to do (quasi-)dumb indentation à la Eclipse. By this I mean the following: If the point is at the beginning of a line and I press tab, force shift the line 2 spaces to the right....
4
votes
1answer
298 views

Customize newline-and-indent function

I'd like to extends this function to work as usual in most cases but if current line starts with * then it should indent and then insert *. Particularly i want to use it in multi line comments, i.e: /...
4
votes
0answers
358 views

Web mode -indentation is misaligned on skipping semicolons

When i indent javascript code (inside html - web mode) that has no semicolons in it, the next statements are indented right with two extra spaces, <script> function processTemplates(){ ...
3
votes
2answers
496 views

Stop javascript-mode from lining up function parameters after newline

Using javascript-mode, functions are indented like this: console.log('Example', var1, var2); test('Example2', var1, var2); I'd like to change this so that ...
2
votes
2answers
196 views

Changing how argument lists are indented in JavaScript

Right now, my argument lists are indented by js-mode like this: some_long_function_name( one_argument, another_argument ); How can I get them to look like this: ...
2
votes
2answers
98 views

Modifying AucTeX bracket indentation locally

I am currently using songs package, which via some TeX trickery uses escaped brackets to mark chords (for example \[G] is G-major, while \[a] is a-minor). This causes problems with indentation, for ...
2
votes
0answers
640 views

Org-Mode correct indentation

I am using spacemacs and try to use full text indentation. When I execute "visual-line-mode" and "adaptive-wrap-prefix-mode" by hand via M-x the text will indent, when I edit it. Of course I tried to ...
1
vote
1answer
121 views

Emacs-Lisp mode indentation problem when doc string contains left parenthesis in first column

Usually when I write Lisp code (in an Emacs-Lisp mode buffer), I can press TAB (bound to indent-for-tab-command) to indent code properly. However, if I write a defun with a docstring (longer than one ...
1
vote
2answers
86 views

Stop reindenting `if` after `else`

Given the file test.c: int main() { if (a) foo(); else if (b) // line 6 bar(); else baz(); } Whenever a comma or paren is typed while point is on line 6 (...
1
vote
1answer
1k views

How to detect tabs or spaces in Emacs

By default I want all indentation (when I hit the tab key) to be 2 spaces. However, when I am editing certain Python files (where I can not mix tabs and spaces) I would like to use whatever the ...
0
votes
1answer
213 views

Setup c-mode indentation, braces and tabs

I've been trying to setup cc-mode based files to behave in the way I want, but with so many varying opinions and suggested ways of doing things, I've not been able to get things just right. All I ...
0
votes
1answer
131 views

Why is emacs indenting with tabs even though indent-tabs-mode is nil?

In C/l-mode F1 v indent-tabs-mode prints: indent-tabs-mode is a variable defined in `C source code'. Its value is nil Original value was t Local in buffer nir_types.cpp; global value is t But ...
0
votes
1answer
92 views

How to see the implementation of the auto-indent procedure?

I want to inspect the lisp code that handle auto-indentation. By "auto-indent" I mean the indentation that automatically puts the beginning of a line at the right position in files such as .c, .cpp, ...