【问题标题】:How to add a tool-bar button in emacs?如何在 emacs 中添加工具栏按钮?
【发布时间】:2014-09-01 07:50:01
【问题描述】:

我尝试在工具栏中添加一个按钮,但这不起作用。 如何做到这一点,我检查了 Emacs wiki,但我什么也没找到。 我使用了 emacs 24.3.1。 工具栏显示,但不是我的新项目。


我可以使用 eval-buffer 运行它,但不能使用我的 .emacs 或找到其他解决方案来解决该问题。 当我使用 eval-buffer 添加它时,我的按钮在滚动后离开我的工具栏。

(defun omar-hotel ()
 "another nonce menu function"
 (interactive)
 (message "hotel, motel, holiday inn"))

(define-key global-map [tool-bar omar-button]
'(menu-item "Hotel" omar-hotel
   :image (image :type xpm :file "/usr/share/emacs/24.3/etc/images/jump-to.xpm")
   )
)

【问题讨论】:

  • 尝试在您的菜单项中将omar-hotel 更改为[omar-hotel]。并且也许确保在从您的 init 文件调用此代码之前打开tool-bar-mode。但是尝试让我看到和你一样的东西:它在 eval'd 时有效,但不是来自 .emacs
  • 尝试在您的 menu-item 中将 omar-hotel 更改为 [omar-hotel] 。这不起作用。

标签: emacs elisp toolbar emacs24 dot-emacs


【解决方案1】:

您好,我找到了一个简单的解决方案来添加工具栏按钮“拼写”是 /usr/share/emacs/23.4/etc/images/ 中的图像

(defun omar-hotel ()
 "another nonce menu function"
 (interactive)
 (message "hotel, motel, holiday inn"))

    (tool-bar-add-item "spell" 'omar-hotel
               'omar-hotel
               :help   "Run fonction omar-hotel")

【讨论】:

    【解决方案2】:

    您的代码有效,但您需要在工具栏处于活动状态后执行它。

    如果您像这样将代码添加到 .emacs 中,您的问题应该会消失:

    (add-hook 'after-init-hook
              (lambda ()
                (define-key global-map [tool-bar omar-button]
                  '(menu-item "Hotel" omar-hotel
                              :image (image :type xpm :file "/usr/share/emacs/24.3/etc/images/jump-to.xpm")
                              ))))
    

    【讨论】:

    • 我将您的代码添加到我的 .emacs 中。我检查函数定义后是否有问题,但与工具栏没有关系。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多