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
0
votes
1answer
19 views

Change indent for function calls in Emacs Lisp?

While writing the question I found a viable workaround solution for myself, so I am posting it as Q&A. I am leaving the question open, because my workaround does not allow to set the amount by ...
1
vote
0answers
50 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 ...
0
votes
0answers
13 views

smart-shift: exit 'smart shift keychord'

I use https://github.com/hbin/smart-shift. I bound keys to do smart-shift-left / right But when I press them I stay in 'smart shift keychord' mode and must press C-g to exit. I wonder how to exit ...
4
votes
1answer
141 views

Is there indentation in org src blocks?

I'm going kinda crazy trying to understand what's going on here... Asked this question on the r/emacs subreddit so apologies if any of you are seeing this again. Do org blocks allow TAB indentation ...
0
votes
0answers
12 views

How to make python-mode follow indentation of first line for an entire block

I want python-mode to follow the indentation of the first line. I want to avoid having to issue C-c <, C-c >. If I have this block (source): def fib(n): # write Fibonacci series up to n &...
0
votes
0answers
42 views

Why emacs makes weird indents in arrays

Often, emacs makes weird indentation in arrays: first line indented properly, but next lines are indented twice. This behaviour found mostly in php (with web-mode): array( array( 'name' => 'Add'...
1
vote
1answer
19 views

Turning off indentation for goto labels

I'm using the ellemtel style for my C code. This mode indents goto labels like this: void f(int x) { if (x) { goto LABEL0; } else { goto LABEL1; } LABEL0: printf("x is zero\n&...
1
vote
0answers
18 views

Customized c-mode indentation style in Emacs 27.2

I would like to produce c code in the following format: char *ft_strdup(const char *s1) { char *h; size_t len; ... } Where I can tab after the type of the function signature and ...
0
votes
1answer
45 views

Why is code indentation in the current codebase of Emacs so difficult to read?

I'm looking at the codebase of Emacs (for example gnus codebase) and see that the code indentation style is so weird. For example, here is source code of the functions gnus-sort-threads-recursive in ...
0
votes
1answer
49 views

yaml: How to set indentation width?

I'm new to editing yaml with emacs. I currently use yaml-mode 20210808.1122 installed like so : (use-package yaml-mode) (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)) I would ...
0
votes
1answer
35 views

Org mode how to apply 4 spaces for tab without initial indent inside source-code-block?

On this example, cursor is at beginning of if when I press tab 2 space indent is added beginning of if block, which is aligned. ** TODO help | ** TODO help #+begin_src python | #+...
0
votes
0answers
11 views

Strange flush left C-code formatting in Emacs 24.3 of SLES 12 SP5

I see some odd Emacs behavior in C-mode recently. I suspect that the change happened either when switching from SLES 12 SP4 to SLES12 SP5 (both have Emacs 24.3), or when switching from SLES 11 SP4 (...
0
votes
0answers
18 views

Overriding semicolon indentation rules from cc-mode for structs

Context: I've a language mode that derives from cc-mode. The language is quite similar to C++, however one difference is that semicolon doesn't follow a struct definition. For example struct S { uint ...
0
votes
0answers
43 views

How to disable babel block indentation?

Is it possible to disable the indentation of new babel source blocks? I played with electric-indent-local-mode and org-src-preserve-indentation without success. Current output: * aa ** bb #+...
0
votes
1answer
43 views

Any Elisp equivalent of Python's inspect.cleandoc?

When working with code generation, Python's inspect.cleandoc is quite useful, as it allows to write inline code in a multi-line string and then automatically adjust the indentation. # -- Input: def ...
0
votes
1answer
31 views

Is there a way to automatically indent a parenthesis in Slime REPL after pressing `C-m o`?

I am using Slime, Paredit, and SBCL to code in Common Lisp. While editing a .lisp file, suppose I have this code: (dotimes (i 4)) I will represent the cursor (point) as -!-. Having the cursor in this ...
2
votes
1answer
66 views

How to define global keybinding for `C-c >` and `C-c <` using defhydra

I am trying to apply following solutions's keybinding to overwrite all mode's keybindings for C-c > and C-c <. From the answer for Can we do C-c > and > and > to continue indentation: (...
1
vote
0answers
75 views

Behavior of indentation in Org

I use Emacs 27.2 and Org 9.4.6. Since a very recent update of Org, I noticed a strange change in the behavior of indentation. In my init file, I have set the variable org-adapt-indentation to '...
0
votes
1answer
29 views

Why Emacs creates multiples whitespaces after I create a comment and jump to a new line?

I am using Emacs, Paredit, Slime to work on Common Lisp (SBCL). When I create a comment such as: ; test It is placed as expected. But if I press return in order to create a new line below ;test this ...
0
votes
1answer
86 views

How to set the default indentation width globally?

By default Emacs uses tab instead of spaces for indentation, so I changed these 2 variables to change this behavior, (setq-default indent-tabs-mode nil) ;; Disable indent with tabs (setq ...
2
votes
1answer
72 views

New line and indent without electric mode

I have come to hate the inconsistency of the electric indent mode and I haven't much of a clue about how it works anyways, so I've disabled it and am trying to get the desired behavior from scratch. I ...
3
votes
1answer
76 views

How to get the following indentation style in c?

I would like to have the following behavior: int main(){ to result in: int main(){ | } Where pipe is the cursor, and I DON'T have to press RETURN key after '{'. I have already achieved the ...
0
votes
0answers
27 views

incorrect c++ enum indentation in emacs 26.x

My emacs 26.3 insists on a very strange enum indentation even when started with --no-init-file --no-site-file class A { public: enum EnumWithLongName { val0, ...
2
votes
2answers
91 views

How to fix indentation for `dash.el` threading macros (e.g. `->>`)

As I write more Elisp, I find myself using the threading macro increasingly often. However, since it is an imported, not a built-in one, the indentation is not like what I want it to be. For example, ...
0
votes
0answers
24 views

No PHP blade block syntax highlight or indentation

I am creating an app with Laravel using Emacs and I can't get Emacs to highlight syntax using web-mode in blade with neither @php @endphp blocks or using <?php ?> blocks. I saw this question ...
1
vote
2answers
61 views

`dtrt-indent-mode` erroneously uses Tab characters

Here is an example file (/tmp/asdf.sh), for which I want dtrt-indent-mode to do the right thing. #! /usr/bin/env bash function asdf() { printf "asASDFASDF" echo "1234" } ...
0
votes
1answer
436 views

Indentation in Org Mode Source Block with Return

I have a weird behavior in org-mode. When I create a source block, pressing RET indents the current and all previous lines with 2 spaces, resulting in something like #+begin_src bash :results output ...
1
vote
1answer
57 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
0answers
14 views

web-mode mojolicious, indentation of elsif

I'm editing my mojolicious templates (.ep extention, perl+html) in webmode. Everything works fine, except the indentation when I use elsif. Say I have % if ( $type eq 'A' ) { % } elsif ( $type eq '...
2
votes
1answer
82 views

How to change CSS files to indent to 2 spaces?

I have only installed emacs straight out of the box. I have not installed anything else: GNU Emacs 26.3 Copyright (C) 2019 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. ...
1
vote
1answer
58 views

How to disable auto indentation in asm-mode

When programming in extended assembler (using asm-mode), auto indentation insists on indenting compiler directives, such as #define, #if and #endif, how can I disable this? Emacs version: 0.300.0@26....
0
votes
0answers
12 views

Dynamic virtual indentation Makefile minor-mode or configuration option

Is there a minor-mode, or configuration setting for Makefile mode that does the following? When viewing a Makefile with lots nested ifeq..endif / ifneq..endif blocks, the buffer contents will be ...
0
votes
0answers
17 views

Emacs Fortran 90 mode indentation too aggressive

In my newer version of emacs, when I edit a Fortran 90 source code and press enter key (new line), the cursor moves down but also skips by some spaces (depending on context) to right. I find the ...
1
vote
1answer
47 views

PSGML conflicts with built-in `sgml-mode`

I’ve installed psgml 1.4.0-9 and psgml-html-mode for DTD-aware editing of HTML.* But the built-in sgml-mode/html-mode seems to be causing some problems: some tags are highlighted in font-lock-function-...
1
vote
1answer
139 views

I am writing Fortran code in emacs but the tab key behaviour changes in F90 mode. Can I change it back?

On loading a f90 file, emacs changes to F90 mode, which changes some emacs behaviours. When I press <tab> emacs inserts two spaces at the left margin. Now when I use the backspace key it deletes ...
0
votes
0answers
42 views

I don't understand skeleton.el indenting rules

As a fun (?) exercise, I am testing skeleton.el templates for some repeated, boring boilerplate coding tasks. I want to generate something like this: int main () { if () { if() { ...
0
votes
0answers
31 views

Commenting in and Org-mode block (SRC) indents entire block. How to comment without indenting org src block?

In my org-mode source blocks, any commenting with a function indents the entire source block. Is this normal behavior? Is there a setting to allow commenting of region, or line without indenting the ...
3
votes
2answers
74 views

Emacs script to indent files from the command line

I am trying to create an Emacs script that indents HTML files from the command line. This is what I have so far: #!/usr/bin/env -S emacs --script (require 'web-mode) (indent-region (point-min) (point-...
0
votes
1answer
36 views

How do I change the default indentation of 'if' for Common Lisp and Scheme?

When I am using (setq lisp-indent-function 'common-lisp-indent-function), the ifs are indented like this: (if x y z) For Scheme, (setq lisp-indent-function 'scheme-indent-function) also ...
0
votes
0answers
16 views

Emacs incorrectly indenting C code when auto-fill-mode is enabled

I have this single line in my ~/.emacs: (add-hook 'prog-mode-hook 'auto-fill-mode) Now I open a foo.c with Emacs and type this code. I only type the code and enter. I do not type any tab. This is the ...
2
votes
1answer
252 views

How do I keep the indentation on org-babel-tangle?

In literate programming, I often like to write my code in small snippets and then export them all at once via org-babel-tangle. This works great for non-indentation sensitive code (especially with ...
0
votes
0answers
18 views

How to stop auto-fill from indenting with spaces when it wraps?

I just added this to my init.el (add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1) (set-fill-column 100))) I am getting the desired autofill, but I am getting four spaces on the new line. How ...
0
votes
0answers
38 views

In Org, how can I mix ordered and unordered lists (numbers and bullets) at the same indentation level?

I'm new to org mode, and I'm trying to figure out if something like this is possible, and if so, how to do realize it: * Unordered 1. Ordered 2. Ordered * UNORDERED * Unordered The key ...
0
votes
0answers
64 views

TAB doesn't indent just pops up completion list

When I enter a new line and with the cursor auto indented due to electric-indent-mode, I see indent-cycles (x) in the modeline, so I hit TAB to cycle the indentation to where I want the cursor to be ...
2
votes
1answer
116 views

Emacs not indenting enum / enum class contents

I've got a small problem to do with Doom Emacs / Emacs. Enum contents are not indented at all... Here's what I would like: enum class RandomEnum { A, B, C, D }; Here's what I get: ...
0
votes
1answer
94 views

ctrl-backspace behaves differently across emacs environments, though .init file is same

I recently needed to start using another mac for work and I wanted to duplicate my spacemacs settings onto my new computer. I simply copied all files located in .emacs onto my new computer, and it ...
0
votes
0answers
31 views

Python indent region is wrong

Given the code: def main(args=None): if args is None: args = sys.argv[1:] load_data() Calling indent-region on the code (under python mode), the output would be: def main(args=None): ...
3
votes
1answer
95 views

Can we do `C-c >` and `>` and `>` to continue indentation

I am using following answer to handle indentations Emacs bulk indent for Python C-c > or C-c C-l shifts the region 4 spaces to the right C-c < or C-c C-r shifts the region 4 spaces to the left ...
2
votes
0answers
58 views

adaptive-wrap-prefix-mode behavior is different/inconsistent inside a buffer

in org-mode I have adaptive-wrap-prefix-mode on. The indentation though has a inconsistent behavior. I have already tried to toggle visual-line-mode and word wrap but the sometimes correct and ...
0
votes
1answer
265 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
2 3 4 5
10