Emacs, insert a rectangular line interactively

I often encounter situations when editing text or code, where I want to insert a rectangle of spaces to align objects, but I do not know exactly how many spaces to insert.

For example, consider the following (very far-fetched) fragment:

void *var = (void *)typedVar; void *otherVar = voidStarOtherVar; int intVar = x*y; int intVar2 = y*z; 

In C mode, by default, Mx align leads to this, which is better:

 void *var = (void *)typedVar; void *otherVar = voidStarOtherVar; int intVar = x*y; int intVar2 = y*z; 

However, suppose my desired alignment (for some reason) is as follows:

 void *var = (void *)typedVar; void *otherVar = voidStarOtherVar; int intVar = x*y; int intVar2 = y*z; 

The only way I know this is to use Mx string-rectangle in the bottom three lines and enter the exact number of spaces.

However, I do not want to count the number of characters in (void *) before entering spaces, so it would be nice to have an โ€œinteractiveโ€ insertion of the rectangle string. For example, I am typing a space in this interactive mode, and I see that it is immediately reflected in the text. I enter another space and it is inserted. This way I can interactively align the text to the desired position.

Is there a built-in way to do this? Or, otherwise, can I somehow create this functionality?

+6
source share
3 answers

An open rectangle may be useful for your example:

Cx ro' Insert blank space to fill the space of the region-rectangle ( . This pushes the previous contents of the area rectangle to the right.

So, you mark the desired rectangle, and this function will move the content to the right of the rectangle.

+7
source

Yes. Built-in cua-selection-mode .

Here is a video of cua-mode . cua-selection-mode only activates rectangular selection.

You can also get this functionality with iedit , but this is an external package . His main goal is editing mirrors.

+2
source

Another alternative already presented is multiple-cursors on github , which is very interactive and quite fun. There is a sublime Emacs Rocks! episode covering him on YouTube.

+1
source

Source: https://habr.com/ru/post/928123/


All Articles