Open ninrod opened 7 years ago
Until now evil-lion has been designed to not handle tabs. Supporting tabs would be a nice feature but the hard part would be to figure out what's the best behavior from the user's standpoint.
This particular example has intermixed tabs (lines 2, 3, 4) and spaces (lines 1, 5, 6). Let me know if you have any suggestions for an algorithm for this case, the best thing which comes to my mind is A) bail out with an error when the given region has both spaces and tabs, and B) turn tabs into spaces (but how many?) and then align
I see. but suppose it was all spaces. would it be possible?
I see that it's not working correctly right now. I'll rename the issue and let you know when fixed
I have a version which works, but it only works when evil-lion-squeeze-spaces
is t
(it is t
by default):
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
# 127.0.0.1 thinkpad.localdomain thinkpad
192.168.0.4 julicloud.local julicloud
127.0.1.1 thinkpad.localdomain thinkpad
Do you happen to know if align.el is capable of aligning on spaces so I can re-use its functionality?
Hum. I use an align function from spacemacs which I think uses align-regexp. Will that test later.
@edkolev, I've just used a function (from spacemacs) to align the block with success.
All I did was vip
, then invoking the function, then insert a space at the prompt and hit enter.
As this function uses align-regexp
from align.el
I believe this is what you are looking for.
interesting to note, it leaved 2 spaces between the columns.
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
# 127.0.0.1 thinkpad.localdomain thinkpad
192.168.0.4 julicloud.local julicloud
127.0.1.1 thinkpad.localdomain thinkpad
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
# 127.0.0.1 thinkpad.localdomain thinkpad
192.168.0.4 julicloud.local julicloud
127.0.1.1 thinkpad.localdomain thinkpad
;; function copied from spacemacs source code
;; modified function from http://emacswiki.org/emacs/AlignCommands
(defun spacemacs/align-repeat (start end regexp &optional justify-right after)
"Repeat alignment with respect to the given regular expression.
If JUSTIFY-RIGHT is non nil justify to the right instead of the
left. If AFTER is non-nil, add whitespace to the left instead of
the right."
(interactive "r\nsAlign repeat regexp: ")
(let* ((ws-regexp (if (string-empty-p regexp)
"\\(\\s-+\\)"
"\\(\\s-*\\)"))
(complete-regexp (if after
(concat regexp ws-regexp)
(concat ws-regexp regexp)))
(group (if justify-right -1 1)))
(message "complete-regexp: %S" complete-regexp)
(align-regexp start end complete-regexp group 1 t)))
I see... so align.el also squeezes (removes) the whitespace.
Thanks for looking into this, I'll try to reuse align.el's functionality but also try to avoid the double-space after aligning.
hi @edkolev,
is it possible to turn this:
into this:
with your package?