0

I have been trying to add a "Save as" button to the org mode toolbar.

Using the example from: https://stackoverflow.com/questions/20917411/how-to-add-item-to-toolbar-in-emacs#28326863

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

I looked at the manual at https://www.gnu.org/software/emacs/manual/html_node/elisp/Tool-Bar.html but do not understand it enough.

I have been able to show the "Save as" button in the toolbar but I do not understand the other parts of the code enough to be able to actually run the "Save as" command if this button is clicked.

I have tried to search for this and have not found any helpful examples.

Any help is appreciated.

ironfish
  • 149
  • 8

2 Answers2

1

To get this

Save as ... toolbar icons

do this

* How to add custom "Save As HTML" or "Save as ASCII" buttons to Toolbar

With cursor inside the below source block, do a =C-c C-c=.  You will
get clickable tool bar buttons when in an ~org-mode~ buffer.

#+begin_src emacs-lisp :results silent
  (tool-bar-add-item "saveas"
             'org-html-export-to-html
             'save-as-html
             :help "Save as HTML"
             :enable '(derived-mode-p 'org-mode))


  (tool-bar-add-item "saveas"
             'org-ascii-export-to-ascii
             'save-as-ascii
             :help "Save as ASCII"
             :enable '(derived-mode-p 'org-mode))  
#+end_src
  • Thanks very much for your input – ironfish Jun 25 '22 at 12:32
  • Looking up org-ascii-export-to-ascii the manual says this removes Org markup and I am not sure if this is what I would want since I want to save as the original org mode file – ironfish Jun 25 '22 at 12:34
  • I would like to be able to do the same command as File > Save as, and I am also not sure why an export to ascii would be needed before saving. Could you explain? – ironfish Jun 25 '22 at 12:37
  • I never knew that `write-file` is called as `File -> Save as`. I have added another answer. –  Jun 25 '22 at 13:51
1

If you want to add Menu Bar -> File -> Save As (which is bound to C-x C-w) to Tool Bar then do

(tool-bar-add-item-from-menu 'write-file "save" nil
                 :label "Save As")
  • Thank you so much for that answer :) It works exactly like I want. I tried and tried to figure this out myself, before posting, but I find it very hard to find any docs on commands, syntax, etc, so you have been very helpful. – ironfish Jun 25 '22 at 19:05
  • I understand each part of your answer except for the 'nil' - could you explain why that is there? – ironfish Jun 26 '22 at 02:59
  • I made one minor change from using "save" to using "saveas" which shows the "Save as" icon. – ironfish Jun 26 '22 at 03:01