all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thorsten Jolitz <tjolitz@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to get a list of all commands with given prefix?
Date: Wed, 19 Mar 2014 02:07:04 +0100	[thread overview]
Message-ID: <87siqfgfnr.fsf@gmail.com> (raw)
In-Reply-To: 06caca3d-1b40-407b-87f3-0ce7327d3c85@default

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	other threads:[~2014-03-19  1:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18 17:58 How to get a list of all commands with given prefix? Thorsten Jolitz
2014-03-18 18:03 ` Jambunathan K
2014-03-19  0:09   ` Thorsten Jolitz
2014-03-19 15:27     ` Jambunathan K
2014-03-19  8:03       ` Thorsten Jolitz
2014-03-19  8:14       ` Thorsten Jolitz
2014-03-19  8:28         ` Jambunathan K
2014-03-19  8:29           ` Jambunathan K
2014-03-18 18:16 ` Jambunathan K
2014-03-19  7:59   ` Alex Bennée
2014-03-19  8:23     ` Thorsten Jolitz
2014-03-19 10:02       ` Michael Heerdegen
2014-03-18 23:25 ` Drew Adams
2014-03-19  1:07   ` Thorsten Jolitz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87siqfgfnr.fsf@gmail.com \
    --to=tjolitz@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.