unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* 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
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ 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] 10+ 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
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ 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
  2024-11-13 23:46 ` Emanuel Berg
  3 siblings, 1 reply; 10+ 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] 10+ 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
  2024-11-13 23:46 ` Emanuel Berg
  3 siblings, 0 replies; 10+ 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] 10+ 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; 10+ 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] 10+ 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
                   ` (2 preceding siblings ...)
  2024-11-12 13:14 ` Eduardo Ochs
@ 2024-11-13 23:46 ` Emanuel Berg
  3 siblings, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2024-11-13 23:46 UTC (permalink / raw)
  To: help-gnu-emacs

mbork 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?

You will collect based on `symbol-file', as you said.

  (symbol-file #'find-sibling-file)
  ; /usr/local/share/emacs/31.0.50/lisp/files.elc

If n/a, it gets more tricky.

When it is eval'd, who gets that data?

Help does. And some other.
You must ask one of them.

  (setq help-mode--current-data (list :symbol f :file file-name))

Otherwise it cannot happen. You can grep the source and stuff,
but that only says it is defined here or there as a bunch of
chars in a text file, not that it is the definition in use.

PS. Hello, everyone! Soo good to see this list is alive again!
    I'm stuck with my project but any day now I'll be my last
    commit on that. I've said for several weeks ...
    https://dataswamp.org/~incal/tr/good/bad-alive.png
DS.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-11-13 23:46 UTC | newest]

Thread overview: 10+ 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
2024-11-13 23:46 ` Emanuel Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).