Re: Filter interactive function declared in file
Heime <[email protected]>
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <tWN77dzndr0NkTbKkzGeuDzOf2hxLKt7yB_w8UVpPlTMG3KW5gQhSzXkjU5xNZHEwAPNwXppmkShe_i6IuvBI_flg2IP7yYtsBhTSnJFI64=@protonmail.com> |
On Wednesday, February 25th, 2026 at 8:07 AM, [email protected] <[email protected]> wrote: > Heime <[email protected]> writes: > > > How can I pass a pattern. Without checking a pattern I get an enormous > > long list of matching function names. > > > > (defun mazonas-smbptn (smb pattern file) > > "Filter symbol SYM defined in a specific file that are currently loaded." > > (when (and (fboundp smb) > > (string= (symbol-file smb) file) > > (commandp smb) > > (string-match-p pattern (symbol-name smb))) > > smb)) > > > > - Delete (fboundp smb) because if (commandp smb) returns t, > then (fboundp smb) is guaranteed to return t. > - Move (commandp smb) to where (fboundp smb) is. > - Swap the (string= ...) and (string-match-p ...) so that > you do not call (symbol-file ...) if the pattern does not match. > > New version: > > (defun mazonas-smbptn (smb pattern file) > "Filter symbol SYM defined in a specific file that are currently loaded." > (when (and (commandp smb) > (string-match-p pattern (symbol-name smb)) > (string= (symbol-file smb) file)) > smb)) > > > > > (defun mazonas-agfun (file pattern) > > "List all interactive functions defined in FILE." > > > > (interactive > > (list > > (read-file-name "File: ") > > (read-regexp "Symbol Pattern (RET for all): "))) > > > > (let (smbs) > > (when (find-file-noselect file) > > (mapatoms (lambda (smb) > > (when (mazonas-smbptn smb pattern file) > > (push smb smbs)))) > > > > (message "Interactive functions: %s" > > (seq-filter #'commandp smbs)) > > (seq-filter #'commandp smbs)))) > > > > - Add a counter for use after you have accumulated your > list: > ... > (let ((smbs nil) > (count 0)) > (when (find-file-noselect file) > (mapatoms (lambda (smb) > (when (mazonas-smbptn smb pattern file) > (setq count (1+ count)) > (push smb smbs)))) > (if (> count 0) > (message "Interactive functions: %s" > (seq-filter #'commandp smbs)) > (message "No interactive functions found")))) > > - Try it non-interactively, for example, using > > (mazonas-agfun "/usr/share/emacs/30.2/lisp/subr.elc" "global-set-*") > => "Interactive functions: (global-set-key)" I did as instructed but getting "No interactive functions found" for the subr.elc example. > (Use M-x locate to locate files on your operating system.) > > - Be careful to specify "file" correctly so that > (string= (symbol-file smb) file) > yields t. > > You should be able to check this by using Edebug and > setting a breakpoint at the expression: > (string= (symbol-file smb) file) > in the function ‘mazonas-smbptn’, and examining the values > that (symbol-file smb) and ‘file’ when the breakpoint is > triggered. If they do not match, then you have not > specified the value of ‘file’ correctly. > > -- > The lyf so short, the craft so long to lerne. > - Geoffrey Chaucer, The Parliament of Birds. >