Leader Keys

A literate programming file for setting up a leader sequence.

The following needs to go in ha-config:

And then add the following in specific files for a single collection:

(major-mode-hydra-define emacs-lisp-mode nil
  ("Eval"
   (("b" eval-buffer "buffer")
    ("e" eval-defun "defun")
    ("r" eval-region "region"))
   "REPL"
   (("I" ielm "ielm"))
   "Test"
   (("t" ert "prompt")
    ("T" (ert t) "all")
    ("F" (ert :failed) "failed"))
   "Doc"
   (("d" describe-foo-at-point "thing-at-pt")
    ("f" describe-function "function")
    ("v" describe-variable "variable")
    ("i" info-lookup-symbol "info lookup"))))

But what about something complicated, like Org?

Introduction

I liked how Evil-focused Emacs configurations, like Doom and Spacemacs, made the concept of converting the plethora of Emacs functions from modifier-based keybindings, like C-x C-f, to key sequences, like SPC f f. I originally started out using the General project. It is a great project, but started Evil-specific. While Fox Kiester (noctuid) is converting it to a non-Evil project, it isn’t ready. Also, general always had a limitation that made me use Oleh Krehel’s (abo-abo) Hydra project for some things, so…

I would like to use the Major Mode Hydra project as a basis for my leaders. It will be prettier, and while it won’t have the nifty :general option to use-package, I think I can make it work.

Make things super pretty with these helper functions:

