From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: [el-search] How to search string excluding docstring? Date: Mon, 25 Dec 2017 18:51:36 +0100 Message-ID: <87wp1a3dcn.fsf@web.de> References: <87608u501d.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1514224228 8069 195.159.176.226 (25 Dec 2017 17:50:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 25 Dec 2017 17:50:28 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org To: Chunyang Xu Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 25 18:50:24 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eTWtI-0001U9-1A for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Dec 2017 18:50:20 +0100 Original-Received: from localhost ([::1]:56816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTWvF-0000kb-34 for geh-help-gnu-emacs@m.gmane.org; Mon, 25 Dec 2017 12:52:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eTWuk-0000kM-1p for help-gnu-emacs@gnu.org; Mon, 25 Dec 2017 12:51:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eTWug-0007HW-T9 for help-gnu-emacs@gnu.org; Mon, 25 Dec 2017 12:51:50 -0500 Original-Received: from mout.web.de ([217.72.192.78]:56004) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eTWug-0007Fs-JR for help-gnu-emacs@gnu.org; Mon, 25 Dec 2017 12:51:46 -0500 Original-Received: from drachen.dragon ([88.74.120.211]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MEEeC-1eiruj3gNM-00FV0o; Mon, 25 Dec 2017 18:51:37 +0100 In-Reply-To: (Chunyang Xu's message of "Tue, 26 Dec 2017 00:58:06 +0800") X-Provags-ID: V03:K0:VFcdFDDNAk+8lcS1kEhwdsf7DPvyTH5iRiSG2JGoYATVjIWkDpp yGwY+eNNJxHwVPeU4uriM9i+IwEarDdxI+Ik7CmKke3YyLk9wCJGoQDXTg7YPlikkgvfhUW RrcNwIbLbH6oXmzUDsrnWACAGqnQFwVNOpHRqqxgO9+LPy60eQw1/BTZxXiZdmoH0O9kgxf asGI0hZmPgy8Rk4gPSQog== X-UI-Out-Filterresults: notjunk:1;V01:K0:isAEv7Cq4aE=:lBzaXvYLWfO4Ml3XHOiMwH wkwTFTaYMDb0nLFDmKBn2U7xdysxSv586k94Rg07LOt8XIfIBbgKiShqDYVtiIuRli01Mb66n iXOo/bZTgmCpLhHDuH9eSlBPYzikKLnlOVTj5afTkeeIo8747ipPRNV5GudnoB2B4UAYMqzPz tEGB1UcMWz6Lq8cwwcEGU20vlQIVZyCb/wM4Tv0iBBUpJaZoRtCCHjuoZ1V2zzkPEpA3Ch1+Z xvv+p+u81FzsE3MQd0YvQSeMlzz6VIO/I9AZbrxYTou1QekNkIC9QOZxBB/gxvfVOkTcBKWBf umnheVsP4Sa9aqntQIu4Or0ihFtfdhUQkyO+dd93sycr0KN8dXdsefbNpWXaoPjoH9vsK6M1B Q/OgqWqIA4NMdfI2Bh3XlvNuJJuzTjRWYZYOrldV8zfRyGaVZ+1qUXc15TBa3Emw/+9d1aKEu 9bzulMWPtHRXqsq4Vm8UCUeFsSqWMOGWbCF72k75bJdez7j0c7RRmrrPRroiXtJZPykzGSpWL W1DcwJW63+C/E4V3sKUl14oIIDR06nK0CYSbQzkiTYXRv4a2pXx/zhdQxn8cvYVSvydzc/BFU MpAqY5y+r6TeXNX5RLQFabBnsOpUkFBfVKr2pXS+IP4fbzRkHfM76V2yfHmCEckMZXqjHC8e7 Tf+K0NkOSZU0EARdX0CZHW6RYLqTwYG/T7VYppC8r94Lywzo+vn/ckkjiwZuRoc48ZOy4X8+t y/UMt4zQziObbLZUxH6bEaMOtSe7xcjKobXvp0MMv8NFpXMvkJd0/j3HDka+JLDLvG0IPEox X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.78 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115454 Archived-At: Chunyang Xu writes: > I also realize another way, which is not general at all but seeming > working. To check if the current string is docstring > > (save-excursion > (backward-up-list) > (pcase (read (current-buffer)) > (`(defun ,_ ,_ ,(and (pred stringp) docstring) . ,_) > (string= docstring string)))) > > then to search docstring > > (and (string) string (guard ...)) > > It has a bug, for example, when search the following, it matches both > the first and the second "foo" (the second is not wanted) > > (defun hello () > "foo" > "foo" > (message "foo")) Yes, that's one of the pitfalls you can run into. One could try to find out at which list position the current expression is - I've not really needed something like this, however. > So my current approach of searching string excluding docstring is > > (defun el-search--docstring-p (string) > (save-excursion > (backward-up-list) > (pcase (read (current-buffer)) > (`(defun ,_ ,_ ,(and (pred stringp) docstring) . ,_) > (string= docstring string))))) > > (and (string "foo") s (guard (not (el-search--docstring-p s)))) Yes, that should work fine (unless you have any top-level strings, but that is never the case for code buffers). You could simplify it a bit by using (pred (string= string)) in the pattern. Regards, Michael.