How to add a tool-bar button in emacs?

别来无恙 提交于 2019-12-01 07:54:36

问题


I try to add a button in the tool-bar but that doesn't works. how to do that, i check in Emacs wiki and i find nothing. I used emacs 24.3.1. The toolsbar are displayed but not my new item.


I can run it with eval-buffer but not with my .emacs or find another solution to resolve that. When i add it with eval-buffer my button leave my toolbar after a scroll.

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

回答1:


Hi i found a simple solution to add a toolbar button "spell" is the image in /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:


Your code works, but you need to execute it after tool bar is active.

If you add your code to your .emacs like this, your problem should be gone:

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


来源:https://stackoverflow.com/questions/24684979/how-to-add-a-tool-bar-button-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!