Emacs M-x命令用于调用“GUI样式”菜单

时间:2008-12-24 01:48:42

标签: user-interface emacs scripting elisp command

问题:在我的Emacs-variant使用特定于操作系统的桌面功能的情况下,如何找到用于在Emacs中执行基于GUI的操作的M-x等效命令?

背景:传统理解指出Emacs中的所有内容都是命令,只要您知道命令的名称,就可以通过M-x调用这些命令。假设这个陈述是正确的,那么在基于“桌面”的Emacs变体中找到用于触发“GUI样式”菜单的命令名称的方法是什么?

例如,如果我鼠标选择“文件”菜单打开文件,则会弹出特定于操作系统的“GUI”样式文件打开对话框,等待我的输入。

我怎样才能找到完全相同的M-x等效命令?

描述-key会告诉我我需要知道什么,但它有使用的迹象:

M-x menu-find-file-existing

不会调用“GUI”样式的文件打开对话框。相反,它使用Emacs内部非GUI-OS中立变体。

2 个答案:

答案 0 :(得分:7)

你需要欺骗Emacs以为键盘没有被使用,这并不像欺骗它认为鼠标 一样。 :)

(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
  "Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
  (let ((last-nonmenu-event nil))
    ad-do-it))

在WinXP上测试Emacs 22.2.1。我相信这个范例已经存在了一段时间,所以它应该适用于较旧的Emacs。如果XEmacs的工作方式与此类似,那就不知道了。

答案 1 :(得分:3)

哇,我很高兴你问过这个问题。我一直想要自己查一下。

C-h k后面的菜单选项会告诉你这个。例如,您可以从选择菜单/编辑/粘贴中获得:

<menu-bar> <edit> <paste> runs the command clipboard-yank
  which is an interactive compiled Lisp function in `menu-bar.el'.
It is bound to <paste>, <f18>, <menu-bar> <edit> <paste>.
(clipboard-yank)
Insert the clipboard contents, or the last stretch of killed text.

如果您需要详细信息,请点击menu-bar-el到LISP来源的链接:

(defun menu-find-file-existing ()
  "Edit the existing file FILENAME."
  (interactive)
  (let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
                  (x-uses-old-gtk-dialog))))
     (filename (car (find-file-read-args "Find file: " mustmatch))))
    (if mustmatch
    (find-file-existing filename)
      (find-file filename))))