knu / phi-search-mc.el

Multiple-cursors extension for phi-search
BSD 2-Clause "Simplified" License
11 stars 4 forks source link

Highlight match after phi-search-mc/mark-all #2

Open nispio opened 9 years ago

nispio commented 9 years ago

Is there a way to call phi-search-mc/mark-all such that for each of the cursors the matching text stays selected after exiting phi-search?

I often find myself using phi-search to search for a regexp, and then calling phi-search-mc/mark-all. When I close phi-search, I have a cursor at each of the matches, but the match is not highlighted. Since I am using regexps, there is not easy way to re-highlight the match at each of the cursors, because each match may be different.

knu commented 9 years ago

You want something like this?

(defun phi-search-complete-with-selection ()
  (interactive)
  (phi-search-complete
   `(lambda ()
      (interactive)
      (when (looking-back ,(buffer-string))
        (push-mark (match-beginning 0) t t)
        (goto-char (match-end 0))
        (activate-mark)))))
nispio commented 9 years ago

That does exactly what I want, unless I invoke phi-search-mc/mark-all first, and then it just makes a mess. Do you know how to fix it so that each cursor selects its own match?

knu commented 9 years ago

@nispio Does this work for you?

(defun phi-search-complete-with-selection ()
  (interactive)
  (let ((query (buffer-string)))
    (phi-search-complete)
    (mc/execute-command-for-all-cursors
     (lambda ()
       (interactive)
       (when (looking-back query)
         (push-mark (match-beginning 0) t t)
         (goto-char (match-end 0))
         (activate-mark))))))
nispio commented 9 years ago

It does, thanks!

knu commented 9 years ago

This implementation uses looking-back which is in accordance with the current behavior of phi-search (https://github.com/zk-phi/phi-search/issues/28). So, I'll see how the issue is dealt with before making a PR.

knu commented 9 years ago

Now that phi-search has changed the behavior I'll have to find out a way for this.

nispio commented 8 years ago

Any thoughts on how to get this working again?