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: Wed, 27 Dec 2017 14:58:21 +0100 Message-ID: <87efngclxe.fsf@web.de> 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 1514383035 6027 195.159.176.226 (27 Dec 2017 13:57:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 27 Dec 2017 13:57:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs@gnu.org, Emanuel Berg To: Chunyang Xu Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 27 14:57:11 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 1eUCCh-000157-8k for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 14:57:07 +0100 Original-Received: from localhost ([::1]:33993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUCEc-00021a-VA for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Dec 2017 08:59:07 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUCE5-000211-4R for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 08:58:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUCE0-00013s-NS for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 08:58:33 -0500 Original-Received: from mout.web.de ([217.72.192.78]:56730) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eUCE0-00012O-3T for help-gnu-emacs@gnu.org; Wed, 27 Dec 2017 08:58:28 -0500 Original-Received: from drachen.dragon ([88.74.120.211]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MT8bi-1eLySe1Xew-00S31s; Wed, 27 Dec 2017 14:58:22 +0100 In-Reply-To: (Chunyang Xu's message of "Wed, 27 Dec 2017 13:38:43 +0800") X-Provags-ID: V03:K0:cipz18NS7KbThxcqeeKmrWKqzE3NTyAFNRY6PdpYEfMwLyx0ryc 7qNppOpqOjstwzmw6wy+U1wOT3IFwLFLGHEl6IkZS0vQKIC5F9qZd4Fnjuk16aEcsuphzv0 7M2buTu59YUOXqSht5cnQWxcnwQtiwptk082JByo61cDHVjN1CeaIZck5W9CkQgHv3E4mtG 9Q4tAdu2/Rw5gj0kmheMw== X-UI-Out-Filterresults: notjunk:1;V01:K0:Y/oAfGS+3yw=:5fBift3MqmbTb75weSD14G xZKntFDhu0qDgK16dpk0q9nnI0VXIUds+WrmjWuyo8qP+56NFyr7V5CpNs/RLHII3Nuw5ox+3 /J2vly57yz7bT/6HdS+hgcV57ClmEbCHmvBv61zF+yYNtHxmWqVJD6k0Z9pbC1I+7FcTvYg3d T4jHfGnUBXA45+rfIDC1nihpmD9RHexWyMMOMLNvr1wRLa4HtW4hGFKPetrUNO+Fht2qWJEnP ZEuWg/82g0HoMbPnOrrNL2iTOi9DP+zve2rVqgNF19TlRVlyNt7+lyn4NDy9/Sq+FBiggMPSa JXSdwqWLZCqcOe6Gk8NTKTg8GCGrILyotrNTgjJ29EQMUNCIuulRgGb/BYtkvQ+JkU5vbesQu DWzFiGmeKhxmioch1m5qVAJcot4MeR1DnncZbQgBetgh76KOdI9ImvLl5bUyVM2IIPcxPrt5T 2ca3r7CLJ9hKQ8jevQ7qoq4bF3iOR0oClCvnlaUcUyPhWEGR6pqXQ8FWeVY1UL2Ym4XMfl3wb Qz3KK7GDM5lfkE07x6kAa6vyfxeThPb1u9c4dTlLIMgKZIPxAIXtx4XLYMh36jgSimznZgSPr bMYZ8xb4D6+Gh0l1lE4E5N0OBVImU0cy5icxyCMztoixuzB9nnEhtVZhLnFQMcqGW7pZ9i2tF jUdVcffUxiLN8jO/b6QJU06LME3ZK1RsqHA34jskUmwRSSd7OnLfLMJm1sKeXMWGvoi7HjlF3 vDClb4lNAnjMxmx6t+DYI3OHSnyeZQUxG8Ei1EWAAtAdOV7Om4OHefQgMy26YZ5AQkmdfv5W 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:115472 Archived-At: Chunyang Xu writes: > ;; FIXME: Update this list every time el-search starts. How? For efficiency reasons I use in el-search a primitive type of caches that know when they need to refresh themselves. In this situation, this would look like #+begin_src emacs-lisp ;; -*- lexical-binding: t -*- (defun el-search--documented-function-p (name) (gethash name (el-search--get-documented-function-table))) (let ((helper (el-search-with-short-term-memory (lambda (_load-history) (message "Recomputing table of documented functions...") (let ((table (make-hash-table))) (mapatoms (lambda (sym) (and (fboundp sym) (get sym 'doc-string-elt) (puthash sym t table)))) table))))) (defun el-search--get-documented-function-table () (funcall helper load-history))) #+end_src The cache is a hash-table (faster lookup) that refreshes when queried and `load-history' changed. This is not optimal when you evaluate definitions by hand, of course. I could provide a `el-search-last-search-start-time' for that purpose, or a `el-search-start-hook' - though, I don't really want hooks to be used to implement pattern matching. FWIW, if you happen to want this (hack!), with a similar technique you can let el-search load searched buffers or files by side effect: #+begin_src emacs-lisp (el-search-defpattern load () "Match anything, load current buffer or file as side effect. Any buffer or file is loaded at most once. This is useful only in rare cases. Use with caution!!!" (declare (heuristic-matcher #'el-search--load-matcher)) (let ((load-matcher (el-search--load-matcher))) `(guard (funcall ',load-matcher (current-buffer) nil)))) (defun el-search--load-matcher () (let ((test (el-search-with-short-term-memory (lambda (file-name-or-buffer) (when-let ((file (if (bufferp file-name-or-buffer) (buffer-file-name file-name-or-buffer) file-name-or-buffer))) (with-demoted-errors "Error: %S" (load file))))))) (lambda (file-name-or-buffer _) (funcall test file-name-or-buffer)))) #+end_src HTH, Michael.