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.

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 ...
29
votes
5answers
2k views

Different indentation styles for different projects

I work on many different C projects with unique indentation styles. How do I get Emacs to do per-project indentation settings without polluting the upstream project trees with .dir-locals.el files? I ...
19
votes
3answers
14k views

How to pretty-format code (auto-insert newlines, indent, etc)?

I'm using spacemacs but presumably it's emacs knowledge that's required here. I have a JSON file with a single long line, let's say this JSON from json.org/example: {"menu": {"id": "file", "value": "...
19
votes
2answers
559 views

Is there any SMIE documentation that is clear?

I've spent many, many hours now trying to get any sort of SMIE indentation rule/grammar/thing working. Are there any examples of a small, toy or skeleton SMIE-based mode with documentation on how it ...
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 ...
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 ...
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 ...
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 ...
13
votes
3answers
285 views

Navigate by indentation

I want to navigate between the lines of a file based on indentation. The file is structured by indentation: a line that's more indented than the previous line is a child of the previous line, a line ...
12
votes
4answers
2k views

How to customize org-mode indentation?

this question actually arises because I like to use non-monospaced fonts, (Sabon, Minion, Garamond, etc.) This cause a problem when use org-indent-mode, since the text under the headlines are now not ...
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 ...
12
votes
1answer
170 views

Auto-Indenting \if statements with AUCTeX

The current AUCTeX behaviour for primitive tex code involving if-like statements is to indent the conditional statement at the same level as the surrounding condition. I.e. code such as \if@...
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 ...
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 ...
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 ...
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 ...
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 ...
10
votes
2answers
718 views

Is there an Emacs mode convenient for writing poetry?

I've tried simple searches on Google and MELPA with keywords like "emacs poetry mode" or "emacs verse mode" but haven't found anything specifically built for the purpose. The manual walks through ...
9
votes
2answers
491 views

How can I write [0,1) in LaTeX mode without breaking indentation?

When writing LaTeX using latex-mode, I often want to write "half-open intervals" in my text. For instance, [0,1), which refers to the set of all numbers x with 0 <= x < 1. Unfortunately, ...
9
votes
3answers
4k views

Set indentation for shell script function

I am trying to set the number of spaces per indent for starting a new function in sh-mode (bash sub-mode). I have tried setting: '(sh-basic-offset 2) '(sh-indentation 2) '(smie-indent-basic 2) (as ...
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:= \ ...
8
votes
1answer
220 views

Indentation in square brackets

Yet another question about indentation in AUCTeX... I would like to be able to indent content inside square brackets [...]. It would be useful for tikz option lists, for example, or trees drawn using ...
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 ...
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) (...
8
votes
0answers
135 views

Custom indentation for specific lines?

I currently try to figure out, how I can handle some lines specifically without messing up the indentation of the rest of the buffer. Consider the following function MyFunc as an example: void MyFunc(...
7
votes
2answers
2k views

no html/jsx indentation in jsx-mode

For some reason the html/jsx in my react source files always wants to indent as follows, i.e. there is almost no indentation: return ( <DateRangePicker ranges={this.state.ranges} startDate={this....
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 ...
7
votes
2answers
995 views

Commented lines shoot off to column 32 in octave-mode

I am using the octave major mode for editing my MATLAB code, since it is more convenient than the unsupported MATLAB packages for emacs on the internet. One downside is whenever I try to auto-indent ...
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 ...
7
votes
3answers
510 views

How to make emacs align and indent a bibtex entry?

I want bibtex-mode to align and properly indent fields. I copied a bibtex entry for the following article into Emacs: (Article source here) But, with a simple paste, the alignment is lost in Emacs ...
7
votes
2answers
110 views

How to highlight preceeding space-indentation that isn't rounded to current width?

Is there a way to highlight (set the background color for example) the space before a line, when it's indentation isn't aligned to the current indentation-width? 4 spaces indentation for eg: fn ...
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 ...
7
votes
2answers
975 views

Indent with 4 spaces, but display 2

At work, we have a policy which states that we have to use 4 spaces for indentation, and in my opinion it makes the code harder to read. Is it possible to indent with 4 spaces, but display it as 2 ...
7
votes
0answers
358 views

Display tab characters as arrows of varying length

I would like to make tab characters ("\t") display as arrows of varying length, just like in editors such as Notepad++, gedit, Geany, etc. Here is an example with tab width set to 4 and space ...
6
votes
1answer
2k views

How to set indent to 4 spaces in nxml-mode?

I wanted to indent my XML files with 4 spaces. I tried to google it, and found this and this one. But they seem pretty old and/or didn't help me. This post is great about how to pretty print XML ...
6
votes
2answers
140 views

Python cycling through indentation

Cycling through indentation levels in python.el 1 can be achieved by pressing <tab> repeatedly, which is bound to indent-for-tab-command. Now, consider: (defun malb/my-indent (&optional ...
6
votes
2answers
165 views

Org-mode : disable indentation when promoting and demoting trees + subtrees

In org-mode, when you press M-S-right or M-S-left to demote or promote a tree with all it's subtrees, the content text is also indented. So suppose I want to deomote the following structure by two ...
6
votes
1answer
574 views

How to indent without the two extra spaces at the beginning of code blocks in org mode?

By default org mode source blocks looks like: #+BEGIN_SRC emacs-lisp (dcg/add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") ...
6
votes
2answers
2k views

How prettify (newlines and indentation) an optimized HTML/JS file?

For example, I have the following bunch of characters (HTML): http://pastebin.com/pwTPp8wd I thought everyone stumbled it upon a processed file, especially when someone would speed up the processing ...
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 ...
6
votes
3answers
234 views

How can I hide indentation on a narrowed defun?

When I'm in the middle of implementing a new function, I like to narrow my source buffer to just that function (C-x n d). However, this leaves the function indented as it was. I would like to have ...
6
votes
1answer
716 views

How to change lisp mode indentation style

I'm not a lisp programmer. But I'm an emacs user, so I use elisp from times to times to do simple scripting. I'm not familiar with lisp style and I'm quite incompatible with it. Default indents ...
6
votes
1answer
90 views

Indentation of list constants

Emacs' indentation of Emacs lisp code is really great, except for one thing: (defconst one-to-ten '(one two three four five six seven eight nine ...
6
votes
1answer
461 views

Prevent electric-indent-mode from reindenting the current line on RET

I am using the Spacemacs configuration files. When I am typing code, electric-indent-mode reindents the current line whenever I press enter. This often causes the indentation to be incorrect when ...
6
votes
0answers
192 views

How to properly indent application in scheme-mode?

The scheme-mode indents application in this way: (define (x) (x 1 2)) But when the function to apply is the result of another application scheme-mode indents the code this way: (define (f) ...
6
votes
2answers
571 views

Do not align nested calls when using ruby-smie

When using the newly added ruby formatting functionality I face the following problem: I would really like for my rspec code to be formatted like the following: it do is_expected.to match(/\[Error\...
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. ...
5
votes
2answers
749 views

Is there a function that returns the position of the first and last non-whitespace characters in a line?

I have a sentence. For example: foo bar When I do gl in Evil normal modus, that sentence turns into: ;; EDH: foo bar ;; ------------ So I need to bind the keys gl to a function, that will turn the ...
5
votes
2answers
760 views

Auto indent plain list content?

When I make a plain list like this: - Pizza making This is an elaborate process that involves many years of training. Usually I have to manually press TAB on every new line. Can this be ...
5
votes
2answers
2k views

change python indent in a specific file

I have a piece of legacy code in Python that uses inconsistent tabs - 2 spaces in some instances and 4 in others. I have my defaults set in my .emacs file to use 4 spaces, but in this case emacs ...