From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Chunyang Xu Newsgroups: gmane.emacs.help Subject: Re: [el-search] How to search string excluding docstring? Date: Wed, 27 Dec 2017 13:38:43 +0800 Message-ID: References: <86373znhk6.fsf@zoho.com> <86tvwenbmo.fsf@zoho.com> <86d132n0e0.fsf@zoho.com> <868tdqmwfq.fsf@zoho.com> <86inculbeq.fsf@zoho.com> <867et9sjd0.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1514353057 16457 195.159.176.226 (27 Dec 2017 05:37:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 27 Dec 2017 05:37:37 +0000 (UTC) User-Agent: mu4e 0.9.18; emacs 27.0.50 Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 27 06:37:32 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 1eU4PE-0003mK-I9 for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 06:37:32 +0100 Original-Received: from localhost ([::1]:46193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eU4RB-0002GF-Le for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 00:39:33 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eU4Qk-0002Fq-6d for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 00:39:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eU4Qf-0005Lw-8c for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 00:39:06 -0500 Original-Received: from forward100p.mail.yandex.net ([77.88.28.100]:48196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eU4Qe-0005Hm-SW for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 00:39:01 -0500 Original-Received: from mxback13j.mail.yandex.net (mxback13j.mail.yandex.net [IPv6:2a02:6b8:0:1619::88]) by forward100p.mail.yandex.net (Yandex) with ESMTP id 5FD985102F5C; Wed, 27 Dec 2017 08:38:55 +0300 (MSK) Original-Received: from smtp2p.mail.yandex.net (smtp2p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:7]) by mxback13j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id UzdfaDcc3V-ctfee3Bt; Wed, 27 Dec 2017 08:38:55 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xuchunyang.me; s=mail; t=1514353135; bh=TrxSNXB8uRs2n7tKSdqUKEwCkbwWQo5zt5bhoiGh2nM=; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID; b=1uBn9NEeWTMym6Dz3ZRPdOpnqBOOKcZ2buNTxRhC4J4SZ0D3TpyYg3TCYkZuKnlLU RUar9kEQ9HLjAtXw4i655SOota+EOMjxQMDSiKykif+IInnpGVxkx0Hf+aZ54B65n3 dVPCX0A6xIe1bnAdL+eyki8+mOKokRSEKm6i4pxI= Original-Received: by smtp2p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zQEJObXhZd-ckn0wi2R; Wed, 27 Dec 2017 08:38:47 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xuchunyang.me; s=mail; t=1514353128; bh=TrxSNXB8uRs2n7tKSdqUKEwCkbwWQo5zt5bhoiGh2nM=; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID; b=pQEGKh1jWn2gom+26bMihlCu0qGfCr5cZrG6aZ4yPl5KeA2lz3IQlfkzzRGnqE+CF xi+Koq8MQPBg4WIko7pzZYprwD2w0Y1/FYay/IdHG5nZCdZyBIdTWzk4wz76zM7D4V MfKfUWMsnMqLq/78zUAvxgMyooLMgSaqe9qir22I= Authentication-Results: smtp2p.mail.yandex.net; dkim=pass header.i=@xuchunyang.me In-reply-to: <867et9sjd0.fsf@zoho.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 77.88.28.100 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:115470 Archived-At: Emanuel Berg writes: > However here there is a collision between the > two worlds. Because where is point? > Over which element to begin with, when the > query is executed? If one knows that, one could > simply get the defun as a list (which it > already is) and ask, "is the 4th element > a string?". If it is, and if point's at it in > the buffer, then yes it is a docstring. I think point is at the beginning of the string, the following assumes this to work. I compare point with the point of docstring (if any) to see if it is a docstring. #+begin_src emacs-lisp ;; FIXME: Update this list every time el-search starts. How? (defvar el-search--symbols-with-doc-string (let (symbols) (mapatoms (lambda (sym) (and (fboundp sym) (get sym 'doc-string-elt) (push sym symbols)))) symbols) "A list of symbols which support doc-string.") (defun el-search--doc-string-p () "Return t if point is at docstring." (pcase (save-excursion (backward-up-list) (read (current-buffer))) (`(,(and symbol (guard (memq symbol el-search--symbols-with-doc-string))) ,_ . ,_) (let ((op (point))) (save-excursion (backward-up-list) (forward-char) (ignore-errors (forward-sexp (1+ (get symbol 'doc-string-elt))) (backward-sexp) (= op (point)))))))) (el-search-defpattern doc-string (&rest regexps) "Match any documentation string that is matched by all REGEXPS." `(and (string ,@regexps) (guard (el-search--doc-string-p)))) (el-search-defpattern s (&rest regexps) "Match any string (excluding doc string) that is matched by all REGEXPS" `(and (string ,@regexps) (guard (not (el-search--doc-string-p))))) #+end_src