简体   繁体   中英

Get list of interactive functions in Elisp/Emacs

I have a bunch of my interactive functions with a prefix, say *zb/" (eg "zb/create-temp-buffer"). I am a bit tired every time to type in Mx interaction this prefix of a command I like to run.

To automate this I'd like to retrieve a list of all my interactive functions and show them through ido-completing-read ( btw, possibly there are other alternative and modern ways to create input with predefined items and autocompletion? ). But I did not manage to find how to retrieve a such list. Could you please give me a cue how to achieve this?

List of all available interactive functions will be enough; to filter is not an issue.

Thanks.

Maybe give Smex a try?

Smex is a Mx enhancement for Emacs. Built on top of Ido, it provides a convenient interface to your recently and most frequently used commands. And to all the other commands, too.

You can use this function for selection

(defun eab/select-zb/ ()
  (interactive)
  (call-interactively
   (intern
    (ido-completing-read "M-x zb/"
             (mapcar 'symbol-name (apropos-internal "^zb/"))))))

You say "possibly there are other alternative and modern ways to create input with predefined items and autocompletion?" .

  1. Use Icicles and just bind icicle-must-match-regexp :
(defun zb/ ()
      (interactive)
      (let ((icicle-must-match-regexp  "^zb/"))
        (call-interactively (intern (completing-read "zb/ command: " obarray 'commandp t)))))
  1. You can also do it with vanilla Emacs and without Ido:
(defun zb/ ()
      (interactive)
      (call-interactively
        (intern (completing-read
                 "zb/ command: "
                 obarray
                 (lambda (cmd)
                   (and (commandp cmd)  (string-match-p "^zb/" (symbol-name cmd))))
                 t))))

Or do as @artscan suggested: use apropos-internal to match the regexp. IOW, either let completing-read do the matching or match first using apropos-internal . You can pass the commandp predicate to apropos-internal as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM