all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp code to list interactive functions
@ 2021-11-04  8:08 Alexander Asteroth
  2021-11-04  9:43 ` Po Lu
  2021-11-04  9:44 ` Robert Pluim
  0 siblings, 2 replies; 15+ messages in thread
From: Alexander Asteroth @ 2021-11-04  8:08 UTC (permalink / raw)
  To: emacs-devel

Dear all,

I don't know if I'm right here but I don't find a group that is devoted
to elisp programming. I'm trying to write a little funtion that I can
call from emacsclient to get a list of interactive functions
available. The result shoud be a list of strings or just one string,
more or less what the *Completions* buffer displays when pressing
M-x followed by <TAB>. I'm sure there must be a very simple solution to
this but somehow I get lost in the code in simple.el on my search for
it.

Why am I doing this? Im currently trying to make i3wm and emacs more
aware of each other, because after 3 years of using exwm I'm now moving
back to using a dedicated WM. Nevertheless I want the WM to still feel
like Emacs, when I use it ;-)

Cheers,

	Alex



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

* Re: elisp code to list interactive functions
  2021-11-04  8:08 elisp code to list interactive functions Alexander Asteroth
@ 2021-11-04  9:43 ` Po Lu
  2021-11-04  9:44 ` Robert Pluim
  1 sibling, 0 replies; 15+ messages in thread
From: Po Lu @ 2021-11-04  9:43 UTC (permalink / raw)
  To: Alexander Asteroth; +Cc: emacs-devel

Alexander Asteroth <alexander.asteroth@h-brs.de> writes:

> I don't know if I'm right here but I don't find a group that is devoted
> to elisp programming. I'm trying to write a little funtion that I can
> call from emacsclient to get a list of interactive functions
> available. The result shoud be a list of strings or just one string,
> more or less what the *Completions* buffer displays when pressing
> M-x followed by <TAB>. I'm sure there must be a very simple solution to
> this but somehow I get lost in the code in simple.el on my search for
> it.

Isn't that done by searching for commands among all interned symbols in
obarray?



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

* Re: elisp code to list interactive functions
  2021-11-04  8:08 elisp code to list interactive functions Alexander Asteroth
  2021-11-04  9:43 ` Po Lu
@ 2021-11-04  9:44 ` Robert Pluim
  2021-11-04 10:49   ` Alexander Asteroth
                     ` (2 more replies)
  1 sibling, 3 replies; 15+ messages in thread
From: Robert Pluim @ 2021-11-04  9:44 UTC (permalink / raw)
  To: Alexander Asteroth; +Cc: emacs-devel

>>>>> On Thu, 04 Nov 2021 09:08:26 +0100, Alexander Asteroth <alexander.asteroth@h-brs.de> said:

    Alexander> Dear all,
    Alexander> I don't know if I'm right here but I don't find a group that is devoted
    Alexander> to elisp programming. I'm trying to write a little funtion that I can
    Alexander> call from emacsclient to get a list of interactive functions
    Alexander> available. The result shoud be a list of strings or just one string,
    Alexander> more or less what the *Completions* buffer displays when pressing
    Alexander> M-x followed by <TAB>. I'm sure there must be a very simple solution to
    Alexander> this but somehow I get lost in the code in simple.el on my search for
    Alexander> it.

You mean something like this?

(all-completions ""
               #'help--symbol-completion-table  
               (lambda (f)
                 (commandp f)))

(that returns quite a few things)

Robert
-- 



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

