From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thorsten Jolitz Newsgroups: gmane.emacs.help Subject: Re: How to get a list of all commands with given prefix? Date: Wed, 19 Mar 2014 02:07:04 +0100 Message-ID: <87siqfgfnr.fsf@gmail.com> References: <87lhw7mlrg.fsf@gmail.com> <06caca3d-1b40-407b-87f3-0ce7327d3c85@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1395191208 23670 80.91.229.3 (19 Mar 2014 01:06:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Mar 2014 01:06:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 19 02:06:57 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WQ4y4-0007Ud-Bo for geh-help-gnu-emacs@m.gmane.org; Wed, 19 Mar 2014 02:06:52 +0100 Original-Received: from localhost ([::1]:38111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ4y3-0007RG-Si for geh-help-gnu-emacs@m.gmane.org; Tue, 18 Mar 2014 21:06:51 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38001) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ4xP-0006HI-5X for help-gnu-emacs@gnu.org; Tue, 18 Mar 2014 21:06:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQ4xJ-0004r7-QL for help-gnu-emacs@gnu.org; Tue, 18 Mar 2014 21:06:11 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:49786) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ4xJ-0004qr-JE for help-gnu-emacs@gnu.org; Tue, 18 Mar 2014 21:06:05 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WQ4xI-0006Il-12 for help-gnu-emacs@gnu.org; Wed, 19 Mar 2014 02:06:04 +0100 Original-Received: from g231224000.adsl.alicedsl.de ([92.231.224.0]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Mar 2014 02:06:04 +0100 Original-Received: from tjolitz by g231224000.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 19 Mar 2014 02:06:04 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: g231224000.adsl.alicedsl.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:QGzOh17ZSm36h5ipJRE7eaScUBE= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96601 Archived-At: Drew Adams 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