From 3542529df665d2909efaeac72b50471640e4c418 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Wed, 2 Jul 2025 20:41:43 +0200 Subject: [PATCH] add some buttons --- lisp/my/my-tool-bar.el | 146 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 7 deletions(-) diff --git a/lisp/my/my-tool-bar.el b/lisp/my/my-tool-bar.el index 495eb143..23e59e6f 100644 --- a/lisp/my/my-tool-bar.el +++ b/lisp/my/my-tool-bar.el @@ -7,6 +7,9 @@ "Newline." "\n") +(defvar my-tool-bar-separator " " + "Separator.") + (defun my-tool-bar-function-save (event) "Run `save-buffer'." (interactive "e") @@ -15,7 +18,6 @@ (save-buffer) ;;(message "foo") )) - (defvar my-tool-bar-button-save "Save " "Button to run `save-buffer'.") @@ -26,7 +28,6 @@ (if (featurep 'counsel) (counsel-find-file) (find-file)))) - (defvar my-tool-bar-button-open "Open " "Button to run `find-file' or `counsel-find-file' if available.") @@ -37,7 +38,6 @@ (let () ;; (keyboard-quit) (keyboard-escape-quit))) - (defvar my-tool-bar-button-cancle "Cancle " "Button to run `keyboard-escape-quit'.") ;; "Button to run `keyboard-quit'." @@ -47,16 +47,54 @@ (interactive "e") (let () (revert-buffer))) - (defvar my-tool-bar-button-revert "Revert " "Button to run `revert-buffer'.") +(defun my-tool-bar-function-undo (event) + "Run `undo-only'." + (interactive "e") + (let () + (undo-only))) +(defvar my-tool-bar-button-undo "Undo " + "Button to run `undo-only'.") + +(defun my-tool-bar-function-redo (event) + "Run `undo-redo'." + (interactive "e") + (let () + (undo-redo))) +(defvar my-tool-bar-button-redo "Redo " + "Button to run `undo-redo'.") + +(defun my-tool-bar-function-cut (event) + "Run `kill-region'." + (interactive "e") + (let () + (kill-region))) +(defvar my-tool-bar-button-cut "Cut " + "Button to run `cut-region'.") + +(defun my-tool-bar-function-copy (event) + "Run `kill-ring-save'." + (interactive "e") + (let () + (kill-ring-save))) +(defvar my-tool-bar-button-copy "Copy " + "Button to run `kill-ring-save'.") + +(defun my-tool-bar-function-paste (event) + "Run `yank'." + (interactive "e") + (let () + (yank))) +(defvar my-tool-bar-button-paste "Paste " + "Button to run `yank'.") + (defun my-tool-bar-function-fill (event) "Run `fill-region'." (interactive "e") (let () (fill-region))) - (defvar my-tool-bar-button-fill "Fill " "Button to run `fill-region'.") @@ -65,7 +103,6 @@ (interactive "e") (let () (flyspell-buffer))) - (defvar my-tool-bar-button-spell "Spell " "Button to run `flyspell-buffer'.") @@ -74,7 +111,6 @@ (interactive "e") (let () (langtool-check-buffer))) - (defvar my-tool-bar-button-langtool "langtool " "Button to run `langtool-check-buffer'.") @@ -92,6 +128,7 @@ You can hide these buttons by customizing `tab-bar-format' and removing `(;;(sep-history-back menu-item ,(tab-bar-separator) ignore) (save menu-item ,my-tool-bar-button-save my-tool-bar-function-save + ;; :enable buffer-modified-p :help "Save `save-buffer'") ;;(sep-test menu-item "" ignore) (open @@ -104,10 +141,27 @@ You can hide these buttons by customizing `tab-bar-format' and removing (revert menu-item ,my-tool-bar-button-revert my-tool-bar-function-revert :help "Re-read current buffer from its file `revert-buffer'") + (undo + menu-item ,my-tool-bar-button-undo my-tool-bar-function-undo + :help "Undo `undo-only'") + (redo + menu-item ,my-tool-bar-button-redo my-tool-bar-function-redo + :help "Redo `undo-redo'") + (cut + menu-item ,my-tool-bar-button-cut my-tool-bar-function-cut + :help "Cut text of region `kill-region'") + (copy + menu-item ,my-tool-bar-button-copy my-tool-bar-function-copy + :help "Copy text of region `kill-ring-save'") + (paste + menu-item ,my-tool-bar-button-paste my-tool-bar-function-paste + :help "Paste text `yank'") (fill menu-item ,my-tool-bar-button-fill my-tool-bar-function-fill :help "Fill text in region to fit between left and right margin `fill-region'") (sep-2 menu-item ,(tab-bar-separator) ignore) + ;; (sep-2 menu-item ,my-tool-bar-separator ignore + ;; :enable nil :help "") (spell menu-item ,my-tool-bar-button-spell my-tool-bar-function-spell :help "Spell `flyspell-buffer'") @@ -124,6 +178,19 @@ See `icon-preference' for the order of type preference." ;; (symbol "") see e.g. https://www.compart.com/en/unicode/U+2630 (require 'icons) + (unless (iconp 'my-tool-bar-icon-separator) + (define-icon my-tool-bar-icon-separator nil + `((image "separator.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text " " + ;; :face tab-bar-tab-inactive + )) + "Icon for save." + :version "29.1")) + (setq my-tool-bar-separator (icon-string 'my-tool-bar-icon-separator)) + (unless (iconp 'my-tool-bar-icon-save) (define-icon my-tool-bar-icon-save nil `((image "save.xpm" @@ -180,6 +247,71 @@ See `icon-preference' for the order of type preference." :version "29.1")) (setq my-tool-bar-button-revert (icon-string 'my-tool-bar-icon-revert)) + (unless (iconp 'my-tool-bar-icon-undo) + (define-icon my-tool-bar-icon-undo nil + `((image "undo.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text "Undo" + ;; :face tab-bar-tab-inactive + )) + "Icon for undo." + :version "29.1")) + (setq my-tool-bar-button-undo (icon-string 'my-tool-bar-icon-undo)) + + (unless (iconp 'my-tool-bar-icon-redo) + (define-icon my-tool-bar-icon-redo nil + `((image "redo.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text "Redo" + ;; :face tab-bar-tab-inactive + )) + "Icon for redo." + :version "29.1")) + (setq my-tool-bar-button-redo (icon-string 'my-tool-bar-icon-redo)) + + (unless (iconp 'my-tool-bar-icon-cut) + (define-icon my-tool-bar-icon-cut nil + `((image "cut.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text "Cut" + ;; :face tab-bar-tab-inactive + )) + "Icon for cut region." + :version "29.1")) + (setq my-tool-bar-button-cut (icon-string 'my-tool-bar-icon-cut)) + + (unless (iconp 'my-tool-bar-icon-copy) + (define-icon my-tool-bar-icon-copy nil + `((image "copy.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text "Copy" + ;; :face tab-bar-tab-inactive + )) + "Icon for copy region." + :version "29.1")) + (setq my-tool-bar-button-copy (icon-string 'my-tool-bar-icon-copy)) + + (unless (iconp 'my-tool-bar-icon-paste) + (define-icon my-tool-bar-icon-paste nil + `((image "paste.xpm" + :height (1.5 . em) + :margin ,tab-bar-button-margin + :ascent center) + (text "Paste" + ;; :face tab-bar-tab-inactive + )) + "Icon for paste." + :version "29.1")) + (setq my-tool-bar-button-paste (icon-string 'my-tool-bar-icon-paste)) + (unless (iconp 'my-tool-bar-icon-fill) (define-icon my-tool-bar-icon-fill nil `((image "newsticker/narrow.xpm"