From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexander Shukaev Newsgroups: gmane.emacs.devel Subject: Re: Isearch: add variable to control search match group Date: Tue, 25 Aug 2015 17:06:37 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1440515895 4996 80.91.229.3 (25 Aug 2015 15:18:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 25 Aug 2015 15:18:15 +0000 (UTC) Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 25 17:18:10 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZUFzB-0006RG-Lr for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2015 17:18:05 +0200 Original-Received: from localhost ([::1]:60851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUFz6-0003kz-6o for ged-emacs-devel@m.gmane.org; Tue, 25 Aug 2015 11:18:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUFo8-0003i6-K0 for emacs-devel@gnu.org; Tue, 25 Aug 2015 11:06:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUFo7-0006PS-Mn for emacs-devel@gnu.org; Tue, 25 Aug 2015 11:06:40 -0400 Original-Received: from mail-la0-x22c.google.com ([2a00:1450:4010:c03::22c]:36785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUFo7-0006OR-F7 for emacs-devel@gnu.org; Tue, 25 Aug 2015 11:06:39 -0400 Original-Received: by labia3 with SMTP id ia3so35788615lab.3 for ; Tue, 25 Aug 2015 08:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=lqhFPkGgqcCA0WNtvqNHOUABjU5f3LVr3hx76ZC1sjk=; b=n9Lq7JnyGcC4dibdjMJl3uRLky3hNUhqk9bJd+o6oslxLww+sUSJNTVj/HFcXCMecJ 6wmjMKrpT1DWHt7jafinBqTljICDtCZYyXiFOUkKpog2W/Aq/NwHPV2VYuqX6jGor+Xc zE5Hh4Q9gDLNoZ1/S8XUYcHFkpezaB4Dtf74qaEkNk3QHVl0Y+GH9+UE+ZpLRE7wc9BN 5vV3VQwvnSlqHLh15CA+zvden3F55DB+OPB5iJH85+QdFBpx548MKPsCye0e498J5oDZ BOUfiVozywYcgs5K/w361e9E8b+zII/HNt6EgQoFyw/aat/C4c5pCu3tcqzscgQ4B8m7 4qKg== X-Received: by 10.152.22.99 with SMTP id c3mr26632965laf.32.1440515197654; Tue, 25 Aug 2015 08:06:37 -0700 (PDT) Original-Received: by 10.112.34.17 with HTTP; Tue, 25 Aug 2015 08:06:37 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:189164 Archived-At: >> 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