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

Example regexp #4

Open
eflanigan00 opened this issue May 13, 2018 · 4 comments
Open

Example regexp #4

eflanigan00 opened this issue May 13, 2018 · 4 comments

Comments

@eflanigan00
Copy link

eflanigan00 commented May 13, 2018

Nice package, thanks for putting this together.
In your example you use \(\s-*[0-9]+\) I can't get that to work.

What works for me is if I go to group -1 and use \([0-9]+\)

What does the -* do in your example? Is this some negation?

  • \s is whitespace
  • [0-9]+ is one or more number

Also posting all the steps in your gif as commands would be useful.

@mkcms
Copy link
Owner

mkcms commented May 14, 2018

Thanks. It would be helpful if you provided some example text which you're trying to align.

In Emacs regular expressions, \s must be followed by a character and it means "match a character with that syntax". The - character stands for whitespace syntax class. Thus \s-* means "match zero or more characters with whitespace syntax class". See Emacs manual for more information.

@phoenixanimations
Copy link

Hi another thanks from me for the package. I believe the above poster is trying to do something like this:

hi 0 
what 1
who 2
how? 3

When using the built in emacs align-regexp you just need to do M-x align-regexp [0-9] RET. Which would result in this:

hi	0 
what	1
who	2
how?	3

This package it appears you have to do \(\s-+\) which matches the whitespace giving the same effect. However if you delete that and put in [0-9] it will not align the numbers. The question is why?

@mkcms
Copy link
Owner

mkcms commented Dec 2, 2018

Hi @phoenixanimations,

The question is why?

When you call align-regexp without a prefix argument, it automatically prepends \(\s-*\) regexp to your expression. With a prefix argument, you have to provide the full regexp. This package also required you to be explicit.

I just pushed a commit which allows you to have the behavior you desire.
What you need to do is this:

(setq ialign-implicit-regexp "\\(\s-*\\)")

Doing so will prepend that string to the regexp, if your regexp doesn't have a subgroup expression.

So with this you can align the text like in your example by just using the regexp [0-9].
Hope this solves your issue.

@phoenixanimations
Copy link

Oh wow, thank you. That's quite interesting and funny enough I might prefer the more explicit in that case.

Anyway thanks for the speedy response, and that definitely solves my problem.

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

3 participants