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

Regexp matches not greedy enough #28

Closed
nispio opened this issue Oct 15, 2014 · 3 comments
Closed

Regexp matches not greedy enough #28

nispio opened this issue Oct 15, 2014 · 3 comments

Comments

@nispio
Copy link

nispio commented Oct 15, 2014

When I use phi-search to run this regexp

\b\([a-z]+-\)*key\(-[a-z]+\)*\b

on the example text below, the matches are not what I expect.

(defun nispio/locate-key-binding (key)
  "Determine in which keymap KEY is defined."
  (interactive "kPress key: ")
  (let ((ret (list (nispio/key-binding-at-point key)
           (minor-mode-key-binding key)
           (local-key-binding key)
           (global-key-binding key))))
    (when (called-interactively-p 'any)
      (with-output-to-temp-buffer "*locate-key*"

Specifically, instead of matching local-key-binding it just matches key-binding at the end, and instead of matching minor-mode-key-binding it just matches key-binding at the end. If I modify the regexp to be

\b\([a-z]+-\)+key\(-[a-z]+\)*\b

then it matches local-key-binding but instead of matching minor-mode-key-binding it just matches mode-key-binding at the end.

It seems that in this part of the regexp, phi-search is not doing greedy matching. Note that I have tested this regexp with isearch-regexp and I get the greedy match that I am expecting. In other words, phi-search is somehow coming up with different matches than isearch-regexp.

@knu
Copy link
Contributor

knu commented Oct 15, 2014

This is because phi-search searches backwards to get all matches.

;; POINT -> BOF
(goto-char phi-search--original-position)
(phi-search--make-overlays-for-1 query nil unlimited)
;; EOF -> POINT
(goto-char (point-max))
(phi-search--make-overlays-for-1 query phi-search--original-position unlimited))

(while (and (phi-search--search-backward query limit

I don't remember why, but it is fixable, I suppose.

@zk-phi
Copy link
Owner

zk-phi commented Nov 6, 2014

Fixed phi-search to perform forward-search. Thanks for the report.

@knu
Copy link
Contributor

knu commented Nov 17, 2014

Cool! 👍

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