(use-package all-the-icons
  :config
  (defun with-faicon (icon str &optional height v-adjust)
    (s-concat (all-the-icons-faicon icon :v-adjust (or v-adjust 0) :height (or height 1)) " " str))

  (defun with-fileicon (icon str &optional height v-adjust)
    (s-concat (all-the-icons-fileicon icon :v-adjust (or v-adjust 0) :height (or height 1)) " " str))

  (defun with-octicon (icon str &optional height v-adjust)
    (s-concat (all-the-icons-octicon icon :v-adjust (or v-adjust 0) :height (or height 1)) " " str))

  (defun with-material (icon str &optional height v-adjust)
    (s-concat (all-the-icons-material icon :v-adjust (or v-adjust 0) :height (or height 1)) " " str))

  (defun with-mode-icon (mode str &optional height nospace face)
    (let* ((v-adjust (if (eq major-mode 'emacs-lisp-mode) 0.0 0.05))
           (args     `(:height ,(or height 1) :v-adjust ,v-adjust))
           (_         (when face
                        (lax-plist-put args :face face)))
           (icon     (apply #'all-the-icons-icon-for-mode mode args))
           (icon     (if (symbolp icon)
                         (apply #'all-the-icons-octicon "file-text" args)
                       icon)))
      (s-concat icon (if nospace "" " ") str))))

Top Level

When I hit the SPC, I want to bring up a magic table of goodness:

(defvar ha-leader--title (with-fileicon "emacs" "Hamacs Leader" 1 -0.05))

(pretty-hydra-define ha-leader (:foreign-keys warn :title ha-leader--title :quit-key "q")
  ("Execute"
   (("SPC" execute-extended-command "M-x")
    ("!" shell-command "Shell")
    ("u" universal-argument "C-u"))

   "Org"
   (("X" org-capture  "org capture")
    ("L" org-store-link  "store org link"))
   )
  ;; "."   '("repeat" . repeat)
  ;; "!"   '("shell command" . shell-command)
  ;; "|"   'piper
  ;; "RET" 'bookmark-jump
  ;; "a"   '(:ignore t :which-key "apps")
  ;; "a <escape>" '(keyboard-escape-quit :which-key t)
  ;; "m"   '(:ignore t :which-key "mode")
  ;; "m <escape>" '(keyboard-escape-quit :which-key t)
  ;; "o"   '(:ignore t :which-key "org/open")
  ;; "o <escape>" '(keyboard-escape-quit :which-key t)
  ;; "o i" 'imenu
  )

What sort of wide grouping can I make:

  • Operations:
    TAB
    Workspaces
    f
    file operations
    w
    window operations
    b
    buffers
    t
    toggles
    h
    help
    d
    data manipulation
    p
    projects
    x
    text
    q
    quit
    r
    replace (R for query-replace)
    y
    copy operation (currently current-location) ?
  • Org:
    C
    Capture Code … could be lowercase
    X
    Org Capture
    L
    Store Link … could be lowercase
    Y
    Copy Code (code-to-clipboard-dwim)
    i
    org-mac-link-get-link
  • Apps:
    o
    org / open
    a
    applications
    g
    git versioning
    n
    notes
  • Movement:
    j
    jump
    s
    search / spelling?
    >
    next error
    <
    prev error
    m
    bookmark
  • Other/Misc:
    e
    errors
    s
    spellcheck
    .
    repeat? Do I use this? Use bookmark?

What’s Free? i should be repurposed k is free l is free m … but , works for minor mode, so m for bookmark? n should be retooled v … c … z …

GitHub - domtronn/all-the-icons.el: A utility package to collect various Icon Fonts and propertize them within Emacs. And then attach it:

(evil-define-key 'normal 'global
      "," 'ha-leader/body)

(all-the-icons-icon-for-buffer) (all-the-icons-icon-for-dir) all-the-icons-icon-for-file all-the-icons-icon-for-mode all-the-icons-icon-for-url

Subsections

File Operations

(defvar ha-window--title (with-faicon "file" "File Management" 1 -0.05))

(pretty-hydra-define ha-window (:foreign-keys warn :title ha-window--title :quit-key "q")
  ("Actions"
   (("TAB" other-window "switch")
    ("x" ace-delete-window "delete")
    ("m" ace-delete-other-windows "maximize")
    ("s" ace-swap-window "swap")
    ("a" ace-select-window "select"))

   "Resize"
   (("h" move-border-left "←")
    ("j" move-border-down "↓")
    ("k" move-border-up "↑")
    ("l" move-border-right "→")
    ("n" balance-windows "balance")
    ("f" toggle-frame-fullscreen "toggle fullscreen"))

   "Split"
   (("b" split-window-right "horizontally")
    ("B" split-window-horizontally-instead "horizontally instead")
    ("v" split-window-below "vertically")
    ("V" split-window-vertically-instead "vertically instead"))

   "Zoom"
   (("+" zoom-in "in")
    ("=" zoom-in)
    ("-" zoom-out "out")
    ("0" jp-zoom-default "reset"))))

Toggles

(pretty-hydra-define ha-toggles
  (:color amaranth :quit-key "q" :title (with-faicon "toggle-on" "Titel"))
  ("Basic"
   (("n" linum-mode "line number" :toggle t)
    ("w" whitespace-mode "whitespace" :toggle t)
    ("W" whitespace-cleanup-mode "whitespace cleanup" :toggle t)
    ("r" rainbow-mode "rainbow" :toggle t)
    ("L" page-break-lines-mode "page break lines" :toggle t))
   "Highlight"
   (("s" symbol-overlay-mode "symbol" :toggle t)
    ("l" hl-line-mode "line" :toggle t)
    ("x" highlight-sexp-mode "sexp" :toggle t)
    ("t" hl-todo-mode "todo" :toggle t))
   "UI"
   (("d" jp-themes-toggle-light-dark "dark theme" :toggle jp-current-theme-dark-p))
   "Coding"
   (("p" smartparens-mode "smartparens" :toggle t)
    ("P" smartparens-strict-mode "smartparens strict" :toggle t)
    ("S" show-smartparens-mode "show smartparens" :toggle t)
    ("f" flycheck-mode "flycheck" :toggle t))
   "Emacs"
   (("D" toggle-debug-on-error "debug on error" :toggle (default-value 'debug-on-error))
    ("X" toggle-debug-on-quit "debug on quit" :toggle (default-value 'debug-on-quit)))))