54

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, was introduced as the default in Emacs 24.4. See also this similar post on StackOverflow. (However, it sounds like you are saying the reverse, and that you ...


28

json.el package provides json-pretty-print-buffer. This is what it produces for your example: { "menu": { "popup": { "menuitem": [ { "onclick": "CreateNewDoc()", "value": "New" }, { "onclick": "OpenDoc()", "value": "Open" }, { "onclick": "CloseDoc()", ...


22

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 paste a carriage return character when the clipboard contents contains a newline (represented by the line feed character). In Emacs, a carriage return looks like ...


21

.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 .dir-locals.el files, or if you want to have personal preferences (presumably not indentation) that shouldn't apply to other people, if you use a distributed ...


20

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 save space, below is only a part of the formatted text that I get on doing the above on your sample text in the question: <table border="4px" cellpadding="0" ...


17

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 want to stop the colon from activating electric indent mode in Python mode, then you could remove the colon character from electric-indent-chars, which Python ...


17

I finally found it in this issue. (setq nxml-child-indent 4 nxml-attribute-indent 4)


16

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 the possible property values here: M-: (info "(elisp) Indenting Macros") return if's default setting is 2 which means the second form get's special treatment ...


16

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)


15

@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: \begin{abstract} This indents to the 4th column, which is way too far! \end{abstract} The following function builds off an old (and seemingly broken?) code ...


15

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 Readme for all the options, but the simplest way to turn it on is: (add-hook 'emacs-lisp-mode-hook #'aggressive-indent-mode) The Old Answer The following ...


14

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-q. That will reindent the whole function definition you're in.


14

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 headline (after the stars). The following issues are influenced by this variable: The indentation is increased by one space in a demotion command, ...


13

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 value to change the details of alignment.


12

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. That will, though, not insert new lines at the exact points as shown in your example. It will simply make the line fit in the fill columns.


11

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 uses the regular methods for indentation though, so it may not respect this. Can you give an example file to demonstrate?


11

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-mode, note that you cannot use tab-width but tab-stop-list that specifies spaces that 1 tab, 2 tabs, 3 tabs... can display: (setq tab-stop-list '(4 8 12 16 20 ...


10

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 init file, you will get your desired behaviour, plus indentation will be preserved on export. From the docs for org-src-preserve-indentation (notice the ...


10

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. Since I do work in several projects that don't all have the same convention of using the .jsx ending for JSX files (some simply use .js endings), I've also ...


9

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, START and END specify the beginning and end of the text to act on, in place of the region. To indent by four columns, just pass the prefix argument with C-u: ...


9

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-org-block-automatically () (when (org-in-src-block-p) (org-edit-special) (indent-region (point-min) (point-max)) (org-edit-src-exit))) (run-at-time ...


9

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 proportional font. The trick then is to set the foreground color of the indentation to be the same as the background color, so that the stars become invisible. We ...


9

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-indent-comment which originally goes like this: (defun octave-indent-comment () "A function for `smie-indent-functions' (which see)." (save-excursion (back-...


9

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 indent (but seems like it could be added with just a line or two of code). The author of the Stack Overflow post, Francesco, gives us the basic commands, and ...


9

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 JSX. That having the same name as the React templates is entirely coincidental. This is why the first commits to this repo were 4 years (pre-dating Facebook'...


9

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 effect. I can't remember ever having to do this before in emacs.


9

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 < token in certaing contexts, like writting < as the first character of an empty buffer in Java or C++ or after the keyword template. The bug has been fixed ...


8

You can make your style look like this instead: '((c-basic-offset . 8) (c-offsets-alist . ((inline-open . 0) (topmost-intro-cont . +) (statement-block-intro . +) (knr-argdecl-intro . 5) (substatement-open . +) (substatement-label . +)...


8

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 note that c is a function call). Simply setting it once in an init file does not work. A simple way for it to register is to set it in ess-mode-hook: (add-...


8

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. Electric RET A character that performs something else than just inserting itself is called electric in Emacs. There are two ways in Emacs to make RET electric: the ...


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