Skip to content

Instantly share code, notes, and snippets.

@sheijk
Created January 26, 2021 21:56

Revisions

  1. sheijk created this gist Jan 26, 2021.
    72 changes: 72 additions & 0 deletions shk-toggle-menu.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;; Toggling options
    ;;
    ;; This is using the following conventions:
    ;; - single keys activates local mode/option
    ;; - global version is prefixed with g and the same key

    (defun shk-flyspell-or-prog-mode ()
    (interactive)
    (if flyspell-mode
    (flyspell-mode -1)
    (if (derived-mode-p 'prog-mode)
    (flyspell-prog-mode)
    (flyspell-mode 1))))

    (defun shk-ws-butler-mode ()
    (interactive)
    (ws-butler-mode))

    (defun shk-transient-toggle-for (key description variable turn-on &optional turn-off)
    "Return forms to be spliced into define-transient-command"
    (unless turn-off
    (setq turn-off turn-on))
    (list
    (list key (concat "" description) turn-off :if-non-nil variable)
    (list key (concat " " description) turn-on :if-nil variable)))

    (defun shk-transient-toggle-for-mode (key description mode)
    "Return forms to be spliced into define-transient-command"
    (shk-transient-toggle-for key description mode mode mode))

    (transient-define-prefix shk-toggle-menu ()
    "Menu to toggle options and minor modes"
    ["dummy"])

    (transient-insert-suffix 'shk-toggle-menu (list 0)
    `["Start"
    ["Debug on"
    ,@(shk-transient-toggle-for "d" "error" 'debug-on-error 'toggle-debug-on-error)
    ,@(shk-transient-toggle-for "D" "quit" 'debug-on-quit 'toggle-debug-on-quit)]
    ["Highlighting"
    ,@(shk-transient-toggle-for-mode "w" "whitespace" 'whitespace-mode)
    ,@(shk-transient-toggle-for-mode "|" "fill column" 'display-fill-column-indicator-mode)
    ,@(shk-transient-toggle-for "t" "truncate lines" 'truncate-lines 'toggle-truncate-lines)
    ,@(shk-transient-toggle-for-mode "T" "visual line mode" 'visual-line-mode)
    ,@(shk-transient-toggle-for-mode "l" "line numbers" 'linum-mode)
    ,@(shk-transient-toggle-for-mode "L" "current line" 'global-hl-line-mode)
    ,@(shk-transient-toggle-for-mode "i" "indent guide" 'indent-guide-mode)]
    ["HL (global)"
    ,@(shk-transient-toggle-for-mode "gw" "whitespace" 'global-whitespace-mode)
    ,@(shk-transient-toggle-for-mode "gT" "visual" 'global-visual-line-mode)
    ,@(shk-transient-toggle-for-mode "gl" "line number" 'global-linum-mode)
    ,@(shk-transient-toggle-for-mode "gi" "indent guide"'indent-guide-global-mode)]
    ["Spell/lint"
    ("s" "✓ spell check" flyspell-mode :if-non-nil flyspell-mode)
    ("s" " spell check comments" flyspell-prog-mode
    :if (lambda () (and (not flyspell-mode) (derived-mode-p 'prog-mode))))
    ("s" " spell check" flyspell-mode
    :if (lambda () (and (not flyspell-mode) (not (derived-mode-p 'prog-mode)))))

    ,@(shk-transient-toggle-for-mode "S" "flycheck" 'flycheck-mode)
    ,@(shk-transient-toggle-for-mode "M" "flymake" 'flymake-mode)]
    ["Assistance"
    ,@(shk-transient-toggle-for "f" "auto fill" 'auto-fill-function 'auto-fill-mode)
    ,@(shk-transient-toggle-for-mode "p" "popwin" 'popwin-mode)
    ("W" " whitespace butler" shk-ws-butler-mode)]
    ["Completion"
    ,@(shk-transient-toggle-for "cn" "none" 'shk-completion-none-mode 'shk-completion-none)
    ,@(shk-transient-toggle-for "ch" "helm" 'shk-completion-helm-mode 'shk-completion-helm)
    ,@(shk-transient-toggle-for "ci" "ivy" 'ivy-mode 'shk-completion-ivy)
    ,@(shk-transient-toggle-for "cd" "ido" 'shk-completion-ido-mode 'shk-completion-ido)
    ,@(shk-transient-toggle-for "cs" "selectrum" 'shk-completion-selectrum-mode 'shk-completion-selectrum)]])