Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
9 views

Indentation: 4 spaces everywhere

This morning, my Emacs changed its indentation rules, and now it indents by 2 spaces, specifically in JS and HTML. It even re-indents code on which I work to 2 spaces, which is unacceptable. Please ...
1
vote
2answers
28 views

Getting electric indent behaviour for added chars to “electric-indent-chars”

I am trying to get electric indent behaviour in bazel BUILD files. These are essentially python files, although the structure is extremely simple. Let me give you an example: cc_binary( name = "...
1
vote
2answers
73 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
0answers
18 views

Letting evil >> increment org level

In evil mode, >> increments the indentation level of the current line. It does so at an org heading too, even though it would be more appropriate there if it would increase the org level (the ...
2
votes
0answers
40 views

How to control JavaScript indentation?

I am coding in Node.js, each time I want to write something that looks like this: const product = Factory .model('App/Models/Product') .create() I get this as an output: const product = Factory ...
0
votes
1answer
23 views

CC mode: make Tab just insert one tab or complete, no auto-indenting

I am dissatisfied with current behaviour of Emacs in CC Mode. I'm not sure if this applies to other major modes, but that's one I'm currently struggling with. Here are my problems: When I press tab, ...
3
votes
2answers
173 views

White space being inserted before a semicolon in asm-mode

When I try to insert a semicolon in my code (in asm-mode) it seems to indent a certain number of tabs like this (usually 4 it seems): D ; And if I put another semicolon on the next ...
0
votes
1answer
927 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
1answer
11 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 ...
1
vote
2answers
129 views

Emacs bulk indent for Python while `cua-mode` is enabled

I'd like to know how to indent multiple lines while Python is my major mode. The link below answers my question for the most part: https://stackoverflow.com/questions/2585091/emacs-bulk-indent-for-...
1
vote
1answer
15 views

Which variable modifies the switch statement indentation on php-mode?

I am currently using php-mode with spacemacs to write in php and recently I noticed this auto-indent behavior, namely pressing TAB. switch ($cond) { case "something": break; } Auto indenting ...
2
votes
1answer
52 views

Emacs indents C++ functions in structs in an unexpected way

Emacs indents functions in structs in the following way: struct A { int a() { return 1; } int b() { return 2; } } int c() { return ...
0
votes
1answer
75 views

highlight-indent-guides-mode

I'm trying to activate highlight-indent-guides-mode by default but it is not working. If i do M-x highlight-indent-guides-mode it works fine but adding (highlight-indent-guides-mode 1) to my .emacs ...
0
votes
2answers
304 views

how to paste with indent

the code block I copy outside emacs, which is not auto-indent when yanking in org type org-return-indent -> yank code block -> indent manually: *** headline | v *** headline { code ...
1
vote
1answer
79 views

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

I have this comment that I write in my python file # -*- Mode: Python; tab-width: 8; indent-tabs-mode: nil; python-indent-offset: 2 -*- # vim:set et sts=4 ts=4 tw=80: But when I load a python file, ...
1
vote
1answer
31 views

Indent forwards a tree structure

I have such a structure in my org note **** pstree * ~ $ pstree -aps 26955 systemd,1 splash └─systemd,1947 --user └─gnome-terminal-,2710 └─bash,1775 └─emacs,25135 ...
0
votes
0answers
20 views

unexpected long indent after colon in web-mode

I have some trouble locating the source of 8 tabs and 3 spaces more than the previous indentation when I'm inside js inside web-mode. These appear after a line that ends with a colon. Example (note ...
6
votes
2answers
571 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\...
5
votes
2answers
324 views

sh-script alignment issues

I'm sure emacs used to do it my way, but things appear to have changed (probably years ago, I've just been living with the pain). I want this (to conform to corp. standards): MULTIFORM=$( curl -...
0
votes
1answer
57 views

How to set tabulator size in the awk mode?

After installing a new kubuntu (16.04) and emacs (25.2.2) I have had indentation problems. It seems like indentation default values have changed or maybe I am missing some configuration file? ...
0
votes
2answers
290 views

prevent auto indent temporarily for multi line conditional, loops, etc

When I am writing in c-mode, I prefer to write multi-line control statements in the following way. if( cond1 && cond2 || cond3 ) { /* stuff */ } for( i = 0; i < N; ++i ) { ...
0
votes
1answer
296 views

How to fix incorrect emacs C#-mode indentation for method braces

My problem is that Emacs incorrectly indents the braces for C# methods, like this: static string LOL() { } then I have to manually correct it to static string LOL() { } I have read ...
2
votes
1answer
705 views

Minor mode for editing ansible playbooks

I have recently started using ansible, and yaml-mode seemed the logical choice for editing playbooks. However, the indentation does not quite work correctly. For example, I might start a task ...
4
votes
1answer
609 views

How to turn off alignment-indent after line continuation in Shell-script mode?

In Shell-script[sh] mode, Emacs defaults to this style of indentation: /this/is/an/example/command/broken/over_multiple_lines which \ causes \ ...
0
votes
1answer
70 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 ...
1
vote
1answer
32 views

Unexpected indentation in backquoted list starting with comma function call

When I write a backquotedlist that starts with ,( emacs aligns the remaining items to the parenthesis and not to the comma; e.g.: (defun kb-test1 () `(,(hello) fdefef ,(fefesd))) (...
7
votes
2answers
687 views

Why does Emacs indent my Lisp LOOP construct weirdly?

I'm using Emacs and SLIME to edit Lisp code. By default, Emacs indents my Lisp LOOP constructs like this: (loop for x across dna1 for y across dna2 count (not (eql x y))) But I expect it to ...
0
votes
1answer
105 views

Automatically indent ONLY logical lines in Org-mode

I want this: ** This is a heading This is a logical line. But, because I have visual-line-mode on, lines will wrap at the edge, as is just and godly. But, such elegant formatting as you see here ...
0
votes
1answer
40 views

Customizing indentation style for continuation lines?

I would like to customize the "k&r" indentation style, so that continuation lines are indented 8 spaces, like this: if (first && second) { // <- 8 spaces. third(); } -- ...
0
votes
2answers
24 views

Automatic re-indentation

I'm using Emacs to write ocaml programs, and the automatic indentation works fine : suppose I write if in the middle of a line, then skip a line and write then ; the keyword then is automatically ...
5
votes
4answers
1k views

Confusion by the usage of indent-tabs-mode nil

I use (setq-default indent-tabs-mode nil) in my init file so to avoid using TABs but when I write some files (like C++ files) then it allows me to insert TABs if I am in an if-statement for example. ...
0
votes
2answers
111 views

Confusion about space and tab characters in Emacs

I am confused by space (SPC) and TAB characters in Emacs. I am often using the default fundamental mode. When I select a region and indent the lines in the region by C-u 9 C-x TAB, I intend to ...
2
votes
0answers
68 views

Strange comment indentation results

I am working with a simple major mode. The format has one single line comment delimiter, i.e., %. However, I get strange results when running fill-paragraph on a comment. Specifically, the result I ...
3
votes
1answer
104 views

Web-mode + Dust.js, no indentation?

If I go to scratch, M-x web-mode RET, type in this snippet: <script type="text/x-dust-template"> {#obj_to_iterate} {prop} <----- this should indent {/obj_to_iterate} </script&...
1
vote
2answers
177 views

What prevents emacs from indenting and how can I force it to?

In certain modes, such as Python I have noticed that Emacs will not indent how I want it it to. It is getting "smart". For instance, in this block of code: def vec_select(veclist, k): ...
0
votes
0answers
29 views

Prevent spacemacs from splitting lines of C++ code

I installed the c-c++ layers in Spacemacs. When I invoke indent-region, Spacemacs splits lines that are longer than 80 characters. How can I prevent this behavior? auto-fill-mode is not enabled and ...
9
votes
3answers
4k views

Set indentation for shell script function

I am trying to set the number of spaces per indent for starting a new function in sh-mode (bash sub-mode). I have tried setting: '(sh-basic-offset 2) '(sh-indentation 2) '(smie-indent-basic 2) (as ...
1
vote
0answers
77 views

c++ mode indentation

If we have a class like the one below emacs is indenting the : (to the initialization list). To be able to match some other editor, is it possible in emacs to indent the : like below? class Test { ...
10
votes
3answers
2k views

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

When I'm using org-mode to take notes about a book, sometimes I'll copy/paste some code snippets into the note file. After pasting it, I'll 1. `C-c '` to call `org-edit-special` 2. `C-x h` to mark ...
-1
votes
1answer
80 views

Why does emacs sh-mode ignore indent-tabs-mode?

sh-mode won't care if indent-tabs-mode is on, it will still insert spaces instead of tabs! Can this be fixed?
0
votes
1answer
86 views

Emacs: indentation takes 4 spaces instead of 2

When I write code in Emacs and press Return, the indentation is automatically set to 4 spaces even if I set it yo 2: (setq tab-width 2) ; or any other preferred value (defvaralias 'c-basic-offset ...
3
votes
1answer
39 views

formatting of elisp file is different in emacs and other text editor

I'm having an issue with formatting in that when I'm in emacs, the formatting looks fine: but when the file is viewed with a different text editor, the spaces are different. this only occurs in the ...
5
votes
1answer
516 views

Indent javascript arrow functions like regular anonymous functions

Using Emacs 25.1 and js-mode for javascript editing. Is it possible to change the indention rules in js-mode to customize the indention of arrow functions? Example of anonymous function indention: ...
2
votes
1answer
186 views

How to indent back one level when writing a newline?

I'm using Emacs to write LaTeX. For example, in the following code, I have write to the level 3. When I press C-j, the cursor will indent to the third level. I what the newline to be indent at level 2....
0
votes
2answers
66 views

How to prevent losing indentation when editing JavaScript code within HTML files in Emacs?

When I edit JavaScript code which exists in an HTML file, I lose code indentation whenever I press Enter. first line of code: second line of code # Press Enter here Result after pressing Enter: ...
0
votes
1answer
102 views

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

Assuming I customized my default C indentation settings through M-x customize-variable c-offsets-alist: (custom-set-variables '(c-offsets-alist (quote ((statement-case-open . 0) (...
0
votes
2answers
45 views

How to configure C-M-q and TAB key to expand pre-existing TAB characters into spaces in C/C++ files

In C and C++ files, I want to configure the mode so that any time I request indentation, that it will always expand all of the embedded TAB characters in indentation (at the start of the line, and no ...
1
vote
1answer
97 views

#ifdef __cplusplus nuisance: How to prevent extra indenting?

If you ever wrote header files that have to be used by both C compiler and C++ compiler, you'd encounter this particular ifdef. This construct causes one to insert extra curly braces in the header ...
2
votes
1answer
192 views

How to detect and match indentation size of current buffer

I'm working on a javascript project that has inconsistent tab sizes 2spaces vs 4spaces on the server and client. I'm using web-mode for javascript editing. I'm looking for a feature like SublimeTexts ...
0
votes
1answer
54 views

Disable `indent-relative`

What's the right way to disable Emacs' default indent-relative behaviour and make sure that TAB always indents by a single level (be it a tab or whitespace character)? There doesn't seem to much ...