Skip to main content
Share Your Experience: Take the 2024 Developer Survey
23 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)
nephewtom's user avatar
  • 2,261
16 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 ...
Dan's user avatar
  • 33.1k
15 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 ...
Tyler's user avatar
  • 22.3k
12 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 ...
Robin Green's user avatar
11 votes
Accepted

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

Org's indentation behaviour is controlled by the org-adapt-indentation variable. It can be set to three states: t: Adapt indentation for all lines headline-data: Adapt indentation for headline data ...
Atemu's user avatar
  • 322
10 votes
Accepted

How to detect tabs or spaces in Emacs

By default I want all indentation (when I hit the tab key) to be 2 spaces. This can be achieved for many modes with settings such as (setq-default indent-tabs-mode nil tab-stop-list ...
Basil's user avatar
  • 12.4k
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 <...
ABu's user avatar
  • 280
8 votes

Indentation in square brackets

Setting LaTeX-begin-regexp and LaTeX-end-regexp does not help here because inside LaTeX-indent-level-count it searches a backslash before checking the regexp. I got it working by modifying TeX-brace-...
Hebi Li's user avatar
  • 81
8 votes

Confusion about space and tab characters in Emacs

Like most things in emacs, the tabs policy is configurable. It sounds to me that you'd like to follow the most common apporach and use the tab key as an indentation tool and not have tab characters in ...
Heikki's user avatar
  • 3,076
7 votes

How to customize org-mode indentation?

Somehow I couldn't get the other answers to work for my setup, but the fastest and easiest fix that worked for me was: `M-x customize-face org-hide` Then, just change the Font Family attribute to ...
Christabella Irwanto's user avatar
7 votes
Accepted

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

I think you'll get what you want with (setq-default electric-indent-inhibit t) This was meant as a variable for major-modes (rather than for users), but it should take care of your use-case as well.
Stefan's user avatar
  • 26.5k
7 votes
Accepted

Why does Emacs indent my Lisp LOOP construct weirdly?

You can use indentation provided by a SLIME contribution: (require 'slime-cl-indent) You may want to add that to the list slime-contribs- see Loading Contribs in the SLIME manual. One can add it to ...
Rainer Joswig's user avatar
7 votes
Accepted

css-mode: use tabs and not spaces

The built-in CSS mode should support this just fine by giving indent-tabs-mode a non-nil value. Note that spaces will still be used for padding if the number of indentation spaces isn't a multiple of ...
simenheg's user avatar
  • 121
7 votes
Accepted

Emacs: indentation takes 4 spaces instead of 2

See this answer to a similar question. That answer doesn't answer that question, because it is about Ruby mode not respecting such code. But it likely does answer your similar question. This is that ...
Drew's user avatar
  • 77.9k
7 votes
Accepted

Emacs auto-indenting comments in an unhelpful manner

Unable to post this as a comment, but the indentation is likely part of one of the active modes (probably lisp-mode based on your description). You can do M+x describe-modes to see which modes are ...
einfeyn496's user avatar
6 votes
Accepted

Weird indentation behavior in C++ mode

It's not weird; std: could be a label and until you type the second : it doesn't know otherwise. Edit: I forgot to mention, but you can customize c-default-style to choose a different indentation ...
db48x's user avatar
  • 18.2k
6 votes

Navigate by indentation

This feature exists in Emacs. Outline mode describes a document as containing heading lines with a level, and has facilities to move among levels. We can define every line as a heading line with a ...
Gilles 'SO- stop being evil''s user avatar
6 votes

How to indent keywords aligned?

Intro to calculate-lisp-indent A better solution is to override the function calculate-lisp-indent. In brief, calculate-lisp-indent is a function that returns the column to which a line at point ...
Aquaactress's user avatar
  • 1,453
6 votes
Accepted

Python cycling through indentation

If you follow through the code of indent-for-tab-command, you'll see the indentation is actually done by a indent-line-function. In Python mode, this is python-indent-line-function. The help for this ...
Tyler's user avatar
  • 22.3k
6 votes

Customized c-offsets-alist override c-file-style in dir-locals

Instead of modifying c-offsets-alist, you can modify c-file-offsets whose purpose is to set offsets via file local variables. A small example for a .dir-locals.el file: ((nil . ((fill-column . 80))) ...
Mohammed Sadiq's user avatar
6 votes
Accepted

Extra indentation for argument lists beginning on a new line

Set point on the line in question and press C-c C-s to call c-show-syntactic-information. This shows you which variable you need to set. I set this to: (c-offsets-alist . ( (arglist-intro . c-...
jue's user avatar
  • 4,576
6 votes
Accepted

Can’t guess python-indent-offset - delete warning when local file variable

The error message is controlled by the python-indent-guess-indent-offset-verbose variable. Since the variable is file-local, you should be able to disable it globally if you put the following in your ...
Lorem Ipsum's user avatar
  • 4,517
6 votes
Accepted

Emacs script to indent files from the command line

@glucas's answer is correct in its diagnosis, but has a minor problem (you want the 0th element of argv) and is incomplete. Here is a more complete example: #!/usr/bin/env -S emacs --script (find-...
NickD's user avatar
  • 30.5k
5 votes
Accepted

change python indent in a specific file

One method of setting variables on a per-file basis is to write a local variable specification in the first line of the file. The details for doing this are in §48.2.4.1 ‘Specifying File Variables’ ...
amdt's user avatar
  • 96
5 votes
Accepted

C brace indentation

As mentioned in this answer on SO, you can do: (setq c-default-style "bsd") This will set the style for all C-based modes. If you want to set it only for one, do e.g.: (add-to-list 'c-default-style ...
Scott Weldon's user avatar
  • 2,715
5 votes
Accepted

How to make evil-mode tab key indent? (not re-indent based on context)

To have tab work as it does in VIM, use tab-to-tab-stop. (define-key evil-insert-state-map (kbd "TAB") 'tab-to-tab-stop)
ideasman42's user avatar
  • 8,826
5 votes
Accepted

Fix indentation of LaTeX code without wrapping lines

If you only want to indent a region, you should call an indenting function, not a filling function that, as you guessed, is meant to break lines. For example, you can use C-M-\ (M-x indent-region RET)...
giordano's user avatar
  • 3,255
5 votes
Accepted

Python mode indentation

I feel kind of ridiculous for not having seen this before, but I found the answer on the EmacsWiki: No Tabs page under the "Smart inference of indentation style" section. Putting that code in my init....
Andrew Lamarra's user avatar
5 votes
Accepted

copy region without leading indentation

You basically just want to be calling indent-rigidly on a copy of the region. That will also deal nicely with indent-tabs-mode (which I think you'll find your version does not). I'd suggest using a ...
phils's user avatar
  • 51.5k

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