* How to get all commands defined in a specified file (or files)?
@ 2024-11-11 19:36 mbork
2024-11-11 20:18 ` Eli Zaretskii
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: mbork @ 2024-11-11 19:36 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi all,
say that I'd like to define a `execute-extended-command' alternative
which would only allow to run commands defined in a specified file. How
can I get all such commands? I know about `symbol-file', but I don't
know how it works (and it's complicated enough that I'm not sure I want
to study it ATM;-) - I tried to instrument it for edebug, but a quick
run revealed only that it's pretty mysterious). I also looked at the
property plist of a function name and saw that the filename is not kept
there. Any hints?
TIA,
--
Marcin Borkowski
https://mbork.pl
https://crimsonelevendelightpetrichor.net/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get all commands defined in a specified file (or files)?
2024-11-11 19:36 How to get all commands defined in a specified file (or files)? mbork
@ 2024-11-11 20:18 ` Eli Zaretskii
2024-11-11 20:38 ` [External] : " Drew Adams
2024-11-11 21:58 ` mbork
2024-11-12 0:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-11-12 13:14 ` Eduardo Ochs
2 siblings, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2024-11-11 20:18 UTC (permalink / raw)
To: help-gnu-emacs
> From: mbork@mbork.pl
> Date: Mon, 11 Nov 2024 20:36:33 +0100
>
> Hi all,
>
> say that I'd like to define a `execute-extended-command' alternative
> which would only allow to run commands defined in a specified file. How
> can I get all such commands? I know about `symbol-file', but I don't
> know how it works (and it's complicated enough that I'm not sure I want
> to study it ATM;-) - I tried to instrument it for edebug, but a quick
> run revealed only that it's pretty mysterious). I also looked at the
> property plist of a function name and saw that the filename is not kept
> there. Any hints?
We have a facility to mark commands as relevant to a major mode or a
list of major modes. If your file defines a major mode, you can use
this for doing what you want. See the command
execute-extended-command-for-buffer. A more general facility is the
variable read-extended-command-predicate.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [External] : Re: How to get all commands defined in a specified file (or files)?
2024-11-11 20:18 ` Eli Zaretskii
@ 2024-11-11 20:38 ` Drew Adams
2024-11-11 22:00 ` mbork
2024-11-11 21:58 ` mbork
1 sibling, 1 reply; 9+ messages in thread
From: Drew Adams @ 2024-11-11 20:38 UTC (permalink / raw)
To: Eli Zaretskii, help-gnu-emacs@gnu.org
> > say that I'd like to define a `execute-extended-command' alternative
> > which would only allow to run commands defined in a specified file.
> How
> > can I get all such commands? I know about `symbol-file', but I don't
> > know how it works (and it's complicated enough that I'm not sure I
> want
> > to study it ATM;-) - I tried to instrument it for edebug, but a quick
> > run revealed only that it's pretty mysterious). I also looked at the
> > property plist of a function name and saw that the filename is not
> kept
> > there. Any hints?
>
> We have a facility to mark commands as relevant to a major mode or a
> list of major modes. If your file defines a major mode, you can use
> this for doing what you want. See the command
> execute-extended-command-for-buffer. A more general facility is the
> variable read-extended-command-predicate.
Maybe also...
Has the file been loaded, so the commands are already defined?
Or are they at least autoloaded?
Does the file use a library-specific prefix for all of its
function names?
If so, you can filter all commands (`commandp') according
to that library prefix.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [External] : Re: How to get all commands defined in a specified file (or files)?
2024-11-11 20:38 ` [External] : " Drew Adams
@ 2024-11-11 22:00 ` mbork
2024-11-11 23:33 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: mbork @ 2024-11-11 22:00 UTC (permalink / raw)
To: Drew Adams; +Cc: Eli Zaretskii, help-gnu-emacs@gnu.org
On 2024-11-11, at 20:38, Drew Adams <drew.adams@oracle.com> wrote:
>> > say that I'd like to define a `execute-extended-command' alternative
>> > which would only allow to run commands defined in a specified file.
>> How
>> > can I get all such commands? I know about `symbol-file', but I don't
>> > know how it works (and it's complicated enough that I'm not sure I
>> want
>> > to study it ATM;-) - I tried to instrument it for edebug, but a quick
>> > run revealed only that it's pretty mysterious). I also looked at the
>> > property plist of a function name and saw that the filename is not
>> kept
>> > there. Any hints?
>>
>> We have a facility to mark commands as relevant to a major mode or a
>> list of major modes. If your file defines a major mode, you can use
>> this for doing what you want. See the command
>> execute-extended-command-for-buffer. A more general facility is the
>> variable read-extended-command-predicate.
>
> Maybe also...
>
> Has the file been loaded, so the commands are already defined?
> Or are they at least autoloaded?
Let's assume they are loaded, though if it worked for autoloaded
functions, too, it would be even better.
> Does the file use a library-specific prefix for all of its
> function names?
Definitely not.
> If so, you can filter all commands (`commandp') according
> to that library prefix.
I'm not sure what you mean here -- isn't `commandp' way too general
here?
Best,
--
Marcin Borkowski
https://mbork.pl
https://crimsonelevendelightpetrichor.net/
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [External] : Re: How to get all commands defined in a specified file (or files)?
2024-11-11 22:00 ` mbork
@ 2024-11-11 23:33 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2024-11-11 23:33 UTC (permalink / raw)
To: mbork@mbork.pl; +Cc: Eli Zaretskii, help-gnu-emacs@gnu.org
> > Does the file use a library-specific prefix for all of its
> > function names?
>
> Definitely not.
>
> > If so, you can filter all commands (`commandp') according
> > to that library prefix.
>
> I'm not sure what you mean here -- isn't `commandp' way too general
> here?
It would be, if you didn't filter also "according to that
library prefix". ;-)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get all commands defined in a specified file (or files)?
2024-11-11 20:18 ` Eli Zaretskii
2024-11-11 20:38 ` [External] : " Drew Adams
@ 2024-11-11 21:58 ` mbork
1 sibling, 0 replies; 9+ messages in thread
From: mbork @ 2024-11-11 21:58 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
On 2024-11-11, at 22:18, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: mbork@mbork.pl
>> Date: Mon, 11 Nov 2024 20:36:33 +0100
>>
>> Hi all,
>>
>> say that I'd like to define a `execute-extended-command' alternative
>> which would only allow to run commands defined in a specified file. How
>> can I get all such commands? I know about `symbol-file', but I don't
>> know how it works (and it's complicated enough that I'm not sure I want
>> to study it ATM;-) - I tried to instrument it for edebug, but a quick
>> run revealed only that it's pretty mysterious). I also looked at the
>> property plist of a function name and saw that the filename is not kept
>> there. Any hints?
>
> We have a facility to mark commands as relevant to a major mode or a
> list of major modes. If your file defines a major mode, you can use
> this for doing what you want. See the command
> execute-extended-command-for-buffer. A more general facility is the
> variable read-extended-command-predicate.
I know, it's cool, I even blogged about it!
(https://mbork.pl/2021-03-27_The_interactive_clause_and_modes).
But what I'm asking is something very different. I explicitly don't
want commands related to a certain mode (major or minor), but commands
defined in a specific file. I know that every function somehow "knows"
where its source is (because it's shown by `describe-function'), but I
want to be able to get that info (for ex., in a function I'd put in
`read-extended-command-predicate', which I knew about, since it's
mentioned in that blog post, but I forgot, so thanks for that!).
Best,
--
Marcin Borkowski
https://mbork.pl
https://crimsonelevendelightpetrichor.net/
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get all commands defined in a specified file (or files)?
2024-11-11 19:36 How to get all commands defined in a specified file (or files)? mbork
2024-11-11 20:18 ` Eli Zaretskii
@ 2024-11-12 0:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-11-12 16:12 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-11-12 13:14 ` Eduardo Ochs
2 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-11-12 0:00 UTC (permalink / raw)
To: help-gnu-emacs
> say that I'd like to define a `execute-extended-command' alternative
> which would only allow to run commands defined in a specified file. How
> can I get all such commands?
Look for the file in `load-history`, that will give you a list of all
the functions/vars/types/faces/... defined in there.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get all commands defined in a specified file (or files)?
2024-11-12 0:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-11-12 16:12 ` Michael Heerdegen via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 9+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2024-11-12 16:12 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> Look for the file in `load-history`, that will give you a list of all
> the functions/vars/types/faces/... defined in there.
Or use the shortcut `feature-symbols', like in
#+begin_src emacs-lisp
(require 'seq)
(seq-filter #'commandp
(mapcar #'cdr
(seq-filter (lambda (entry) (eq (car-safe entry) 'defun))
(feature-symbols 'MY-LIB))))
#+end_src
AFAIU this will only work when MY-LIB is loaded. And I dunno if
this is correct when MY-LIB is used in natively compiled form. The
implementation of `symbol-file' suggests that it is not.
Michael.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How to get all commands defined in a specified file (or files)?
2024-11-11 19:36 How to get all commands defined in a specified file (or files)? mbork
2024-11-11 20:18 ` Eli Zaretskii
2024-11-12 0:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-11-12 13:14 ` Eduardo Ochs
2 siblings, 0 replies; 9+ messages in thread
From: Eduardo Ochs @ 2024-11-12 13:14 UTC (permalink / raw)
To: mbork; +Cc: Help Gnu Emacs mailing list
[-- Attachment #1: Type: text/plain, Size: 1436 bytes --]
On Mon, 11 Nov 2024 at 16:38, <mbork@mbork.pl> wrote:
> Hi all,
>
> say that I'd like to define a `execute-extended-command' alternative
> which would only allow to run commands defined in a specified file. How
> can I get all such commands? I know about `symbol-file', but I don't
> know how it works (and it's complicated enough that I'm not sure I want
> to study it ATM;-) - I tried to instrument it for edebug, but a quick
> run revealed only that it's pretty mysterious). I also looked at the
> property plist of a function name and saw that the filename is not kept
> there. Any hints?
>
> TIA,
>
> --
> Marcin Borkowski
> https://mbork.pl
> https://crimsonelevendelightpetrichor.net/
>
>
Hi Marcin,
eev has some functions for examining the load-history. I'm attaching a
screenshot, and you can try them with:
;; From: http://anggtwu.net/2024-find-tryit-links.html
(progn
(package-initialize)
(package-refresh-contents)
(package-install 'eev)
(eev-beginner)
(find-eev-quick-intro "2. Evaluating Lisp")
)
)
and then `M-x find-eloadhistory-links'.
The load-history is easy to use with cl-loop after we understand its
format, but understanding its format took me a while.
"Eev is not for adults - and if you're an adult then you will probably
want to uninstall it after a few minutes". More on that here:
http://anggtwu.net/2024-find-tryit-links.html#uninstalling
Cheers!
Eduardo Ochs
[-- Attachment #2: sshot.png --]
[-- Type: image/png, Size: 102513 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-11-12 16:12 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-11 19:36 How to get all commands defined in a specified file (or files)? mbork
2024-11-11 20:18 ` Eli Zaretskii
2024-11-11 20:38 ` [External] : " Drew Adams
2024-11-11 22:00 ` mbork
2024-11-11 23:33 ` Drew Adams
2024-11-11 21:58 ` mbork
2024-11-12 0:00 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-11-12 16:12 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-11-12 13:14 ` Eduardo Ochs
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.