all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Chunyang Xu <mail@xuchunyang.me>
Cc: help-gnu-emacs@gnu.org, Emanuel Berg <moasen@zoho.com>
Subject: Re: [el-search] How to search string excluding docstring?
Date: Wed, 27 Dec 2017 14:58:21 +0100	[thread overview]
Message-ID: <87efngclxe.fsf@web.de> (raw)
In-Reply-To: <m2fu7wbuho.fsf@xuchunyang.me> (Chunyang Xu's message of "Wed, 27 Dec 2017 13:38:43 +0800")

Chunyang Xu <mail@xuchunyang.me> 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.



  reply	other threads:[~2017-12-27 13:58 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6328.1514197667.27995.help-gnu-emacs@gnu.org>
2017-12-25 12:00 ` [el-search] How to search string excluding docstring? Emanuel Berg
2017-12-25 13:57   ` Chunyang Xu
2017-12-25 14:34     ` Michael Heerdegen
     [not found]   ` <mailman.6334.1514210258.27995.help-gnu-emacs@gnu.org>
2017-12-25 14:08     ` Emanuel Berg
2017-12-25 17:55       ` tomas
     [not found]       ` <mailman.6358.1514224565.27995.help-gnu-emacs@gnu.org>
2017-12-25 18:11         ` Emanuel Berg
2017-12-25 19:14           ` tomas
     [not found]           ` <mailman.6366.1514229270.27995.help-gnu-emacs@gnu.org>
2017-12-25 19:36             ` Emanuel Berg
2017-12-25 21:20               ` tomas
     [not found]               ` <mailman.6371.1514236843.27995.help-gnu-emacs@gnu.org>
2017-12-25 21:56                 ` Emanuel Berg
2017-12-26  2:44                   ` Emanuel Berg
2017-12-26 13:34                   ` Emanuel Berg
2017-12-26 13:48                     ` Jean-Christophe Helary
     [not found]                     ` <mailman.6381.1514296097.27995.help-gnu-emacs@gnu.org>
2017-12-26 15:19                       ` Emanuel Berg
2017-12-27  5:38                     ` Chunyang Xu
2017-12-27 13:58                       ` Michael Heerdegen [this message]
     [not found]                     ` <mailman.6406.1514353148.27995.help-gnu-emacs@gnu.org>
2017-12-27  6:58                       ` Emanuel Berg
2017-12-25 19:39             ` Emanuel Berg
2017-12-25 10:27 Chunyang Xu
2017-12-25 10:40 ` Jean-Christophe Helary
2017-12-25 12:00 ` Skip Montanaro
2017-12-25 18:04   ` Michael Heerdegen
2017-12-25 14:56 ` Michael Heerdegen
2017-12-25 16:58   ` Chunyang Xu
2017-12-25 17:51     ` Michael Heerdegen
     [not found] ` <mailman.6340.1514213787.27995.help-gnu-emacs@gnu.org>
2017-12-25 15:50   ` Emanuel Berg
2017-12-25 16:59     ` Michael Heerdegen
     [not found]     ` <mailman.6351.1514221174.27995.help-gnu-emacs@gnu.org>
2017-12-25 18:04       ` Emanuel Berg

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

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

  git send-email \
    --in-reply-to=87efngclxe.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mail@xuchunyang.me \
    --cc=moasen@zoho.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.