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
9 votes
1 answer
387 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) ...
0 votes
1 answer
75 views

indent-buffer At top level

Not really sure why this has stopped working When I run the command indent-buffer ..it just says At top level Same if I mark the whole buffer and run indent-region. Any way to debug this?;)
3 votes
1 answer
353 views

How to set web-mode to use single-line comment style instead of multi-line for JavaScript

When commenting C-style code like C++, JavaScript etc., I use single-line comments to be able to uncomment a previously commented region selectively, i.e // This // is // a single-line style // ...
1 vote
1 answer
44 views

How to strip/normalise indent on paste?

It's often the case that I want to move a code block from one place to another that has a different level of indent. Here's an example Haskell snippet: someFunc = withSystemTempDirectory "test&...
10 votes
1 answer
276 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
2 answers
825 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\...
0 votes
1 answer
75 views

How to fix indentation of items below header 3 in org mode?

In org mode, when I do a header 1 or 2, the bullets beneath it snaps to align under the header. But bullets do not indent under for header 3. How do I edit this?
1 vote
3 answers
453 views

Babel + Python function definition with for loop causes IndentationError

I am using orgmode and Babel to run Python source code blocks. I noticed that if I define a function that returns a value, and if this function has a for loop inside it, then evaluating it with Babel ...
2 votes
1 answer
33 views

getting macro calls to indent correctly (like defun instead of functions) in common lisp code?

I'm editing a Common lisp (not elisp) source file; bottom right says (Lisp adoc [COMMON-LISP-USER sbcl]). I'm using slime, so I'm pretty sure that's what the adoc means. I have the following in a ...
1 vote
1 answer
153 views

opening brace alignment/indentation problem in LaTeX mode

I have an alignment/indentation problem in LaTeX mode. Every time I begin a line with an opening brace and I hit <TAB> or run an indentation command on the region, the brace becomes aligned with ...
0 votes
0 answers
13 views

Correct tree-sitter based indentation for d-ts-mode.el

I've put together a d-ts-mode for the D programming language at https://gitlab.com/per.nordlow/elisp/-/blob/main/d-ts-mode.el. The indentation doesn't work for all cases. Does anyone have advice on ...
0 votes
1 answer
93 views

Babel C++ blocks have incorrect indentation

When using a C++ source block in org-mode, the indentation doesn't match that of the C++ major mode. Viewing the source block in the org file: Viewing the same code in a C++ mode buffer or using org-...
0 votes
1 answer
30 views

Unexpected (lack of) indentation in C++ end-of-line comments

When using C++ mode I've noticed that the tab key indents the current line. However, if I'm at the end of the line, I would like to be able to use tab to add aligned whitespace so that I can add // ...
1 vote
1 answer
42 views

What is the difference between a tab stop and a tab width?

Greetings lately I've been trying to learn Emacs and configure it as an IDE, so I started learning the basics, until I got to the segment of configuring indentations. I do understand that the term Tab ...
0 votes
1 answer
822 views

Javascript mode mixes tabs and spaces for indent

My javascript mode indents with a mix of tabs and spaces. I'm ok with the mix if spaces are used for cosmetic alignment, but this is just wrong: First level of indentation is spaces, second is tab, ...
1 vote
2 answers
41 views

web-mode doesn't give correct indentation

I have the following lines activated: (setq indent-tabs-mode nil) (setq tab-width 1) (setq web-mode-markup-indent-offset 1) (setq web-mode-css-indent-offset 1) (setq web-mode-code-indent-offset 1) ...
0 votes
1 answer
20 views

`tab-stop-list` being ignored

