gabesoft / evil-mc

Multiple cursors implementation for evil-mode
MIT License
387 stars 36 forks source link

Add Virtual white space forms edit #16

Open SnookEE opened 8 years ago

SnookEE commented 8 years ago

I am trying to understand the state of virtual white space. Sometimes called virtual space.

Examples of this block access technique can be seen in eclipse, visual studio, notepad++, textmate and eclipse. It works by appending virtual space characters when navigating and adding text.

This becomes extremely useful in multicolumn block edits as the cursor no longer tracks to the smallest line. You can now append to multiple lines as a replicated cursor. For example of why this is a problem take a look at the multiple-select video where you can see the additional steps he goes through to maintain the alignment.

Further benefits come in the form of block yanks and puts. You can select text as a column when there might not be intermediate space on all lines. Further trickery can be added to paste single line text to multiples and so forth.

Happy to assist or explain further.

gabesoft commented 8 years ago

Yea, vim has virtual white space too. But, I think that is more useful for visual blocks than for multiple cursors. In fact evil-mc doesn't support visual block selection. Also, I'm not sure whether evil-mode supports virtual whitespace either. That being said I'm interested in hearing more about how virtual white space would improve upon what evil-mc does currently.

SnookEE commented 8 years ago

http://usevim.com/2012/09/21/vim101-virtualedit/ is more or less exactly what I am trying to accomplish.

http://www.gnu.org/software/emacs/manual/html_node/emacs/Picture-Mode.html seems similar

The feature I believe would be adding it to emacs evil mode in a fashion that you can interact with the blocks while in the normal vi mode. Perhaps by leveraging the picture-mode.

Evil-MC seemed like a good start because of attempting to interface immediately with the spacemacs guys. I'm not sure if it is an aside or not, because multiple cursors can also mean that they aren't necessarily linked in a block mode.

As far as why it is useful, languages like VHDL that are doing a lot of expression of tabular data and list association benefit greatly. You'll have a text construct like the following;

    s_axi_reg_aclk      : in  std_logic;
    s_axi_reg_aresetn   : in  std_logic;
    s_axi_reg_awaddr    : in  std_logic_vector(C_S_AXI_REG_ADDR_WIDTH - 1 downto 0);
    s_axi_reg_awprot    : in  std_logic_vector(2 downto 0);
    s_axi_reg_awvalid   : in  std_logic;
    s_axi_reg_awready   : out std_logic;
    s_axi_reg_wdata     : in  std_logic_vector(C_S_AXI_REG_DATA_WIDTH - 1 downto 0);
    s_axi_reg_wstrb     : in  std_logic_vector((C_S_AXI_REG_DATA_WIDTH / 8) - 1 downto 0);
    s_axi_reg_wvalid    : in  std_logic;
    s_axi_reg_wready    : out std_logic;
    s_axi_reg_bresp     : out std_logic_vector(1 downto 0);
    s_axi_reg_bvalid    : out std_logic;
    s_axi_reg_bready    : in  std_logic;
    s_axi_reg_araddr    : in  std_logic_vector(C_S_AXI_REG_ADDR_WIDTH - 1 downto 0);
    s_axi_reg_arprot    : in  std_logic_vector(2 downto 0);
    s_axi_reg_arvalid   : in  std_logic;
    s_axi_reg_arready   : out std_logic;
    s_axi_reg_rdata     : out std_logic_vector(C_S_AXI_REG_DATA_WIDTH - 1 downto 0);
    s_axi_reg_rresp     : out std_logic_vector(1 downto 0);
    s_axi_reg_rvalid    : out std_logic;
    s_axi_reg_rready    : in  std_logic

You can see that it would be formatted such as all the colons are lined up. Then you would want to copy either the left side of the column or the right side of the column as if it was a table.

gabesoft commented 8 years ago

Sounds good. I think that most of functionality that you're looking for can be accomplished with either evil-mc or visual block. But, otherwise this functionality really should be implemented in evil mode. It doesn't really belong in evil-mc as its purpose is to simulate the cursor behavior at multiple positions.

SnookEE commented 8 years ago

That is correct, but there are a few key points I think evil-mc, and how it will all fit together is only beginning to solidify in my mind.

So the features i'm looking for are;

  1. Unrestricted movement outside of insert mode.
  2. Ability to select and yank/paste any arbitrary region.
  3. Ability to duplicate a singular line yank to a block paste.
  4. Ability to insert (i.e. edit) multiple lines simultaneously in an unrestricted column.

Of these I think the functionality is provided more or less by;

  1. picture-mode does this, with some white space care and feeding baggage, but does not do it in evil navitagion mode so would have to been added into that.
  2. An add-on phi-rectangle which is derived from rect-mark allows for proper visualization of the text selection, and combined with picture-mode is almost a direct translation of visual-block mode from vim.

3/4 are where I believe evil-mc and what I'm working toward have common ground. Perhaps It would make more sense to glue together this functionality in a spacemacs layer since most of it exists, but to my mind it seems like evil-mc would do a better job of providing this than multiple-cursors would. That tstatement may be colored by a relative naivete of how this is all architected.

Do you think evil-mc could play nice with these other features wihtout needing any special sauce? How would one glue together that functionality with evil-mc?

Thanks,

gabesoft commented 8 years ago

I think number 3 is more or less possible right now since you could copy a line and then create some cursors and paste it in multiple places. The only question is whether you can create cursors at all the necessary places. With evil-mc you can create a cursor at any arbitrary position so the answer should be yes for the most part. 4 is a little trickier because if the real cursor cannot reach a position then the fake cursors are not able to do that either since they try to simulate the real cursor. In fact it would be a bug if the fake cursors did something different than the real cursor.

SnookEE commented 8 years ago

I think the key to being unrestricted is to leverage the white space addition functionality of picture-mode. Movement of the real cursor is unrestricted because picture-mode will ad whitespace as you enter regions without defined characters.

To extend that notion to the fake cursors would be the same operation, but it would have to be coordinated with the picture-mode white space addition hooks.

I believe the feature set and the operation is clear in my mind, but what is less so is how do you coordinate the interaction of these different packages. Do you have any advice on how to understand that concept better?

gabesoft commented 8 years ago

The only way to understand how to do this is to dive in and read some code. I'd start with the evil mode package