2

I want to move a region leftwards by one tab stop, as a rigid block (not changing indentation of internal lines).

Here's the quote from the relevant documentation, but I don't understand:

C-x TAB This command is used to change the indentation of all lines that begin in the region, moving the affected lines as a “rigid” unit.

If called with no argument, the command activates a transient mode for adjusting the indentation of the affected lines interactively. While this transient mode is active, typing LEFT or RIGHT indents leftward and rightward, respectively, by one space. You can also type S-LEFT or S-RIGHT to indent leftward or rightward to the next tab stop (see Tab Stops). Typing any other key disables the transient mode, and resumes normal editing.

I'm not seeing a transient mode. How do I move a region to the previous tab stop?


Related answer, to un-indent by 4 spaces

Community
  • 1
  • 1
Hatshepsut
  • 5,962
  • 8
  • 44
  • 80
  • `C-x ` is normally bound to `indent-rigidly` ... if it is not then perhaps check your key binding with `C-h k` then `C-x ` – donkopotamus Apr 10 '16 at 23:06
  • @donkopotamus `C-x ` is good -- I'm looking for de-indent/un-indent/dedent though. That `C-h k` is a great tip -- thanks. – Hatshepsut Apr 10 '16 at 23:08
  • 2
    If it is bound correctly, then `C-x ` should dedent to the previous multiple of `tab-width`. What is happening for you instead? – donkopotamus Apr 10 '16 at 23:16
  • @donkopotamus I press `C-x`, release, then ``, release then `SHIFT-LEFTARROWKEY`. Is that what you're saying? Doing that, it doesn't seem to notice that that's all supposed to be the same command. It just indents the region by one character to the right for the `C-x ` part and then just highlights a character as `shift-left` would normally do. – Hatshepsut Apr 10 '16 at 23:25
  • What happens if you highlight a region and then `M-x indent-rigidly`? – donkopotamus Apr 11 '16 at 00:03
  • @donkopotamus It rigidly indents the selected lines one character to the right – Hatshepsut Apr 11 '16 at 00:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/108769/discussion-between-donkopotamus-and-hatshepsut). – donkopotamus Apr 11 '16 at 00:06

2 Answers2

1

This behaviour, of a transient mode, was introduced in Emacs 24.4. In this case the submitter was running 24.3.

On Emacs 24.3, indent-rigidly cannot shift forward or back "to the nearest tab stop". Instead it may only be used to shift by a given number of characters.

For example:

  • to shift the region to the left by 7 characters use C-u - 7 C-x <tab>
  • to shift the region to the right by 3 characters use C-u 3 C-x <tab>
donkopotamus
  • 22,114
  • 2
  • 48
  • 60
1

I think your goal can also be achieved by 'rectangle operations'.

To move a text block to left by one tab stop, you can just delete a column of tabs in the left, then the text block will be moved automatically to left by the length of what have been deleted.

The steps to do so:

  1. select the content you want to delete as region. Be aware of that the start point and end point of the region will be the rectangle's two vertexes.
  2. issue \C-x r d, or M-x delete-rectangle.

And to move a text block to right by one tab stop, you can just insert a column of tabs before the text block.

  1. same as above one. But now the rectangle's width should be 0 (that is, the start point and end point of the region is on the same column).
  2. issue \C-x r t <TAB>, or M-x string-rectangle. Here <TAB> is the contents you want to insert, it can be anything else.
astropeak
  • 147
  • 1
  • 8