Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
1k views

How to detect tabs or spaces in Emacs

By default I want all indentation (when I hit the tab key) to be 2 spaces. However, when I am editing certain Python files (where I can not mix tabs and spaces) I would like to use whatever the ...
0
votes
1answer
207 views

Backwards tab-to-tab-stop?

The tab-to-tab-stop command moves the point to the next tabstop; I can't find an equivalent to move to the previous tabstop and tab-to-tab-stop doesn't accept a universal argument to reverse direction....
0
votes
0answers
451 views

use spaces over tabs everywhere

How do I use spaces instead of tabs everywhere? I noticed that web-mode was using tabs and could not figure out how to fix it. (Also, you may notice I was trying to set 2 tab spaces globally ...
0
votes
1answer
59 views

Why am i getting extra indentation-steps on react-router render function?

I am trying to write a school project in React with react-router v4 in web-mode. When i try to write the render props function web-mode inserts 4 spaces instead of the desired 2. <Switch> &...
1
vote
2answers
102 views

CSS mode won't indent values across multiple lines

When a line in my CSS file appears to be too long (typically a property followed by a bunch of values), I want to split them in to several new lines like this: But I have to manually enter spaces ...
0
votes
0answers
382 views

2 tab space with (evil mode) visual mode

When I hit return or try to indent a large block using visual mode with the evil mode package in Emacs it always uses 4 tab spaces. When I hit tab normally I get 2 tabs which is good, but I always ...
2
votes
1answer
2k views

Python mode indentation

Working on .py files, I know how to get emacs to use 4 spaces as an indent by default. I also know how to get it to use the tab character by default. I'd like to leave it at using spaces by default, ...
0
votes
1answer
35 views

Changed indentation settings - how to reformat old code?

I changed my Emacs configuration including indentation settings -now when I open an old C++ file I can write code and it looks like this: int x(int z){ return z; } However, the old code in this ...
0
votes
0answers
50 views

Carets (^^I) displayed in a PDF document output by LaTex from org mode instead of indentation

I have a C++ function in Emacs org mode: #+BEGIN_SRC c++ int x(int y){ return y; } #+END_SRC I use C-c C-e l o to convert it to a LaTeX PDF. However, the output in the PDF was: int x(...
0
votes
0answers
117 views

Indenting org entries programmatically

If I have a bunch of headings with sub-headings and content, how can I programmatically indent them correctly? I've tried combining bunch of elisp functions with mapping api, still can't figure it out....
1
vote
2answers
752 views

How to fix multiline-string indentation in python-mode?

When adding the docstring to a fuction def func(): """|""" After pressing RET I have this def func(): """ """ Instead of this def func(): """ | """ | is a cursor.
0
votes
1answer
264 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 ...
0
votes
1answer
113 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
200 views

Customize electric indent

I would like to change the "electric-indent" behavior in emacs, at least in the LaTeX major mode, but possibly in some other ones as well. What I would like is to retain the behavior that when ...
3
votes
0answers
40 views

Auto-indenting C code with tabs for blocks and spaces for other wrapping? [duplicate]

Is it possible to setup emacs to indent C code, with tabs for blocks { ... } and spaces with other wrapping (argument, for example)? Eg: <-->if (foo) { <--><-->function(a, b, <--...
0
votes
1answer
181 views

How to stop emacs re-indenting while typing? (cc-mode)

Using C/C++ (cc-mode), emacs sometimes re-indents text as I'm typing. For example (# for indentation, the first 4 are a tab): enum { ####/ Typing *, becomes: enum { ######/* (inserting 2 extra ...
8
votes
3answers
681 views

Ruby always indent 2 spaces?

I would like to use 2-space indents all the time like: sidekiq_options({ retry: true }) I've tried setting .emacs.d/init.el to: (setq-default indent-tabs-mode nil) (setq-default tab-width 2) (...
1
vote
2answers
82 views

Stop reindenting `if` after `else`

Given the file test.c: int main() { if (a) foo(); else if (b) // line 6 bar(); else baz(); } Whenever a comma or paren is typed while point is on line 6 (...
3
votes
1answer
75 views

Why does (indent-region …) insert a 't' into my buffer?

I'm using this yasnippet: # -*- mode: snippet -*- # name : case : {...} # key: case # -- `(indent-region (- (point) 20) (+ (point) 20) nil)`case ${2:constexpr}: ${3:\{} $0 break; ${3:$(if (...
4
votes
1answer
82 views

Vector literal indentation

I want to write my emacs-lisp-mode modification which respects some of my preferences. In particular, I want to override indentation for vector literals. Emacs treats vector literal as quoted list ...
7
votes
2answers
619 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 ...
3
votes
1answer
258 views

Wrong indent with emacs 24 and 25 in shell-script-mode?

I get the following indentation for my bash script for i in *; { echo $i } echo done The last indent is wrong and should be zero spaces. How can this be fixed?
1
vote
0answers
131 views

Should K&R indentation work in C++ code?

Given the following file, named as x.cpp I get the following unexpected indentation behavior: #include <stdio.h> class X { public: X() { // <-- Why the indent? ...
7
votes
2answers
104 views

How to highlight preceeding space-indentation that isn't rounded to current width?

Is there a way to highlight (set the background color for example) the space before a line, when it's indentation isn't aligned to the current indentation-width? 4 spaces indentation for eg: fn ...
0
votes
1answer
91 views

how to get web-mode to ignore alignment in favor of indentation during method chaining?

when I write code (Javascript, specifically) in a web-mode buffer which chains methods across newlines: object.foo() .bar() web-mode seems to want to align it like this: object.foo() .bar()// ...
3
votes
2answers
139 views

Mapping RET to use the same indentation level as the previous line

I code in Erlang, and I dislike the default indentation style that erlang.el provides: it tends to push code way too far to the right for my likings. I'd like to have a simple automatic indentation ...
1
vote
0answers
712 views

spacemacs, web-mode, cannot indent

I am using spacemacs. When writing .html file, it shows that it is in web-mode. I want to indent, press TAB, but nothing happened. So I can only use SPC to indent. I added (setq web-mode-markup-...
1
vote
0answers
28 views

How to indent when type } ) or ;

I found a way to auto indent when I type one of }, ; or ) using this code: (setq mode-autoindent-list '(javascript-mode js-mode php-mode web-mode)) (defun mode-autoindent () (when (and (member ...
0
votes
1answer
869 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 "...
3
votes
0answers
244 views

highlight-indentation-mode discontinue

I am using spacemacs. When enabling highlight-indentation-mode in python-mode, I found that the vertical lines are not continue, they will be interrupted if there is an empty line. How can I fix this?
3
votes
2answers
464 views

Stop javascript-mode from lining up function parameters after newline

Using javascript-mode, functions are indented like this: console.log('Example', var1, var2); test('Example2', var1, var2); I'd like to change this so that ...
0
votes
0answers
142 views

web-mode-indentation wrong

Using web-mode and evil I get a really strange behaviour when pressing return after curly braces: let StubMapsService = Ember.Service.extend({ getMapElement(location) { (RET) } }); let f ...
3
votes
0answers
412 views

Smart Tab and newline-and-indent

I have the following customizations in my .spacemacs file (defun dotspacemacs/layers () dotspacemacs-additional-packages '(smart-tabs-mode)) (defun dotspacemacs/user-config () (setq-default ...
2
votes
2answers
181 views

Changing how argument lists are indented in JavaScript

Right now, my argument lists are indented by js-mode like this: some_long_function_name( one_argument, another_argument ); How can I get them to look like this: ...
1
vote
2answers
426 views

emacs indentation style in file local variables

I am using emacs 24.5 and I ran into a problem with file local variables. I am working on a git project where file local variables are set like: /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:...
4
votes
0answers
168 views

How to properly indent application in scheme-mode?

The scheme-mode indents application in this way: (define (x) (x 1 2)) But when the function to apply is the result of another application scheme-mode indents the code this way: (define (f) ...
1
vote
1answer
188 views

How to indent the selected line one “tab” forward or backward [duplicate]

In a lot of text editors there is a keystroke used to move the selected lines one "tab" to the right, usually 4 whitespace or one "tab" to the left. How can I do this in emacs? I have only found ...
1
vote
1answer
109 views

Emacs-Lisp mode indentation problem when doc string contains left parenthesis in first column

Usually when I write Lisp code (in an Emacs-Lisp mode buffer), I can press TAB (bound to indent-for-tab-command) to indent code properly. However, if I write a defun with a docstring (longer than one ...
2
votes
1answer
133 views

Fix indentation of LaTeX code without wrapping lines

If I select everything in LaTeX-mode (AUCTeX) and auto-fill the region, the indentation of all lines is corrected. This is the part I like. However, it also breaks all long lines (which I think is ...
4
votes
1answer
88 views

ESS indentation inside functions

Indentation for R inside functions seems to be broken for pipes and '+'s: f <- function(something){ mutate(something, l="aaaa") %>% select(l) %>% str_replace("a", "A")...
0
votes
2answers
67 views

Tab key getting bounded to forward-button

Launching emacs with the -Q option (default settings) shows TAB being correctly bound to indent-for-tab-command. If I launch emacs without the -Q, TAB is always being bound to forward-button which is ...
3
votes
0answers
97 views

preventing indenting to open paren when creating a new block in react-mode

I'm using spacemacs for react development. i like it mostly but I have one issue that is annoying. Currently emacs will try to align certain lines with the last opening paren, so something like this:...
0
votes
1answer
107 views

Smart Tab : indenting with C-u <tab> does not work (beginning of a line)

(I haven't find any answer in previous topics) I am using Smart Tab globally, i.e. I have put the following code in my .emacs : (require 'smart-tab) (global-smart-tab-mode 1) I am writing a program ...
1
vote
2answers
437 views

How to indent relative to start of the previous line rather than relative to the beginning of the expression?

In php-mode – and in many others I believe – indentation of an expression spreading over several lines is computed relative to the starting column of the expression rather than the column of the first ...
5
votes
2answers
302 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 -...
3
votes
0answers
161 views

Highlight indent guides in org-mode src blocks

is it possible to show indentation guides in org-mode source code blocks? I use highlight-indent-guides-mode for highlighting indention and it does not work in org-mode (I think this is because the ...
2
votes
0answers
72 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 // ...
2
votes
0answers
57 views

How to protect LaTeX comment lines from indentation?

When I type <TAB> in a LaTeX file anywhere on a comment line, the comment symbol is moved to the beginning of the previous non-blank line. This also occurs with M-x indent-region. Is there a ...
0
votes
1answer
130 views

Inconsistent Indentation for C/C++ Upon Loading File

Problem: When a C++ file is loaded, the indentation rules are not always what they should be, i.e. instead of indenting by 3, it will indent by 1 or 8 for that session. This occurs consistently ...
1
vote
1answer
2k views

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

Currently pressing TAB in evil insert mode, runs indent-for-tab-command I'm not sure of the exact details, but from what I can tell this is performing some kind of re-indentation, which does nothing ...