edkolev / evil-lion

Evil align operator
131 stars 12 forks source link

Different behavior in built-in Emacs alignment and evil-lion #10

Closed ogdenwebb closed 7 years ago

ogdenwebb commented 7 years ago

Evil-lion-left and built-in align-regexp have the different rules to align the strings. With evil-lion it looks like you align a piece of code to a new string(fourth string) instead of align a new string to the existing piece of code.

For example:

(teal-green "#6fb593")
(wheat            "#b9c791")
(dark-blue  "#2a4661")
(blue       "#5485b6")
(alt-blue   "#6666be")
(cyan       "#54b6b6")

screenshot-2017-03-29_15-29-22

In my opinion, the align-regexp way is more natural. Would you like to add an option to set alignment rules? Or maybe change the current behavior?

edkolev commented 7 years ago

This seems like a nice addition. I see these possible options for configuration:

  1. custom variable evil-lion-mimic-align-regex; as a result:
    • aligning will not be repeated, it will be performed on the first occurrence only (this is what align-regexp does)
    • spaces before CHAR (" in this case) will be exactly one (again, this is what align-regexp does)

BTW align-regexp with "repeat ON" will result in one extra space before the second occurrence:

(teal-green "#6fb593 ")
(wheat      "#b9c791 ")
(dark-blue  "#2a4661 ")
(blue       "#5485b6 ")
(alt-blue   "#6666be ")
(cyan       "#54b6b6 ")

I don't really like evil-lion-mimic-align-regex. A better option would be to just call interactively align-regexp instead of trying to mimic it (gl would be like an alias of align-regexp).

  1. custom variable evil-lion-squeeze-spaces, inspired by vim-lion's g:lion_squeeze_spaces https://github.com/tommcdo/vim-lion#options

As a result, If this evil-lion-sqeeze-spaces is t, evil-lion will cleanup extra spaces right in front of CHAR (but it will not add spaces if there weren't any to begin with).

I'll think some more. Either way, I would like to extend evil-lion to be able to do this, I just have to figure out a good way to do it.

edkolev commented 7 years ago

I just pushed this commit https://github.com/edkolev/evil-lion/commit/6885d51d8124ce2f6d2a0137659911b3c7d27c8b which adds the following option:

(setq evil-lion-squeeze-spaces t) ;; default is nil

With this set to t, the desired behaviour will be achieved.

I'll use it for some time, then make it the default.

ogdenwebb commented 7 years ago

@edkolev yes, works fine for me. Thanks for this change. If you want, the issue can be closed.

edkolev commented 7 years ago

I've made this the default behaviour, starting with https://github.com/edkolev/evil-lion/commit/dd732c1471ecc9f6d964b214b7b6a5ac9f08178e

To disable removal of spaces:

(setq evil-lion-squeeze-spaces nil) ;; default is t

Cheers.