* Re: elisp code to list interactive functions
  2021-11-04  9:44 ` Robert Pluim
@ 2021-11-04 10:49   ` Alexander Asteroth
  2021-11-04 11:51   ` Philipp Stephani
  2021-11-04 19:34   ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Alexander Asteroth @ 2021-11-04 10:49 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1550 bytes --]

Perfect, that did what I wanted more precisely:

-----------------------
(require 'help-fns)
(require 'seq)

(defun aa/show-interactive-commands ()
  (interactive)
  (seq-sort-by #'length #'<
	       (all-completions ""
				#'help--symbol-completion-table  
				(lambda (f)
				  (commandp f)))))
-----------------------

Returns a list (sorted by size) of available interactive commands. I can
now make them known to i3 to integrate them on demand. Great!

Thanks,

        Alex


On Do, Nov 04 2021, 10:44:17, Robert Pluim wrote:

>>>>>> On Thu, 04 Nov 2021 09:08:26 +0100, Alexander Asteroth <alexander.asteroth@h-brs.de> said:
>
>     Alexander> Dear all,
>     Alexander> I don't know if I'm right here but I don't find a group that is devoted
>     Alexander> to elisp programming. I'm trying to write a little funtion that I can
>     Alexander> call from emacsclient to get a list of interactive functions
>     Alexander> available. The result shoud be a list of strings or just one string,
>     Alexander> more or less what the *Completions* buffer displays when pressing
>     Alexander> M-x followed by <TAB>. I'm sure there must be a very simple solution to
>     Alexander> this but somehow I get lost in the code in simple.el on my search for
>     Alexander> it.
>
> You mean something like this?
>
> (all-completions ""
>                #'help--symbol-completion-table  
>                (lambda (f)
>                  (commandp f)))
>
> (that returns quite a few things)
>
> Robert


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 524 bytes --]

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

* Re: elisp code to list interactive functions
  2021-11-04  9:44 ` Robert Pluim
  2021-11-04 10:49   ` Alexander Asteroth
@ 2021-11-04 11:51   ` Philipp Stephani
  2021-11-04 16:14     ` Alexander Asteroth
  2021-11-04 17:07     ` Lars Ingebrigtsen
  2021-11-04 19:34   ` Stefan Monnier
  2 siblings, 2 replies; 15+ messages in thread
From: Philipp Stephani @ 2021-11-04 11:51 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Alexander Asteroth, Emacs developers

Am Do., 4. Nov. 2021 um 10:44 Uhr schrieb Robert Pluim <rpluim@gmail.com>:
>
> >>>>> On Thu, 04 Nov 2021 09:08:26 +0100, Alexander Asteroth <alexander.asteroth@h-brs.de> said:
>
>     Alexander> Dear all,
>     Alexander> I don't know if I'm right here but I don't find a group that is devoted
>     Alexander> to elisp programming. I'm trying to write a little funtion that I can
>     Alexander> call from emacsclient to get a list of interactive functions
>     Alexander> available. The result shoud be a list of strings or just one string,
>     Alexander> more or less what the *Completions* buffer displays when pressing
>     Alexander> M-x followed by <TAB>. I'm sure there must be a very simple solution to
>     Alexander> this but somehow I get lost in the code in simple.el on my search for
>     Alexander> it.
>
> You mean something like this?
>
> (all-completions ""
>                #'help--symbol-completion-table
>                (lambda (f)
>                  (commandp f)))
>
> (that returns quite a few things)


That's using an internal function, which should not be used outside
help.el and can go away at any time. But the following should also
work:
(cl-loop for symbol being the symbols
   when (commandp symbol)
   collect symbol)



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

* Re: elisp code to list interactive functions
  2021-11-04 11:51   ` Philipp Stephani
@ 2021-11-04 16:14     ` Alexander Asteroth
  2021-11-04 17:07     ` Lars Ingebrigtsen
  1 sibling, 0 replies; 15+ messages in thread
From: Alexander Asteroth @ 2021-11-04 16:14 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: Robert Pluim, Emacs developers

[-- Attachment #1: Type: text/plain, Size: 2399 bytes --]

Even better. That way one require statement becomes unnecessary.

Thanks,

        Alex

PS: Now in i3wm I can bind this to something like S-x to either start
programs or run interactive emacs commands (and focus emacs). Similar
behaviour as I had bound S-x to in EXWM :-)

The emacs code now looks like this:

> (defun aa/show-interactive-commands ()
>   (interactive)
>   (seq-sort-by #'length #'<
> 	       (cl-loop for symbol being the symbols
> 			when (commandp symbol)
> 			collect (symbol-name symbol))))

and I can call it from a script like:

> #!/bin/bash

> if [ $# -eq 0 ]
> then
>     BUFFERS=`emacsclient -e '(aa/show-interactive-commands)' | sed 's/\" \"/)\\\\n(/g' | sed 's/\"//g'`
>     echo -e $BUFFERS 
> else
>     emacsclient -ne "$1" >/dev/null
>     i3-msg -q '[class="Emacs"] focus'
> fi

Which in turn is bound in i3 to Super-x to call

> bindsym Mod4+x exec "rofi -modi 'M-x:~/bin/emacs-interactive-command.sh,run' -combi-modi M-x,run -show combi"


On Do, Nov 04 2021, 12:51:28, Philipp Stephani wrote:

> Am Do., 4. Nov. 2021 um 10:44 Uhr schrieb Robert Pluim <rpluim@gmail.com>:
>>
>> >>>>> On Thu, 04 Nov 2021 09:08:26 +0100, Alexander Asteroth <alexander.asteroth@h-brs.de> said:
>>
>>     Alexander> Dear all,
>>     Alexander> I don't know if I'm right here but I don't find a group that is devoted
>>     Alexander> to elisp programming. I'm trying to write a little funtion that I can
>>     Alexander> call from emacsclient to get a list of interactive functions
>>     Alexander> available. The result shoud be a list of strings or just one string,
>>     Alexander> more or less what the *Completions* buffer displays when pressing
>>     Alexander> M-x followed by <TAB>. I'm sure there must be a very simple solution to
>>     Alexander> this but somehow I get lost in the code in simple.el on my search for
>>     Alexander> it.
>>
>> You mean something like this?
>>
>> (all-completions ""
>>                #'help--symbol-completion-table
>>                (lambda (f)
>>                  (commandp f)))
>>
>> (that returns quite a few things)
>
>
> That's using an internal function, which should not be used outside
> help.el and can go away at any time. But the following should also
> work:
> (cl-loop for symbol being the symbols
>    when (commandp symbol)
>    collect symbol)


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 524 bytes --]

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