Tying to write a new mode, I am stuck at: (define-derived-mode NEWS-mode text-mode "NEWS" "Major mode for NEWS file." (setq tab-stop-list '(2 6 59 65)) (setq indent-tabs-...
1 vote
1 answer
269 views

Why is electric-indent-mode adding extra indentation after pressing return twice in org source blocks?

When I try to write code in source block in Org mode, pressing return once acts as expected while hitting it a second time increases the indentation to two levels if it's currently less than that. ...
0 votes
1 answer
38 views

How to unindent after Org list

GNU Emacs v29.2 Doom core v3.0.0-pre Doom modules v23.12.0-pre So I want to RET/return after some bullet point lists and no longer be indented, but this is my current issue and I don't know ...
0 votes
2 answers
79 views

How to indent-region with TAB key?

I want to detect if selection made was activated and bind appropriate code for indent-region or ifselection mode was not activate - other code.
0 votes
0 answers
43 views

Indentation in org num mode

When working with both org indent mode and org num mode turned on, I observe that text lines are aligned with the outline numbering, like so which looks cluttered to me. Instead I'd prefer an ...
1 vote
1 answer
296 views

Use spaces for indentation in Protocol-Buffers mode

Protocol-Buffers mode binds c-indent-line-or-region to the TAB key. Since one of my projects uses 4 spaces for .proto file indentation, I've tried customizing indent-tabs-mode to nil, and tab-width ...
1 vote
1 answer
128 views

How do I suppress indentation after labels in Groovy?

I'm writing some Groovy code, and in my unit tests I have something like the following: def testFoo(){ given: //setup statement 1 //setup statement 2 //... when: //Execute ...
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": "...
1 vote
1 answer
44 views

How best to cope with Dragon speech recognition occasionally adding blank spaces at the beginning of lines?

BRIEF: When speech recognition software occasionally inserts extra blank spaces at the beginning of lines that are being dictated into emacs fundamental or textmode, how can the bad stuff below be ...
0 votes
1 answer
61 views

Evil mode "o" auto indent in text mode - how to turn it off?

When I press o in evil mode (which moves the cursor to the line under, and goes into insert mode), the cursor is indented by two spaces. When I press o, the cursor goes here This happens in text ...
3 votes
2 answers
319 views

Maintaining consistent visual fill column under `org-indent-mode`

How can one enable org-indent-mode (or otherwise indent content to Org headings) while still maintaining a consistent visual fill column?
1 vote
1 answer
54 views

Switch Cases's code block doesn't get indented in JavaScript mode

I'm having trouble with the indentation of the cases's code-blocks in my switch statements it looks like this: switch(var) { case "case1": case's code line 1; case's code line 2; ...
0 votes
1 answer
48 views

add a new line with the same indentation level as the current line

when python code block gets larger, it's hard to find the right indentation level def foo(): for a in l: # l1 # l1-1 for b in k: # l2 print(a) # (2) print(b) ...
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 ...
3 votes
1 answer
142 views

Indentation with reader macros: common lisp in emacs

Okay, I'm not sure whether this question is more relevant to Common Lisp, or to Emacs. I have reader macros in Common Lisp (found them here), that allow the declaration of hash-tables by: #{'a 'b, '...
0 votes
1 answer
170 views

Indentation not being followed on TypeScript/TSX

I have problem with the indentation in JSX/TSX files, I'm not sure how to describe it but the thing is that it does not follow the indentation on the file, please take a look the gif below: After ...
0 votes
1 answer
405 views

In Doom Emacs, when cursor is highlighting a line, it indents a few pixels in. How to turn off the indent and just do line highlighting?

I can't find a setting to turn off that small pixel indentation when cursor is highlighting the line you're on. It makes it hard to try to type text to align when the line itself is indented a few ...
1 vote
1 answer
146 views

How can I insert some multiline text that respects the indentation at which it is inserted?

I have a function that reads a link from the clipboard and generates a metadata-ful markdown link from it, and inserts it: (defun night/unt () (interactive) (let* ((link (current-kill 0)) ...
1 vote
1 answer
117 views

C offset is 2 with treesit

I recently started using treesit and I'm noticing with C files, my auto-indent is 2 spaces. How can I fix this to make it 4 spaces again? I've tried c-basic-offset.
0 votes
1 answer
64 views

In Org-mode, how to disable indentation of first line of a paragraph?

When converting from Org-mode to PDF, the first line of a paragraph is automatically indented: aaaaaa bbbbb ccccc ddddd eee ee fffff ggggg This is fine. However, I would like to disable it when I ...
0 votes
0 answers
16 views

How to auto insert new line when hit return key between {}

When write functino in c.c like this: int main(){} After I hit return key between {}, it goes like this: int main(){ } How could I get it to work like this: int main() { >position of cursor ...
0 votes
1 answer
54 views

c-mode inconsistent indentation (sometimes tabs, sometimes spaces)

I have the following line in my .emacs file: (setq-default indent-tabs-mode nil) but sometimes my indents still come through as tabs rather than spaces in c-mode. It is inconsistent; roughly 70% of my ...
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 ...
3 votes
2 answers
2k views

How to change shell-script-mode indentation not to use tabs?

To reproduce my issue, open your .bashrc or a .sh file and type the following: if while echo The if has no indentation. Good. The while has the default four spaces of indentation. Good. ...
0 votes
0 answers
79 views

how to turn off python formatting in emacs

I have a python program that I edit in emacs. However, sometimes when I save it, it gets re-indented, and in doing so, messes up the indentation of sections, where I have some code and then some ...
0 votes
0 answers
31 views

How do I trim spaces and indentations after traversing a DOM tree?

The following traverse the dom tree and provide an iterative custom formatting. However during the formatting, there are empty spaces and indentations which I needed to trim. ;;; This is where the ...
1 vote
2 answers
842 views

Syntax/indentation problems with Vue mode in Emacs 27 nightly

I'm using vue-mode, based on mmm-mode with Emacs 27 nightly from 10/10/2019. Since that Emacs update, I don't get any indentation support in the script section of a Vue file. Try this file with emacs -...
1 vote
1 answer
23 views

how to indent strictly in multiples of tabstop (e.g. 4)

Demonstration of the problem: # starting point: function hello_world { _somecommand_ parameter ' | <--- point/cursor is here on step one ' } # the next step (I take issue with): ...
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 ...
4 votes
1 answer
4k views

How to assign TAB to indentation and to yasnippet expand key

i'm trying to have the key TAB to: Indent my code (like in any other text editor) Trigger Yasnippet I have theses lines in my config: (global-set-key (kbd "TAB") 'yas-expand) (global-set-key (kbd "...
0 votes
0 answers
28 views

How can I make `fill-paragraph` on selected text respect indentation in AUCTeX?

Using fill-paragraph in AUCTeX normally respects the given indentation. However, if I use fill-paragraph on a selection, only the first line will be indented, the other lines won't. Is there a way to ...
3 votes
1 answer
312 views

Keep text selection after indenting with evil

I'm using emacs with evil key-bindings and I'd like to know, after getting some text into visual mode, how do you make sure that after hitting >> for indenting the text, the selection is kept, ...
1 vote
1 answer
45 views

Unexpected auto indentation by 8 spaces with AucTeX

It's currently hitting the standard list-like environments and comments but I can't quite figure when exactly it happens, as it looks non-deterministic: sometimes in a big document I actually get a ...
0 votes
0 answers
12 views

List Adaptive Fill Keeps Growing for Lists in Olivetti Mode

I'm having trouble with my org lists. They seem to have an ever increasing amount of adaptive-fill as I nest them deeper and deeper. A picture of the problem is below. These are all single lines in ...

1
2 3 4 5
11