Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I emulate Vim's 'softtabstop' in Emacs?
    text
    copied!<p>I've been trying to get into emacs lately, and one of the things I need to get right is indentation.</p> <p>Example 1:</p> <pre><code>sub foo { my $bar = 'quux'; | </code></pre> <p>Example 2:</p> <pre><code>sub foo { my $bar = 'quux'; |# foo </code></pre> <p>Imagine that the pipe character in the above examples indicates the cursor position. Now, I use (4) spaces for every indent level (no tabs), and I have emacs setup to indent my code automatically with that in mind. No problems there. But in the examples above, if I were to hit backspace at the indicated cursor positions, I want emacs to backspace all the way back to the next indent level (column / 4). That is, I want it to treat the preceding whitespace as if it were made up of tabs. Instead, it always just erases a single space character.</p> <p>In vim, I turn on 'expandtab' to make it insert spaces instead of tabs, and 'softtabstop', which makes it (among other things) backspace to the next "soft tabstop" as described above.</p> <p>In emacs, I suppose I could (if I knew emacs/elisp better) bind backspace to a function which does something like the following:</p> <pre><code>if indent-tabs-mode is nil if the cursor position is preceded by whitespace calculate the position of the previous "soft tabstop" if there's enough whitespace backspace all the way to that point else backspace by one character </code></pre> <p>What I want to know is, is there a simpler way to do this, and/or does anyone know of an existing solution?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload