emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Isearch: add variable to control search match group


From: Alexander Shukaev
Subject: Isearch: add variable to control search match group
Date: Tue, 25 Aug 2015 01:55:12 +0200

Hello,

would it be reasonable to add

(defcustom isearch-regexp-group 0
  "Number used to match concrete group in search pattern."
  :group 'isearch
  :type 'number)

and substitute all the calls to `(match-beginning 0)' and `(match-end
0)' with `(match-beginning (or isearch-regexp-group 0))' and
`(match-end (or isearch-regexp-group 0))' accordingly in 'isearch.el'?

For instance, I develop my own search module on top of Isearch
currently, and I really have problem with the fact that the choice of
group 0 is hard-coded in Isearch.  Let me give you a simple example,
where this makes things stiff.  Note, though, that the following
example (and the corresponding change above) are meant for
programmatic use of Isearch in the first place (rather than
interactive one).  Imagine that my search module wants to search for

\(^\|\s-+?\)(;;)\($\|\s-+?\)

and I am actually only interested in the "(;;)" part since I also want
to highlight it (with both, current match highlighting and all matches
lazy highlighting).  Then, clearly, "\(^\|\s-+?\)" and "\($\|\s-+?\)"
are just anchors.  Also, note that I deliberately chosen non-word
constituent to prevent any speculations on the usage of "\<" and "\>"
for this example.  Now, since Emacs does not have Vim-like "\zs" and
"\ze" to control beginning and end of match respectively on the one
hand, and does not have something like (hypothetical, but very welcome
too) "\sb", which would essentially stand for "space boundary" (i.e.
do for spaces what "\<" and "\>" do for words) on the other hand (in
which case I would simply transform the original search RE into

\(^\|\sb\)(;;)\($\|\sb\)

and be done with it), I have no choice, but to use something like this

\(^\|\s-+?\)\(?1:(;;)\)\($\|\s-+?\)

and then extract exactly the 1st group from it.  Unfortunately,
Isearch internally does not support that at all.  Will it be possible
to follow my suggestion and/or maybe somebody has better ideas?

Regards,
Alexander



reply via email to

[Prev in Thread] Current Thread [Next in Thread]