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
1
vote
1answer
21 views

Adjusting indenting for lisp if statements

I am learning common lisp and am trying to follow the style guide suggested by lisp-lang.org. In this style guide is an if statement style that I think makes the code more readable: (if (cond) (...
2
votes
0answers
34 views

Indenting LaTeX code for \if \else \fi statements

This is related to this Emacs.SE question. I use the code from the answer: (setq LaTeX-begin-regexp "\\(?:begin\\|if@\\)\\b") (setq LaTeX-end-regexp "\\(?:end\\|else\\|fi\\)\\b") (defun LaTeX-indent-...
1
vote
1answer
31 views

auto-fill-mode without automatic indentation

Is it possible to prevent auto-fill-mode from automatically indenting new lines according to the previous? I would like new lines to begin at column 0 regardless of the previous line's indentation.
1
vote
0answers
25 views

Add whitespace as indentation with `indent-region`

When using indent-region, emacs will indent code and leave bank spaces untouched. It seems to me that the majority prefer to delete whitespace. However I prefer white space indented with the code. An ...
1
vote
1answer
29 views

Insert “indent” regardless of mode

When typing docstring in python-mode, I always have issue with indentation. If I am at this point (| is the cursor): def fn(): """ Args:|""" If I press Enter, the cursor will move right below ...
1
vote
1answer
22 views

customize js2-mode switch indentation

This is pretty simple but it's thwarting me: this is how a switch statement indents in js2-mode switch(letterGrade){ case "A+": value = 100 ; break; case "A": value = 97 ; break; ...
1
vote
1answer
24 views

Modifying ruby-mode indentation

Currently, ruby-mode in Emacs 27 indents the following snippets like this: expect(foo).to match( bar ) expect(foo).to \ match(bar) Is there a way to ...
0
votes
0answers
14 views

Python indent closing parentheses for multi-line function

I've discovered some reformatting with Black or Yapf: def responses(self, foo=SuperLongClassnameBar.FOOBAR ) -> List['Foobar']: Using emacs and elpy, it won't indent the closing ...
0
votes
0answers
26 views

electric-pair-mode screws indentation

I have some trouble with my emacs indentation. Since I have enabled electric-pair-mode my indentation is screwed when I use hanging braces. Example (| is my cursor): int main(int argc, char *argv[]) {...
0
votes
0answers
11 views

Customize indent of line-continuation in f90-mode?

In f90-mode, is it possible to make continuation lines indent to the opening parenthesis instead of by a fixed amount of columns, without having to rewrite f90-indent-line? For conformance with a ...
0
votes
2answers
28 views

How to “escape” a plain list / cannot outdent region

This is start from: * Up ** Foo - x Notice that the plain list under Foo is indented. This is what I want next: * Up ** Foo - x ** Bar But from - x, I don't know how to "escape" the plain ...
1
vote
0answers
34 views

Identation issues in python mode

almost everytime, I cope e.g. snippets from the web and paste it with M-w in a python buffer the indentation is all wrong. Sometimes slanted to the left, sometimes to the right. Often all of the ...
0
votes
0answers
18 views

Conf[Unix] not indenting configuration file

I am having trouble trying to configure the conf[Unix] mode to do indentation. I have a hook that indents the whole file when I save the file: (defun indent-hook() "Indent before saving." (indent-...
2
votes
2answers
27 views

Define key binding for a single mode (Fundamental)

In light that this may be a duplicate, but I did not find the answer to my question scouring this site. The default behavior of GNU Emacs appears to have electric-indent-mode enabled, which is fine ...
1
vote
2answers
41 views

(un)-Indenting text over a region

This in org mode. How do I get from 1 to 2 2 to 3 in as few keystrokes as possible? And, if possible, in reverse. I was hoping selecting Food's subtree and M-^ would do the job but what it does ...
0
votes
0answers
49 views

Bad indentation with tsx

I have a .tsx file and a function that returns some html. It starts like: return <div className=... Then at some point I have a component with many arguments so I have to split them vertically. I ...
1
vote
1answer
19 views

C-M-\ fails to indent Lisp code

I follow this tutorial. The code after selecting the region and <Tab> or equivalently C-M-\ in an org file: (setq trees '(pine fir oak maple) herbivores '(gazelle antelope zebra)) I would have ...
0
votes
1answer
75 views

How to disable syntactic indentation interactively in php-mode?

I discovered that in php-mode, syntactic indentation makes rigid indentation very slow when the marked region is big. When I disable syntactic indentation, rigid indentation is not slow anymore. So I ...
1
vote
0answers
15 views

How does SMIE mode determine what the parent of a token is?

I'm writing indentation rules for a custom mode using SMIE. I want to use smie-rule-parent-p to have different behavior for indenting an empty line depending on context, so inside my indentation ...
0
votes
1answer
14 views

Automatically fixing bad indentation (Scheme-Lisp)

Let's say I make this code with bad formatting: is there an emacs command that can automatically fix indentation? I know this question has been asked a few times before, but all the answers I've seen ...
0
votes
0answers
84 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 -...
0
votes
0answers
21 views

How to make the cursor go to the beginning of the line by default when I hit return? [duplicate]

When I hit Enter/Return on my keyboard, the cursor goes to position of character 82 instead of the beginning of the line. This behavior is very confusing to me. Do I need to add something to the ...
1
vote
1answer
75 views

How to remove message `Indentation setup for shell type sh`

I open shell files at startup and often get this in *Messages*: Setting up indent for shell type sh Indentation variables are now local. Indentation setup for shell type sh All my files cause this ...
2
votes
0answers
24 views

Can I use “comment-column” for comments in other modes than emacs-lisp-mode?

Emacs-lisp-mode distinguishes multiple kinds of comments. ; is an "end of line" comment when following code, or a "right-margin" comment obeying comment-column when indented with indent-for-tab-...
0
votes
2answers
82 views

Unusual behavior when overriding `calculate-lisp-indent'

I've modified calculate-lisp-indent as a better solution to the indentation questions here, here and here. By "modified" I mean I overrode the function with advice. After doing this when I restarted ...
0
votes
2answers
41 views

Why is my Python indentation set to 8 locally by default?

I'm running Emacs 25.2.2 on Ubuntu 18.04 for WSL. I launch emacs -q and open a new Python file, test.py. As soon as I hit the Tab key, I notice the indentation is 8 spaces instead of 4. I don't like ...
1
vote
2answers
87 views

How can I represent a 4 spaces indent width as 2 spaces?

For clarity: I mean indents as represented by individual spaces, not tab characters. I'm working with a friend on a javascript project, and while I'm an 80col zealot, he wants to have 4 space indent. ...
0
votes
1answer
31 views

automatic indentation with space like visual studio

Is there any package that covers indentation with space like visual studio? like, if(a==b) ==> if(a<space>==<space>b) for(int i=0;i<N;i++) ==> for(int i<space>=<space&...
1
vote
0answers
31 views

sh-mode: Correctly indent and highlight inside bash's subshell substitution $()?

I noticed that bash will correctly apply syntax highlighting inside the subshell substitution in VALUE="Hello $(echo World)." But when creating a more complicated value, e.g. VALUE="Hello $( ...
1
vote
1answer
114 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. ...
1
vote
1answer
69 views

How to stop Emacs from deleting trailing whitespace?

By default, Emacs quietly deletes trailing whitespaces once the user moves on to the next line. To reproduce the issue in plain Emacs, do this: Start plain Emacs: emacs --no-init-file --no-site-file ...
1
vote
3answers
68 views

SMIE Indenting Arguments and Blocks

This is closely related to a previous question I asked here: SMIE Basic Identation and Block Example However, it is sufficiently different (and already big enough) that I might as well ask it as a ...
3
votes
2answers
86 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 ...
0
votes
1answer
20 views

Does it exists any library and or functionality that provides an API for indenting major modes?

I am currently maintaining a fork of a major mode and I usually get by through reusing snippets other people have written that provides indention for similar languages. However, this does lead to a ...
0
votes
1answer
37 views

How to align “end of line comments” in sh-mode?

I moved to column 60 of the first line and evaluated set-comment-column. Then I moved to the second column and called indent-for-comment, but it indents the comment randomly but not at column 60. How ...
0
votes
0answers
27 views

Refresh code indentation over a region

I have this: #!/usr/bin/bash while read f; do { #Try echo "$f" } || { # Catch printf "error" } done < "${1:-/dev/stdin}"; And I would like this in one ...
0
votes
0answers
35 views

Annoying indentation bug with ES6 multiline string using js-mode or js2-mode

I am using js2-mode right now. I am working on a .js file that contain a ES6 multi like string like this: Vue.component("comment", { props: { comment: { type: Object, ...
0
votes
1answer
33 views

Shift all tags in file to the right

In a .org file, I can align all my tags to the right with C-u C-c C-q. I'd like more space before text runs into tags in a file. Is there a variable for the location of the tags column in the org ...
2
votes
1answer
73 views

How to indent inline elements only once?

In this case the basic offset is 4 and tabs mode is enabled. For example I am getting: if (! (true // Problem when the value starts inline. && false)) {} // I get two tabs, one per '(...
1
vote
1answer
36 views

Adding rule to indentation

A code base I work on has the macro #define when break; case to make switch statements 'cleaner' However this causes problems with indentation, Is it possible to set the behavior of 'when' to be ...
1
vote
2answers
172 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-...
1
vote
1answer
34 views

Align statement breaks on rhs with equal sign

Is there a way to have rhs statement breaks align with the equal sign on the lhs line? e.g. some_value = a * b + c / some_other_value * x; becoming some_value = a * b + c / ...
4
votes
1answer
84 views

Custom indentation for macros in C mode

I'm working in a codebase with an extensive use of function macros and I'm having some difficulty finding the correct way to set indentations with them. Specifically, we pass a lot of statement lists {...
1
vote
1answer
42 views

Breaking up minified html

Is it possible to do this with vanilla emacs? If not what changes do I need to make. Original test.html <a id="try_redacted" target="_blank" href="http://redacted.com/game/2d/?try=1" style="right:...
0
votes
0answers
26 views

Convert gnu indent options to emacs indentation settings

I've worked at two places where code is supposed to be indented/formatted according to gnu indent (ie there's a prescribed set of options to gnu indent that's to be used). Is there an easy way to set ...
1
vote
2answers
66 views

Python Documentation String Indent In Auto-Fill Mode (Emacs 26.2)

I've noticed a peculiar behavior when using auto-fill-mode editing Python code. For example if I start typing the following (fill-column is set to 79): def some_function(keyword_argument0, ...
2
votes
1answer
43 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 ...
0
votes
1answer
64 views

How to indent truncated lines?

For me it seems like a really ruff edge that default spacemacs comes without an option to give my lines a correct indentation, when they are wrapped. (Click the first link if you want to see the issue ...
0
votes
0answers
29 views

How do I disable full-buffer indentation after each yank in web-mode?

In editing html/php mix in web-mode, I inserted a single line by a yank 'C-y' and the full buffer (it says region) is re-indented. It takes a large amount of time. It even throws a warning: "Warning (...
3
votes
1answer
84 views

SML Mode weird indentation

Whenever I hit enter to get to the next line when writing a function for example emacs indents an addition tabs worth of space. I'll try to sketch out the problem: fun pow(x : int, y : int) = ----...