|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
;; This file:
;; http://anggtwu.net/elisp/find-lgrep-links.el.html
;; http://anggtwu.net/elisp/find-lgrep-links.el
;; (find-angg "elisp/find-lgrep-links.el")
;; Author: Eduardo Ochs <eduardoochs@gmail.com>
;; Date: 2024jan31
;; Public domain.
;;
;; (load (buffer-file-name))
;; (eval-buffer)
;;
;; These sexps generate temporary buffers with lots `find-efunction's
;; that don't work:
;;
;; (find-eaproposf "macro")
;; (find-eaproposf "code-pdf")
;; (find-eaproposf "^find-.*file")
;;
;; But compare:
;;
;; (find-efunction 'find-efile)
;; (find-lpgreps 'find-efile "e")
;; (find-efunction 'brff)
;; (find-lgreps 'brff)
;; (find-efunction 'cl-struct-p--cmacro)
;; (find-lgreps 'cl-struct-p--cmacro "cl-struct-p")
;; Index:
;; «.find-lgrep» (to "find-lgrep")
;; «.find-lgreps» (to "find-lgreps")
;; ********
;; See: (find-eev "eev-plinks.el" "find-lgrep")
;;; __ _ _ _
;;; / _(_)_ __ __| | | | __ _ _ __ ___ _ __
;;; | |_| | '_ \ / _` |_____| |/ _` | '__/ _ \ '_ \
;;; | _| | | | | (_| |_____| | (_| | | | __/ |_) |
;;; |_| |_|_| |_|\__,_| |_|\__, |_| \___| .__/
;;; |___/ |_|
;;
;; «find-lgrep» (to ".find-lgrep")
;; Tests: (ee-find-lgrep "/tmp/foo.elc" "\"e\"")
;; (find-lgrep 'find-efile "\"e\"")
;; (find-lgrep 'brg "[ ']brg[ )]")
;;
(defun find-lgrep (fname0 re)
"Use lgrep to search for all occurrences of RE in FNAME0.
If FNAME0 is a symbol, convert it to a file name using:
(setq fname0 (symbol-file fname0 'defun)))
If FNAME0 ends in .elc, convert it to the corresponding .el."
(find-dbsw-call (ee-find-lgrep fname0 re)))
(defun ee-find-lgrep (fname0 re)
"An internal function used by `find-lgrep'."
(if (symbolp fname0) (setq fname0 (symbol-file fname0 'defun)))
(setq fname0 (ee-file-name-elc-to-el (ee-expand fname0)))
(let* ((dir (file-name-directory fname0))
(fname (file-name-nondirectory fname0)))
`(lgrep ,re ,fname ,dir)))
(defun ee-file-name-elc-to-el (fname)
"If FNAME ends with .elc, return the corresponding .el.
Return FNAME unchanged in the other cases. Note: this is fragile,
and I don't know if it would work on packages installed by
straight.el."
(replace-regexp-in-string ".elc$" ".el" fname))
;;; __ _ _ _
;;; / _(_)_ __ __| | | | __ _ _ __ ___ _ __ ___
;;; | |_| | '_ \ / _` |_____| |/ _` | '__/ _ \ '_ \/ __|
;;; | _| | | | | (_| |_____| | (_| | | | __/ |_) \__ \
;;; |_| |_|_| |_|\__,_| |_|\__, |_| \___| .__/|___/
;;; |___/ |_|
;;
;; «find-lgreps» (to ".find-lgreps")
;; TODO: rename this
;; (find-lgreps 'find-efile)
;; (find-lgreps 'find-efile "e")
;; (find-lgreps 'brg "brg")
(defun find-lgreps (f &optional stem)
"Go to a temporary buffer with links for finding the source code of F."
(interactive (find-function-read))
(setq stem (or stem (format "%s" f)))
(let* ((fname0 (symbol-file f 'defun))
(fname (ee-shorten-file-name (ee-file-name-elc-to-el fname0)))
(stem1 (format "\"%s\"" stem))
(stem2 (format "[( ']%s$" stem))
(stem3 (format "[( ']%s[ )]" stem)))
(find-estring-elisp
`(ee-template0 "\
;; (find-lgreps '{f} \"{stem}\")
;; (find-eloadhistory-for '{f})
;; (find-eloadhistory-for '{f} 2 \" {f})\")
;; (find-efunction 'find-lgreps)
(find-efunctionpp '{f})
{(ee-S `(find-lgrep ',f ,stem1))}
{(ee-S `(find-lgrep ',f ,stem2))}
{(ee-S `(find-lgrep ',f ,stem3))}
{(ee-S `(find-lgrep ,fname ,stem1))}
{(ee-S `(find-lgrep ,fname ,stem2))}
{(ee-S `(find-lgrep ,fname ,stem3))}
{(ee-S `(find-fline ,fname))}
"))))
(provide 'find-lgrep-links)
;; Local Variables:
;; coding: utf-8-unix
;; End: