help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get a list of all commands with given prefix?


From: Thorsten Jolitz
Subject: Re: How to get a list of all commands with given prefix?
Date: Wed, 19 Mar 2014 02:07:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Drew Adams <drew.adams@oracle.com> writes:

>> I wonder how I can easily get a list of all interactive commands with a
>> given prefix 'foo-' in a program (non-interactively)?
>
> (defun foo (prefix &optional msgp)
>   (interactive "sPrefix: \np")
>   (let ((cmds  ()))
>     (mapatoms
>      (lambda (symb) (when (and (commandp symb)
>                           (string-match-p
>                            (format "\\`%s" (regexp-quote prefix))
>                            (symbol-name symb)))
>                  (push symb cmds))))
>     (when msgp (pp-eval-expression 'cmds))))
>
> (Interactive only so you can check it.)

Ups, while I was writing my extended solution yours sit here for more
than an hour already ...

Well, I post mine anyway, it has one additional feature - it stores all
Org commands with their keybindings, if they have one, as an alist in a
global variable:

#+begin_src emacs-lisp
  ;; usage examples:
  (setq omm-org-cmds-with-key-bindings nil)
  
  (defun omm-get-org-cmd-syms-with-key-bindings (s)
    "Store a list of symbols/keys pairs in obarray that are Org commands."
    (and (commandp s)
         (string-match "\\(^org-\\|^orgtbl-\\)" (symbol-name s))
         (with-temp-buffer
           (org-mode)
           (let ((cmd-key (substitute-command-keys
                           (concat "\\[" (symbol-name s) "]"))))
             (push
              (cons s
                    (if (string-match "^M-x " cmd-key) nil cmd-key))
              omm-org-cmds-with-key-bindings)))))
  
  (mapatoms 'omm-get-org-cmd-syms-with-key-bindings) 
  
  (nth 20 omm-org-cmds-with-key-bindings)
#+end_src

#+results:
: (org-clock-in . C-c C-x TAB)

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]