Reputation: 1977
i.e. anything that can be run from M-x
. including any C built-ins, user-defined, etc.
e.g. list-all-commands
'(... about-emacs ... zap-to-char ...)
it must be accessible, given behavior like autocomplete for M-x
.
from How to print all the defined variables in emacs?, we can access all symbols:
(pp-eval-expression
(quote (loop for x being the symbols
if (boundp x)
collect (symbol-name x))))
but most of those are not interactive functions.
EDIT:
sigh there is a point, in fact. By sending this list to the speech recognition engine, after tokenizing on the hyphen, and symbol-name
and whatever, I should be able to speak all but the most strangely-written commands (Dragon NaturallySpeaking is good about that). without this list, recognition accuracy would decrease, and I would have to manually hardcode keyboard shortcuts for any commands I wanted, or deal with constant frustration at misrecognitions.
that is what I need. but, I might also want to write my own autocomplete behavior; or compare the similarity of the names that different modes provide; or to discover new commands that are lexically similar to common commands I use (e.g. using align-regex
often might suggest align-entire
); or to analyze any inconsistencies in naming movement through different regions (e.g. beginning-of-line
versus up-list
); or I already looked at say ido
, and wanted to see if there was a standard function to build the data structure it uses to efficiently query; or I feel like benchmarking it; or maybe I'm just curious. there are lots of uses for this.
the whole point of Emacs is that behavior is exposed to the programmer, and not just through the UI.
Can you take back your vote to close now? I think it's not "unclear what I'm asking", and if it is suggest points of clarification.
Upvotes: 3
Views: 951
Reputation: 30701
(let ((cmds ()))
(mapatoms (lambda (s) (when (commandp s) (push s cmds))))
cmds)
Upvotes: 4
Reputation: 891
M-x space should give you a buffer with a complete list of completions. Use C-x o (perhaps multiple times) to switch from the mini-buffer to the completion buffer and copy its contents.
The elisp function doing that completion is found in simple.el in the function read-extended-command:
(completing-read
(concat (cond
((eq current-prefix-arg '-) "- ")
((and (consp current-prefix-arg)
(eq (car current-prefix-arg) 4)) "C-u ")
((and (consp current-prefix-arg)
(integerp (car current-prefix-arg)))
(format "%d " (car current-prefix-arg)))
((integerp current-prefix-arg)
(format "%d " current-prefix-arg)))
;; This isn't strictly correct if `execute-extended-command'
;; is bound to anything else (e.g. [menu]).
;; It could use (key-description (this-single-command-keys)),
;; but actually a prompt other than "M-x" would be confusing,
;; because "M-x" is a well-known prompt to read a command
;; and it serves as a shorthand for "Extended command: ".
"M-x ")
obarray 'commandp t nil 'extended-command-history)))
Upvotes: 2
Reputation: 5027
You can check if a symbol is an interactive command with commandp
:
(pp-eval-expression
'(loop for x being the symbols
if (commandp x) collect x))
Upvotes: 3