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.

2 Answers 2

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")
3
  • 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 at 19:05
  • I understand each part of your answer except for the 'nil' - could you explain why that is there?
    – ironfish
    Jun 26 at 2:59
  • I made one minor change from using "save" to using "saveas" which shows the "Save as" icon.
    – ironfish
    Jun 26 at 3:01
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
4
  • Thanks very much for your input
    – ironfish
    Jun 25 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 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 at 12:37
  • I never knew that write-file is called as File -> Save as. I have added another answer. Jun 25 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.