57 votes
Accepted

How to disable auto-indentation of new lines?

Disable electric-indent-mode: (when (fboundp 'electric-indent-mode) (electric-indent-mode -1)) That works with any Emacs version. This annoyance or shiny-new-feature, depending on your point of view,...
user avatar
  • 69.1k
29 votes

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

json.el package provides json-pretty-print-buffer. This is what it produces for your example: { "menu": { "popup": { "menuitem": [ { "onclick": "CreateNewDoc()", ...
user avatar
  • 10.8k
21 votes
Accepted

Different indentation styles for different projects

.dir-locals.el is my preferred method when it's possible, especially as it applies to all Emacs users working on that project. For projects that are hostile to Emacs users or otherwise don't want ....
user avatar
21 votes
Accepted

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

You can use the built-in sgml-mode for this. M-x sgml-mode - Enable the sgml-mode major mode so that sgml-pretty-print command auto-loads. C-x h - Select the whole buffer. M-x sgml-pretty-print To ...
user avatar
  • 24.2k
21 votes
Accepted

Completely disable all auto-indentation

Emacs ≤24.3 Pressing RET doesn't indent by default (except in some programming modes, for which you need to check mode-specific configuration, e.g. “electric” settings). Unix terminals normally ...
user avatar
19 votes

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

I finally found it in this issue. (setq nxml-child-indent 4 nxml-attribute-indent 4)
user avatar
  • 1,989
17 votes
Accepted

python auto indent problem

This is caused by electric-indent-mode, which is enabled by default in Emacs 24.4. You can turn it off with (electric-indent-mode -1) If you don't want to disable electric indent mode entirely but ...
user avatar
  • 6,364
16 votes

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

Aggressive Indent Mode Since some people asked for it, I turned this answer into a package. If you have Melpa configured, you can install it with M-x package-install RET aggressive-indent See the ...
user avatar
  • 22.3k
16 votes
Accepted

Modifying the indentation of some Emacs Lisp forms

Answer: Symbols for functions and macros have a lisp-indent-function property which you can set with declare or in your case, since if is already defined, you can just use put. You can read about ...
user avatar
16 votes
Accepted

Correct indentation for wrapped lines

After M-x package-install RET adaptive-wrap RET: (setq-default adaptive-wrap-extra-indent 2) (add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode) (global-visual-line-mode +1)
user avatar
  • 9,993
15 votes
Accepted

How to indent items in LaTeX/AUCTeX itemize environments?

@sykora's comment about (setq LaTeX-item-indent -2 LaTeX-indent-level 4) is almost there, but it does mean we spill over to every other environment as well. So, for example, we would also have: \...
user avatar
  • 31k
15 votes
Accepted

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

It looks like you need the fill-region function more than the indentation. Select that line and do M-x fill-region. Select the same, now split across multiple lines, and do M-x indent-region. ...
user avatar
  • 24.2k
14 votes
Accepted

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

Instead of mark-sexp + indent-region, you can press C-M-q. This will call indent-pp-sexp. Not automatic, but a bit better than having to invoke two commands. Or if you're using paredit-mode, press M-...
user avatar
  • 3,258
14 votes
Accepted

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

Set the variable org-adapt-indentation to nil. The default value is t, which means: When this variable is set, Org assumes that you write outlines by indenting text in each node to align with the ...
user avatar
  • 20.1k
13 votes
Accepted

How to make emacs align and indent a bibtex entry?

When the cursor is somewhere in the entry, run the command bibtex-fill-entry (bound to C-c C-q), which will align the fields. You may also want to set variable bibtex-align-at-equal-sign to a non nil ...
user avatar
  • 31k
11 votes
Accepted

Make web-mode always indent with spaces

In general, if you want indentation to use spaces only, I would recommend customizing: (setq-default indent-tabs-mode nil) This forces indentation to use spaces and no tabs. I'm not sure if web-mode ...
user avatar
  • 3,954
11 votes
Accepted

Better indentation and navigation in assembly source code

Just use the built-in asm-mode. It gives you syntax highlighting for any assembly languages. gas-mode does not do that and is not usable with AT&T syntax. If you want to set indentation for asm-...
user avatar
  • 6,652
10 votes
Accepted

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

Try to customize org-edit-src-content-indentation. I think by default it is set to 2. I think this is what controls that behavior. However, if you put (setq org-src-preserve-indentation t) in your ...
user avatar
  • 4,535
10 votes
Accepted

no html/jsx indentation in jsx-mode

This is a known issue and as of now, it has not been fixed. I've decided to forego jsx-mode for this reason and just use web-mode. It has support for JSX and is better suited for mixed content files. ...
user avatar
  • 501
10 votes
Accepted

Set indentation for shell script function

Setting sh-basic-offset to the required indentation is what is needed - but what I didn't realise is, it's also necessary to close and reopen all shell script files before the customisation takes ...
user avatar
9 votes
Accepted

Repeating a command n times

The documentation for indent-rigidly says: If called from a program, or interactively with prefix ARG, indent all lines starting in the region forward by ARG columns. If called from a program, ...
user avatar
  • 5,206
9 votes
Accepted

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

Below is a hard solution, but it works perfect. Actually it is just a function which simulations your operations, and use a run-at-time to make it be called every 10 seconds. Cheers. (defun indent-...
user avatar
  • 2,250
9 votes
Accepted

How to customize org-mode indentation?

One solution is to modify org-indent-strings to use stars instead of spaces as the indentation character. This means that the width of the indentation will always be correct, even when using a ...
user avatar
  • 2,735
9 votes
Accepted

Commented lines shoot off to column 32 in octave-mode

I achieved what I wanted by overriding some definitions from the original major mode. In /lisp/progmodes/octave.el (the file was zipped, I had to unzip it to view the source), I redefined octave-...
user avatar
  • 425
9 votes

Word wrap that preserves indent from previous line

I stumbled across an answer to this... on StackOverflow... You can use the package Adaptive-Wrap. It's pretty nice, there's an "extra indent" option you can use for the wrapped line, though no max ...
user avatar
9 votes

no html/jsx indentation in jsx-mode

FYI for anyone else who comes across this issue, this is because this jsx-mode project is not made to edit Facebook's React JSX templates but rather this other compiled javascript language also called ...
user avatar
9 votes
Accepted

formatting constexpr if in c++-mode

UPDATE: That pretest version that I put down there in the original question (emacs-26.0.90.tar.gz) had a bug that cause certain infinity loops while parsing the buffer, specifically when using the <...
user avatar
8 votes
Accepted

How to configure specific Java indentation?

You can make your style look like this instead: '((c-basic-offset . 8) (c-offsets-alist . ((inline-open . 0) (topmost-intro-cont . +) (statement-block-...
user avatar
  • 4,440
8 votes
Accepted

ESS indentation of parentheses after =?

Set ess-arg-function-offset to nil: (setf ess-arg-function-offset nil) For me this indents your examples the way that you want them to be. Read the documentation of the variable to find out why (and ...
user avatar
  • 131
8 votes
Accepted

Indentation after braces in C

Your question appears to be dealing with two independent issues: you want the RET character to automatically indent; and you want an indentation style that is different from the Emacs default. ...
user avatar
  • 5,480

Only top scored, non community-wiki answers of a minimum length are eligible