;;; my-tool-bar.el --- Tool bar -*- lexical-binding: t -*- ;;; Commentary: ;;; Code: (defun my-tool-bar-newline () "Newline." "\n") (defun my-tool-bar-function-save (event) "Run `save-buffer'." (interactive "e") (let () ;;(message "%s" event) (save-buffer) ;;(message "foo") )) (defvar my-tool-bar-button-save "Save " "Button to run `save-buffer'.") (defun my-tool-bar-function-open (event) "Run `find-file' or 'counsel-find-file' if available." (interactive "e") (let () ;;(message "%s" event) (if (featurep 'counsel) (counsel-find-file) (find-file)) ;;(message "foo") )) (defvar my-tool-bar-button-open "Open " "Button to run `find-file' or `counsel-find-file' if available.") (defun my-tool-bar-function-cancle (event) "Run `keyboard-escape-quit'." ;; "Run `keyboard-quit'." (interactive "e") (let () ;; (keyboard-quit) (keyboard-escape-quit))) (defvar my-tool-bar-button-cancle "Cancle " "Button to run `keyboard-escape-quit'.") ;; "Button to run `keyboard-quit'." ;; (defun my-tool-bar-format-save () ;; "Produce the Menu button for the tool bar that shows the menu bar." ;; `((menu-bar menu-item ,my-tool-bar-button-save ;; my-tool-bar-function-save :help "Save buffer"))) (defun my-tool-bar-format () "Produce tool-bar buttons for the tab bar. These buttons will be shown when `my-tool-bar-mode' is enabled. You can hide these buttons by customizing `tab-bar-format' and removing `my-tool-bar-format' from it." (when my-tool-bar-mode `(;;(sep-history-back menu-item ,(tab-bar-separator) ignore) (save menu-item ,my-tool-bar-button-save my-tool-bar-function-save :help "Save") ;;(sep-test menu-item "" ignore) (open menu-item ,my-tool-bar-button-open my-tool-bar-function-open :help "Open File...") (cancle menu-item ,my-tool-bar-button-cancle my-tool-bar-function-cancle :help "Cancle") (sep-tool-bar menu-item ,(my-tool-bar-newline) ignore)))) (defun my-tool-bar--load-buttons () "Load the icons for the tool bar buttons." ;; (emoji "") see e.g. https://emojipedia.org/hamburger ;; (symbol "") see e.g. https://www.compart.com/en/unicode/U+2630 (require 'icons) (unless (iconp 'my-tool-bar-icon-save) (define-icon my-tool-bar-icon-save nil `((image "save.xpm" :height (1.5 . em) :margin ,tab-bar-button-margin :ascent center) (emoji "💾") (symbol "🖫") (text "Save" ;; :face tab-bar-tab-inactive )) "Icon for save." :version "29.1")) (setq my-tool-bar-button-save (icon-string 'my-tool-bar-icon-save)) (unless (iconp 'my-tool-bar-icon-open) (define-icon my-tool-bar-icon-open nil `((image "open.xpm" :height (1.5 . em) :margin ,tab-bar-button-margin :ascent center) (emoji "📂") (symbol "🗁") (text "Open" ;; :face tab-bar-tab-inactive )) "Icon for open file." :version "29.1")) (setq my-tool-bar-button-open (icon-string 'my-tool-bar-icon-open)) (unless (iconp 'my-tool-bar-icon-cancle) (define-icon my-tool-bar-icon-cancle nil `((image "cancel.xpm" :height (1.5 . em) :margin ,tab-bar-button-margin :ascent center) (text "Quit" ;; :face tab-bar-tab-inactive )) "Icon for quit." :version "29.1")) (setq my-tool-bar-button-cancle (icon-string 'my-tool-bar-icon-cancle)) ) (define-minor-mode my-tool-bar-mode "Toggle tool bar mode for the tab bar. Tool bar mode displays action buttons. It will enable `tab-bar-mode' if not already." :global t :group 'tab-bar (if my-tool-bar-mode (progn (my-tool-bar--load-buttons) (unless tab-bar-mode (tab-bar-mode 1)) ;;(add-hook 'pre-command-hook #'tab-bar--history-pre-change) ;;(add-hook 'window-configuration-change-hook #'tab-bar--history-change) ) ;;(remove-hook 'pre-command-hook #'tab-bar--history-pre-change) ;;(remove-hook 'window-configuration-change-hook #'tab-bar--history-change) )) (provide 'my-tool-bar) ;;; my-tool-bar.el ends here