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
1answer
37 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
132 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
780 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
2answers
303 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
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
223 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
42 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
207 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
734 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
86 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
76 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
85 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
685 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
266 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
142 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
110 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
98 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
172 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
735 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
29 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
926 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
259 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
495 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
149 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
459 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
195 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
465 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:...
6
votes
0answers
192 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
223 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
121 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
137 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
68 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
112 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
112 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 ...
2
votes
2answers
466 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
323 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
175 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
78 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
59 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
132 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 ...
1
vote
0answers
108 views

Prevent emacs to indent when yanking into html buffer

I have disabled electric indent mode, as specified here, but when yanking text, indenting is still performed. I am yanking text into an html buffer, and I do not want any change whatsoever to be ...
1
vote
0answers
61 views

Make backspace(+?) remove a level of indentation in ReST mode

I often find myself in the situation where ReST-mode has correctly identified that my last line can be followed by an idented line, but I want to continue on the next higher level of indentation. How ...
1
vote
0answers
506 views

setting csharp mode indentation to 2 spaces

Complete emacs/lisp newbie trying to switch from vim. I noticed that emacs indents C# files to 4 spaces, which is normally great, but I'm working on a project that requires 2 space indentation. I've ...
0
votes
1answer
61 views

Strange Errors in Python-Mode

I am using the python mode. When i try to evaluate the following def using C-M-x i get this error from the python interpreter which looks strange: def foo(*args, **kwargs): print args, kwargs &...
0
votes
1answer
107 views

Why is tab-width reset when I open a C++ file?

So I'm trying to setup default indentation in Emacs. Currently I have the following at the bottom of my .emacs file as per a number of tutorials I've found on the internet. (setq-default indent-tabs-...
1
vote
1answer
319 views

Emacs bad indentation

So I've decided to try emacs, and I find it really good. However, I'm mostly writing Python, so the indentation is a crucial thing for me. After couple of failures in configuring I've finally reached ...
5
votes
1answer
195 views

Docstrings don't automatically indent themselves in elpy-mode. How do I fix this?

This is an example function that shows that docstrings do not automatically indent. def testing_docstring(): """ docstring is not indented automatically! Even after a newline. """ ...
1
vote
0answers
159 views

How to indent a tex file like org-mode?

When I'm editing a org-mode file, the structure of mine is like this(you may need configuration in init.el): * A section This is the content of the section #+BEGIN_SRC lang code here #+...