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.

Filter by
Sorted by
Tagged with
48 votes
5 answers
30k 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 ...
WeSenseASoulInSearchOfAnswers's user avatar
17 votes
1 answer
4k 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 ...
ReneFroger's user avatar
  • 3,870
20 votes
2 answers
15k 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 ...
Mr Fooz's user avatar
  • 303
17 votes
1 answer
4k 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 ...
Dan's user avatar
  • 33k
6 votes
4 answers
4k 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. ...
Adam's user avatar
  • 2,447
6 votes
3 answers
900 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 ...
fghj's user avatar
  • 193
4 votes
1 answer
311 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 ...
DGrady's user avatar
  • 265
1 vote
1 answer
393 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 ...
Rovanion's user avatar
  • 987
18 votes
4 answers
2k 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 ...
Maciej Goszczycki's user avatar
12 votes
2 answers
2k 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 ...
AnoE's user avatar
  • 408
11 votes
1 answer
4k 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 ...
Hunger's user avatar
  • 213
11 votes
3 answers
2k 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:= \ ...
Mekk's user avatar
  • 1,047
11 votes
1 answer
925 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 ...
topisani's user avatar
  • 113
8 votes
1 answer
678 views

How to stop web-mode from reindenting after yank?

I'm editing this code: callFunction({ x: somearray, }); Then I want to extract somearray to be a variable with a copy. I cut somearray and delete the colon, then enter (_ is the cursor): const ...
Arry's user avatar
  • 213
7 votes
1 answer
3k 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, ...
elethan's user avatar
  • 4,825
6 votes
2 answers
975 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 ...
littleqz's user avatar
  • 117
3 votes
2 answers
2k 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: ...
chasely's user avatar
  • 231
3 votes
2 answers
2k views

How can I get flush left text in org-indent-mode?

I open an org file in emacs and it displays thus: I enable word wrap with M-x visual-line-mode and get: But I prefer the extra indenting of headlines provided by org indent mode, so then do M-x org-...
user2567544's user avatar
37 votes
7 answers
42k 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": "...
Emmanuel Touzery's user avatar
25 votes
5 answers
4k views

How to indent keywords aligned?

Probably influenced by Clojure, I more often use property lists as data-structures. Emacs most of the time indents them like this, `(:token ,token :token-quality ,quality) , while this ...
politza's user avatar
  • 3,336
23 votes
3 answers
1k 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 ...
Nagora's user avatar
  • 373
16 votes
3 answers
9k 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 ...
Robin Green's user avatar
14 votes
5 answers
7k 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 ...
CodyChan's user avatar
  • 2,649
13 votes
1 answer
2k 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 ...
Amelio Vazquez-Reina's user avatar
13 votes
1 answer
312 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 ...
Spacemoose's user avatar
12 votes
1 answer
326 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@...
elemakil's user avatar
  • 2,527
12 votes
2 answers
6k 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 ...
Vivian Maya's user avatar
12 votes
2 answers
5k 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 ...
dieuwe's user avatar
  • 123
11 votes
4 answers
1k 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 ...
Viesturs's user avatar
  • 825
11 votes
2 answers
2k 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 ...
purple_arrows's user avatar
9 votes
2 answers
3k 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 ...
Eleno's user avatar
  • 1,448
9 votes
3 answers
2k views

How can I make python-mode correctly indent python's match statement?

Python 3.10 added a match statement. When I try and type one in emacs 27.2, it does not indent it correctly, presumably because it does not yet have support for it. How do I get python-mode to ...
Rob Gilton's user avatar
9 votes
1 answer
384 views

indent cl-loop to respect `if else` statements

I have a hard time writing and reading cl-loops with they way they're indented by default as I can't easily tell what the control flow is: (cl-loop for x below 10 if (cl-oddp x) ...
Aquaactress's user avatar
  • 1,453
8 votes
1 answer
3k views

Why does org-mode not indent content under headings when I press tab?

In a buffer like this: * Heading ** Sub-heading content| pressing <tab> should result in this: * Heading ** Sub-heading content| Instead, nothing happens.
Atemu's user avatar
  • 322
8 votes
3 answers
2k 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) (...
zlotnika's user avatar
8 votes
1 answer
1k 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 \ ...
Malvineous's user avatar
8 votes
1 answer
3k 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 ...
gunnarw's user avatar
  • 81
8 votes
2 answers
3k 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....
flooose's user avatar
  • 521
7 votes
1 answer
4k 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 ...
Monkey Supersonic's user avatar
6 votes
2 answers
2k 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 ...
Gustav Bertram's user avatar
6 votes
2 answers
657 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),...
Jorge Israel Peña's user avatar
6 votes
1 answer
2k 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 ...
ayvango's user avatar
  • 585
4 votes
1 answer
228 views

How to tell Emacs to keep indentation in algorithmic environment?

I frequently find myself typesetting algorithms, and I choose the algorithmicx/algpseudocode package for that. I like the package, it is simple to use and has everything I typically need. The problem ...
Jeff's user avatar
  • 537
4 votes
3 answers
892 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....
NVaughan's user avatar
  • 1,481
4 votes
2 answers
2k views

Variable-pitch face breaking indentation in org mode

I want to use a variable pitch face when using org mode (for composing articles, prose, etc.) The emacs wiki suggested using buffer face mode with a hook to set the face for org mode buffers: ;; Use ...
Snelephant's user avatar
4 votes
1 answer
442 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: /...
4lex1v's user avatar
  • 603
4 votes
0 answers
389 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(){ ...
Saravana's user avatar
  • 2,071
3 votes
1 answer
3k views

How to set the default indentation width globally?

By default Emacs uses tab instead of spaces for indentation, so I changed these 2 variables to change this behavior, (setq-default indent-tabs-mode nil) ;; Disable indent with tabs (setq ...
apoorv569's user avatar
  • 113
3 votes
1 answer
1k 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 ...
Praxeolitic's user avatar
3 votes
2 answers
385 views

SMIE Basic Identation and Block Example

I've tried for a while to create a simple major mode that uses SMIE to perform navigation and indentation, but it seems like even the simple examples that I've found seems to break quite easily. The ...
Xaldew's user avatar
  • 1,231