unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alexander Shukaev <haroogan@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Isearch: add variable to control search match group
Date: Tue, 25 Aug 2015 17:06:37 +0200	[thread overview]
Message-ID: <CAKu-7Wwz-um521g3tbCPfE4bGt3OU0MGDGaC=QYEehDrQ=cVgw@mail.gmail.com> (raw)
In-Reply-To: <jwvegir1l8t.fsf-monnier+emacs@gnu.org>

>> 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.
>
> How do you do that currently?  I'd expect that to do the above, you'd
> set isearch-search-fun-function, and that function can take care of
> shuffling the match-data so that the interesting part is
> match-subgroup 0.

(defun my-search-function
    (&optional forward regexp-p wrap-p)
  "Return search function.
If FORWARD is non-nil, search forward, otherwise backward.
If REGEXP-P is non-nil, input is treated as regular expression.
If WRAP-P is non-nil, search can wrap around top or bottom of buffer."
  `(lambda
       (string &optional bound noerror count)
     (let* ((point    (point))
            (function ',(if regexp-p
                            (if forward
                                #'re-search-forward
                              #'re-search-backward)
                          (if forward
                              #'search-forward
                            #'search-backward)))
            (result   (funcall function
                               string
                               bound
                               ,(if wrap-p t 'noerror)
                               count)))
       (when (and (null result) ,wrap-p)
         (goto-char ,(if forward '(point-min) '(point-max)))
         (unwind-protect
             (setq result (funcall function string bound noerror count))
           (unless result
             (goto-char point))))
       result)))

(defun devil-isearch-search-fun ()
  "Return Isearch-compatible search function.
Based on `isearch-forward' and `isearch-regexp'."
  (my-search-function isearch-forward
                      isearch-regexp
                      t))

(defun my-isearch-input
    (&optional string forward regexp-p history-p)
  "Search for (user-entered) input in specified direction."
  ...
  (let (...
        (isearch-search-fun-function #'my-isearch-search-fun)
        ...)
    ...
    (if forward (isearch-forward regexp-p) (isearch-backward regexp-p))
    ...))

Do you mean that I can modify `my-search-function' in such a way that
the calls to `match-beginning' and `match-end' with group 0 happening
inside and after calls to `isearch-forward' and `isearch-backward'
will return the positions of the middle group excluding anchors?  If
yes, then maybe you could show me how to achieve that?  Thanks.

Regards,
Alexander



  reply	other threads:[~2015-08-25 15:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-24 23:55 Isearch: add variable to control search match group Alexander Shukaev
2015-08-25 14:45 ` Stefan Monnier
2015-08-25 15:06   ` Alexander Shukaev [this message]
2015-08-25 22:08     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKu-7Wwz-um521g3tbCPfE4bGt3OU0MGDGaC=QYEehDrQ=cVgw@mail.gmail.com' \
    --to=haroogan@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).