* Re: elisp code to list interactive functions
  2021-11-04 11:51   ` Philipp Stephani
  2021-11-04 16:14     ` Alexander Asteroth
@ 2021-11-04 17:07     ` Lars Ingebrigtsen
  2021-11-04 17:32       ` Robert Pluim
                         ` (2 more replies)
  1 sibling, 3 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-04 17:07 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: Robert Pluim, Alexander Asteroth, Emacs developers

Philipp Stephani <p.stephani2@gmail.com> writes:

> That's using an internal function, which should not be used outside
> help.el and can go away at any time. But the following should also
> work:
> (cl-loop for symbol being the symbols
>    when (commandp symbol)
>    collect symbol)

Since we're code golfing:

(seq-filter #'commandp obarray)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: elisp code to list interactive functions
  2021-11-04 17:07     ` Lars Ingebrigtsen
@ 2021-11-04 17:32       ` Robert Pluim
  2021-11-04 17:44       ` Andreas Schwab
  2021-11-04 20:06       ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Robert Pluim @ 2021-11-04 17:32 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Philipp Stephani, Alexander Asteroth, Emacs developers

>>>>> On Thu, 04 Nov 2021 18:07:34 +0100, Lars Ingebrigtsen <larsi@gnus.org> said:

    Lars> Philipp Stephani <p.stephani2@gmail.com> writes:
    >> That's using an internal function, which should not be used outside
    >> help.el and can go away at any time. But the following should also
    >> work:
    >> (cl-loop for symbol being the symbols
    >> when (commandp symbol)
    >> collect symbol)

    Lars> Since we're code golfing:

    Lars> (seq-filter #'commandp obarray)

But aren't we planning to rename obarray in Emacs 31?

😇

Robert
-- 



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

* Re: elisp code to list interactive functions
  2021-11-04 17:07     ` Lars Ingebrigtsen
  2021-11-04 17:32       ` Robert Pluim
@ 2021-11-04 17:44       ` Andreas Schwab
  2021-11-04 20:06       ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Andreas Schwab @ 2021-11-04 17:44 UTC (permalink / raw)
  To: Lars Ingebrigtsen
  Cc: Philipp Stephani, Alexander Asteroth, Robert Pluim,
	Emacs developers

On Nov 04 2021, Lars Ingebrigtsen wrote:

> Philipp Stephani <p.stephani2@gmail.com> writes:
>
>> That's using an internal function, which should not be used outside
>> help.el and can go away at any time. But the following should also
>> work:
>> (cl-loop for symbol being the symbols
>>    when (commandp symbol)
>>    collect symbol)
>
> Since we're code golfing:
>
> (seq-filter #'commandp obarray)

I don't think mapc does something useful with obarrays.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



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

* Re: elisp code to list interactive functions
  2021-11-04  9:44 ` Robert Pluim
  2021-11-04 10:49   ` Alexander Asteroth
  2021-11-04 11:51   ` Philipp Stephani
@ 2021-11-04 19:34   ` Stefan Monnier
  2 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2021-11-04 19:34 UTC (permalink / raw)
  To: Robert Pluim; +Cc: Alexander Asteroth, emacs-devel

> (all-completions ""
>                #'help--symbol-completion-table  

This is internal (as evidenced by the "--").
You can pass `obarray` instead, which is not.

>                (lambda (f)
>                  (commandp f)))

Aka #'commandp


        Stefan




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

* Re: elisp code to list interactive functions
  2021-11-04 17:07     ` Lars Ingebrigtsen
  2021-11-04 17:32       ` Robert Pluim
  2021-11-04 17:44       ` Andreas Schwab
@ 2021-11-04 20:06       ` Stefan Monnier
  2021-11-04 20:15         ` Lars Ingebrigtsen
  2 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2021-11-04 20:06 UTC (permalink / raw)
  To: Lars Ingebrigtsen
  Cc: Philipp Stephani, Robert Pluim, Alexander Asteroth,
	Emacs developers

> (seq-filter #'commandp obarray)

Sweet: not only the code is shorter, but the returned value is much
shorter as well ;-)


        Stefan




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

* Re: elisp code to list interactive functions
  2021-11-04 20:06       ` Stefan Monnier
@ 2021-11-04 20:15         ` Lars Ingebrigtsen
  2021-11-04 20:20           ` Stefan Monnier
  2021-11-05  0:12           ` Po Lu
  0 siblings, 2 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-04 20:15 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Philipp Stephani, Alexander Asteroth, Robert Pluim,
	Emacs developers

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (seq-filter #'commandp obarray)
>
> Sweet: not only the code is shorter, but the returned value is much
> shorter as well ;-)

Win win!

I thought somebody had extended the seq functions to also work on these
thingies, but I guess not?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

* Re: elisp code to list interactive functions
  2021-11-04 20:15         ` Lars Ingebrigtsen
@ 2021-11-04 20:20           ` Stefan Monnier
  2021-11-05  2:08             ` Lars Ingebrigtsen
  2021-11-05  0:12           ` Po Lu
  1 sibling, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2021-11-04 20:20 UTC (permalink / raw)
  To: Lars Ingebrigtsen
  Cc: Philipp Stephani, Robert Pluim, Alexander Asteroth,
	Emacs developers

Lars Ingebrigtsen [2021-11-04 21:15:01] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>> (seq-filter #'commandp obarray)
>> Sweet: not only the code is shorter, but the returned value is much
>> shorter as well ;-)
> Win win!
> I thought somebody had extended the seq functions to also work on these
> thingies, but I guess not?

Nope.  I did provide a patch which introduced a separate type for
obarrays, but it come with some rough corners, and in any case it
introduces a backward incompatibility with fairly limited advantages, so
it's not clear it's a good idea.

But until such a thing is done, we can't reliably distinguish an obarray
from a vector.

This said, an obarray is fundamentally unordered, so it would be odd for
`seq.el` to support it.


        Stefan




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

* Re: elisp code to list interactive functions
  2021-11-04 20:15         ` Lars Ingebrigtsen
  2021-11-04 20:20           ` Stefan Monnier
@ 2021-11-05  0:12           ` Po Lu
  1 sibling, 0 replies; 15+ messages in thread
From: Po Lu @ 2021-11-05  0:12 UTC (permalink / raw)
  To: Lars Ingebrigtsen
  Cc: Stefan Monnier, Philipp Stephani, Alexander Asteroth,
	Robert Pluim, Emacs developers

Lars Ingebrigtsen <larsi@gnus.org> writes:

> I thought somebody had extended the seq functions to also work on these
> thingies, but I guess not?

I think not, and that you will have to use mapatoms for them.  Something
along the lines of:

  (let (commands)
    (mapatoms (lambda (atom)
                (when (commandp atom)
                  (push atom commands))))
    commands)



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

* Re: elisp code to list interactive functions
  2021-11-04 20:20           ` Stefan Monnier
@ 2021-11-05  2:08             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 15+ messages in thread
From: Lars Ingebrigtsen @ 2021-11-05  2:08 UTC (permalink / raw)
  To: Stefan Monnier
  Cc: Philipp Stephani, Alexander Asteroth, Robert Pluim,
	Emacs developers

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Nope.  I did provide a patch which introduced a separate type for
> obarrays, but it come with some rough corners, and in any case it
> introduces a backward incompatibility with fairly limited advantages, so
> it's not clear it's a good idea.
>
> But until such a thing is done, we can't reliably distinguish an obarray
> from a vector.

The advantages are fairly limited, but it feels like obarrays are such a
strange little corner of Emacs Lisp, and it'd be really cool to have it,
like, becoming a more well-behaved citizen.

> This said, an obarray is fundamentally unordered, so it would be odd for
> `seq.el` to support it.

Er, yes.  `map-filter' er could support it, though (if it could
distinguish it).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no



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

end of thread, other threads:[~2021-11-05  2:08 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-04  8:08 elisp code to list interactive functions Alexander Asteroth
2021-11-04  9:43 ` Po Lu
2021-11-04  9:44 ` Robert Pluim
2021-11-04 10:49   ` Alexander Asteroth
2021-11-04 11:51   ` Philipp Stephani
2021-11-04 16:14     ` Alexander Asteroth
2021-11-04 17:07     ` Lars Ingebrigtsen
2021-11-04 17:32       ` Robert Pluim
2021-11-04 17:44       ` Andreas Schwab
2021-11-04 20:06       ` Stefan Monnier
2021-11-04 20:15         ` Lars Ingebrigtsen
2021-11-04 20:20           ` Stefan Monnier
2021-11-05  2:08             ` Lars Ingebrigtsen
2021-11-05  0:12           ` Po Lu
2021-11-04 19:34   ` Stefan Monnier

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.