【问题标题】:Emacs: list the names of every interactive commandEmacs:列出每个交互式命令的名称
【发布时间】:2015-04-29 19:54:08
【问题描述】:

即任何可以从M-x 运行的东西。包括任何 C 内置函数、用户定义等。

例如list-all-commands

'(... about-emacs ... zap-to-char ...)

考虑到M-x 的自动完成等行为,它必须是可访问的。

How to print all the defined variables in emacs?,我们可以访问所有符号:

(pp-eval-expression
   (quote (loop for x being the symbols
      if (boundp x)
      collect (symbol-name x))))

但其中大部分不是交互式功能。

编辑:

叹息其实有一点。通过将此列表发送到语音识别引擎,在对连字符和symbol-name 进行标记之后,我应该能够说出除了最奇怪的书面命令之外的所有命令(Dragon NaturallySpeaking 很好)。如果没有这个列表,识别准确度会降低,我将不得不手动硬编码我想要的任何命令的键盘快捷键,或者处理错误识别时不断的挫败感。

这就是我需要的。但是,我可能还想编写自己的自动完成行为;或比较不同模式提供的名称的相似性;或发现在词法上与我使用的常用命令相似的新命令(例如,使用align-regex 通常可能建议使用align-entire);或分析不同地区命名运动中的任何不一致(例如beginning-of-lineup-list);或者我已经看过ido,想看看是否有一个标准函数来构建它用来高效查询的数据结构;或者我想对它进行基准测试;或者我只是好奇。这有很多用途。

Emacs 的全部意义在于行为向程序员公开,而不仅仅是通过 UI。

您现在可以收回投票结束吗?我认为这不是“不清楚我在问什么”,如果是建议澄清点。

【问题讨论】:

  • 这有什么意义?你已经有M-x
  • 我有M-x。我没有list-all-commands 。查看我的编辑。
  • 您是否包含默认未加载(或自动加载)的命令?在通过某种方式加载相关库之前,Emacs 不会知道大量的命令。
  • @phils "runnable" 命令,很好。

标签: emacs


【解决方案1】:
(let ((cmds  ()))
  (mapatoms (lambda (s) (when (commandp s) (push s cmds))))
  cmds)

【讨论】:

    【解决方案2】:

    您可以使用commandp 来检查符号是否是交互式命令:

    (pp-eval-expression
     '(loop for x being the symbols
            if (commandp x) collect x))
    

    【讨论】:

      【解决方案3】:

      M-x 空间 应该为您提供一个包含完整完成列表的缓冲区。使用 C-x o(可能多次)从迷你缓冲区切换到完成缓冲区并复制其内容。

      simple.el 中的函数 read-extended-command 中可以找到完成该功能的 elisp 函数:

      (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)))
      

      【讨论】:

      • 这真的很酷。你知道是什么提供的吗?然后我可以阅读它的源代码,并找到它正在调用的函数。
      • @sam boosalis: C-h k M-x 给出:M-x runs the command execute-extended-command, which is an interactive compiled Lisp function. It is bound to <execute>, <menu>, M-x. (execute-extended-command PREFIXARG &optional COMMAND-NAME) ...我会在具有该名称的来源中搜索。
      • 我的 Emacs (GNU Emacs 24.2.1 (x86_64-apple-darwin, NS apple-appkit-1038.36)) 说 runs the command execute-extended-command, which is an interactive built-in function in 'C source code'。它没有指向源的链接,我不知道 C 是否有意义。
      • @sam boosalis:一会儿。安装 elisp 源。试图找到函数。
      • @sam boosalis:我在 debian linux 上添加了我的 emacs 24.4.1 中引用的 lisp 源代码。我不能告诉你它是否可以在 mac emacs 中工作
      猜你喜欢
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      相关资源
      最近更新 更多