Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aligning on spaces doesn't work correctly #13

Open
ninrod opened this issue Jul 6, 2017 · 7 comments
Open

Aligning on spaces doesn't work correctly #13

ninrod opened this issue Jul 6, 2017 · 7 comments

Comments

@ninrod
Copy link

ninrod commented Jul 6, 2017

hi @edkolev,

is it possible to turn this:

#<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

into this:

#<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

with your package?

@edkolev
Copy link
Owner

edkolev commented Jul 7, 2017

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

@ninrod
Copy link
Author

ninrod commented Jul 7, 2017

I see. but suppose it was all spaces. would it be possible?

@edkolev
Copy link
Owner

edkolev commented Jul 8, 2017

I see that it's not working correctly right now. I'll rename the issue and let you know when fixed

@edkolev edkolev changed the title how would I align this snippet around spaces: Aligning on spaces doesn't work correctly Jul 8, 2017
@edkolev
Copy link
Owner

edkolev commented Jul 9, 2017

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?

@ninrod
Copy link
Author

ninrod commented Jul 9, 2017

Hum. I use an align function from spacemacs which I think uses align-regexp. Will that test later.

@ninrod
Copy link
Author

ninrod commented Jul 10, 2017

@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.

  • before:
#<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
  • after:
#<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
  • the function:
;; 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)))

@edkolev
Copy link
Owner

edkolev commented Jul 11, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants