From 7c025b69bd2b4e07bc1a7aef064215b08feb82f7 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 7 Jan 2020 12:45:23 -0500 Subject: [PATCH] Add a number of useful hydras --- emacs/init.org | 456 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 445 insertions(+), 11 deletions(-) diff --git a/emacs/init.org b/emacs/init.org index 2ffa935..2f27bee 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -850,6 +850,74 @@ Winner is a minor mode that keeps an undo/redo history of the window configurati (leader-def-key "wp" #'winner-undo) #+END_SRC +* Info +#+BEGIN_SRC emacs-lisp + (use-package info + :init + (defhydra hydra-info (:color blue + :hint nil) + " + Info-mode: + + ^^_]_ forward (next logical node) ^^_l_ast (←) _u_p (↑) _f_ollow reference _T_OC + ^^_[_ backward (prev logical node) ^^_r_eturn (→) _m_enu (↓) (C-u for new window) _i_ndex _d_irectory + ^^_n_ext (same level only) ^^_H_istory _g_oto (C-u for new window) _,_ next index item _c_opy node name + ^^_p_rev (same level only) _<_/_t_op _b_eginning of buffer virtual _I_ndex _C_lone buffer + regex _s_earch (_S_ case sensitive) ^^_>_ final _e_nd of buffer ^^ _a_propos + + _1_ .. _9_ Pick first .. ninth item in the node's menu. + + " + ("]" Info-forward-node) + ("[" Info-backward-node) + ("n" Info-next) + ("p" Info-prev) + ("s" Info-search) + ("S" Info-search-case-sensitively) + + ("l" Info-history-back) + ("r" Info-history-forward) + ("H" Info-history) + ("t" Info-top-node) + ("<" Info-top-node) + (">" Info-final-node) + + ("u" Info-up) + ("^" Info-up) + ("m" Info-menu) + ("g" Info-goto-node) + ("b" beginning-of-buffer) + ("e" end-of-buffer) + + ("f" Info-follow-reference) + ("i" Info-index) + ("," Info-index-next) + ("I" Info-virtual-index) + + ("T" Info-toc) + ("d" Info-directory) + ("c" Info-copy-current-node-name) + ("C" clone-buffer) + ("a" info-apropos) + + ("1" Info-nth-menu-item) + ("2" Info-nth-menu-item) + ("3" Info-nth-menu-item) + ("4" Info-nth-menu-item) + ("5" Info-nth-menu-item) + ("6" Info-nth-menu-item) + ("7" Info-nth-menu-item) + ("8" Info-nth-menu-item) + ("9" Info-nth-menu-item) + + ("?" Info-summary "Info summary") + ("h" Info-help "Info help") + ("q" Info-exit "Info exit") + ("C-g" nil "cancel" :color blue)) + :general + (Info-mode-map "C-/" 'hydra-info/body)) +#+END_SRC + * xref After I select an xref reference, I want the xref buffer closed: #+BEGIN_SRC emacs-lisp @@ -859,6 +927,107 @@ After I select an xref reference, I want the xref buffer closed: (general-def 'normal xref--xref-buffer-mode-map "RET" #'xref-goto-xref-and-quit :keymaps 'override) #+END_SRC +* IBuffer +#+BEGIN_SRC emacs-lisp + (use-package ibuffer + :straight (:type built-in) + :init + (defhydra hydra-ibuffer-main (:color pink :hint nil) + " + ^Navigation^ | ^Mark^ | ^Actions^ | ^View^ + -^----------^-+-^----^--------+-^-------^--------+-^----^------- + _k_: ʌ | _m_: mark | _D_: delete | _g_: refresh + _RET_: visit | _u_: unmark | _S_: save | _s_: sort + _j_: v | _*_: specific | _a_: all actions | _/_: filter + -^----------^-+-^----^--------+-^-------^--------+-^----^------- + " + ("j" ibuffer-forward-line) + ("RET" ibuffer-visit-buffer :color blue) + ("k" ibuffer-backward-line) + + ("m" ibuffer-mark-forward) + ("u" ibuffer-unmark-forward) + ("*" hydra-ibuffer-mark/body :color blue) + + ("D" ibuffer-do-delete) + ("S" ibuffer-do-save) + ("a" hydra-ibuffer-action/body :color blue) + + ("g" ibuffer-update) + ("s" hydra-ibuffer-sort/body :color blue) + ("/" hydra-ibuffer-filter/body :color blue) + + ("o" ibuffer-visit-buffer-other-window "other window" :color blue) + ("q" quit-window "quit ibuffer" :color blue) + ("." nil "toggle hydra" :color blue)) + + (defhydra hydra-ibuffer-mark (:color teal + :columns 5 + :after-exit (hydra-ibuffer-main/body)) + "Mark" + ("*" ibuffer-unmark-all "unmark all") + ("M" ibuffer-mark-by-mode "mode") + ("m" ibuffer-mark-modified-buffers "modified") + ("u" ibuffer-mark-unsaved-buffers "unsaved") + ("s" ibuffer-mark-special-buffers "special") + ("r" ibuffer-mark-read-only-buffers "read-only") + ("/" ibuffer-mark-dired-buffers "dired") + ("e" ibuffer-mark-dissociated-buffers "dissociated") + ("h" ibuffer-mark-help-buffers "help") + ("z" ibuffer-mark-compressed-file-buffers "compressed") + ("b" hydra-ibuffer-main/body "back" :color blue)) + + (defhydra hydra-ibuffer-action (:color teal + :columns 4 + :after-exit + (if (eq major-mode 'ibuffer-mode) + (hydra-ibuffer-main/body))) + "Action" + ("A" ibuffer-do-view "view") + ("E" ibuffer-do-eval "eval") + ("F" ibuffer-do-shell-command-file "shell-command-file") + ("I" ibuffer-do-query-replace-regexp "query-replace-regexp") + ("H" ibuffer-do-view-other-frame "view-other-frame") + ("N" ibuffer-do-shell-command-pipe-replace "shell-cmd-pipe-replace") + ("M" ibuffer-do-toggle-modified "toggle-modified") + ("O" ibuffer-do-occur "occur") + ("P" ibuffer-do-print "print") + ("Q" ibuffer-do-query-replace "query-replace") + ("R" ibuffer-do-rename-uniquely "rename-uniquely") + ("T" ibuffer-do-toggle-read-only "toggle-read-only") + ("U" ibuffer-do-replace-regexp "replace-regexp") + ("V" ibuffer-do-revert "revert") + ("W" ibuffer-do-view-and-eval "view-and-eval") + ("X" ibuffer-do-shell-command-pipe "shell-command-pipe") + ("b" nil "back")) + + (defhydra hydra-ibuffer-sort (:color amaranth :columns 3) + "Sort" + ("i" ibuffer-invert-sorting "invert") + ("a" ibuffer-do-sort-by-alphabetic "alphabetic") + ("v" ibuffer-do-sort-by-recency "recently used") + ("s" ibuffer-do-sort-by-size "size") + ("f" ibuffer-do-sort-by-filename/process "filename") + ("m" ibuffer-do-sort-by-major-mode "mode") + ("b" hydra-ibuffer-main/body "back" :color blue)) + + (defhydra hydra-ibuffer-filter (:color amaranth :columns 4) + "Filter" + ("m" ibuffer-filter-by-used-mode "mode") + ("M" ibuffer-filter-by-derived-mode "derived mode") + ("n" ibuffer-filter-by-name "name") + ("c" ibuffer-filter-by-content "content") + ("e" ibuffer-filter-by-predicate "predicate") + ("f" ibuffer-filter-by-filename "filename") + (">" ibuffer-filter-by-size-gt "size") + ("<" ibuffer-filter-by-size-lt "size") + ("/" ibuffer-filter-disable "disable") + ("b" hydra-ibuffer-main/body "back" :color blue)) + :general + ((normal motion visual insert emacs) ibuffer-mode-map "." 'hydra-ibuffer-main/body)) + +#+END_SRC + * Speedbar Speedbar is cool but having it open in a separate frame is annoying. This makes it open in a side window in the same frame: #+BEGIN_SRC emacs-lisp @@ -1248,6 +1417,91 @@ And a global keybinding to open an org file: (leader-def-key "fo" #'find-org-file) #+END_SRC +Finally, add a helpful agenda-mode hydra: +#+BEGIN_SRC emacs-lisp + (with-eval-after-load 'org-agenda + (defhydra hydra-org-agenda (:pre (setq which-key-inhibit t) + :post (setq which-key-inhibit nil) + :hint none) + " + Org agenda (_q_uit) + + ^Clock^ ^Visit entry^ ^Date^ ^Other^ + ^-----^---- ^-----------^------------ ^----^----------- ^-----^--------- + _ci_ in _SPC_ in other window _ds_ schedule _gr_ reload + _co_ out _TAB_ & go to location _dd_ set deadline _._ go to today + _cq_ cancel _RET_ & del other windows _dt_ timestamp _gd_ go to date + _cj_ jump _o_ link _+_ do later ^^ + ^^ ^^ _-_ do earlier ^^ + ^^ ^^ ^^ ^^ + ^View^ ^Filter^ ^Headline^ ^Toggle mode^ + ^----^-------- ^------^--------------- ^--------^------- ^-----------^---- + _vd_ day _ft_ by tag _ht_ set status _tf_ follow + _vw_ week _fr_ refine by tag _hk_ kill _tl_ log + _vt_ fortnight _fc_ by category _hr_ refile _ta_ archive trees + _vm_ month _fh_ by top headline _hA_ archive _tA_ archive files + _vy_ year _fx_ by regexp _h:_ set tags _tr_ clock report + _vn_ next span _fd_ delete all filters _hp_ set priority _td_ diaries + _vp_ prev span ^^ ^^ ^^ + _vr_ reset ^^ ^^ ^^ + ^^ ^^ ^^ ^^ + " + ;; Entry + ("hA" org-agenda-archive-default) + ("hk" org-agenda-kill) + ("hp" org-agenda-priority) + ("hr" org-agenda-refile) + ("h:" org-agenda-set-tags) + ("ht" org-agenda-todo) + ;; Visit entry + ("o" link-hint-open-link :exit t) + ("" org-agenda-goto :exit t) + ("TAB" org-agenda-goto :exit t) + ("SPC" org-agenda-show-and-scroll-up) + ("RET" org-agenda-switch-to :exit t) + ;; Date + ("dt" org-agenda-date-prompt) + ("dd" org-agenda-deadline) + ("+" org-agenda-do-date-later) + ("-" org-agenda-do-date-earlier) + ("ds" org-agenda-schedule) + ;; View + ("vd" org-agenda-day-view) + ("vw" org-agenda-week-view) + ("vt" org-agenda-fortnight-view) + ("vm" org-agenda-month-view) + ("vy" org-agenda-year-view) + ("vn" org-agenda-later) + ("vp" org-agenda-earlier) + ("vr" org-agenda-reset-view) + ;; Toggle mode + ("ta" org-agenda-archives-mode) + ("tA" (org-agenda-archives-mode 'files)) + ("tr" org-agenda-clockreport-mode) + ("tf" org-agenda-follow-mode) + ("tl" org-agenda-log-mode) + ("td" org-agenda-toggle-diary) + ;; Filter + ("fc" org-agenda-filter-by-category) + ("fx" org-agenda-filter-by-regexp) + ("ft" org-agenda-filter-by-tag) + ("fr" org-agenda-filter-by-tag-refine) + ("fh" org-agenda-filter-by-top-headline) + ("fd" org-agenda-filter-remove-all) + ;; Clock + ("cq" org-agenda-clock-cancel) + ("cj" org-agenda-clock-goto :exit t) + ("ci" org-agenda-clock-in :exit t) + ("co" org-agenda-clock-out) + ;; Other + ("q" nil :exit t) + ("gd" org-agenda-goto-date) + ("." org-agenda-goto-today) + ("gr" org-agenda-redo)) + (general-def '(normal visual motion insert emacs) org-agenda-mode-map "." 'hydra-org-agenda/body)) +#+END_SRC + + ** Exporting *** HTML Export to HTML: @@ -1414,13 +1668,52 @@ Integrate Google calendar with org-mode: :commands (projectile-find-file projectile-grep projectile-switch-project - projectile-project-root) + projectile-project-root) + :init + (defhydra hydra-projectile (:color teal + :hint nil) + " + PROJECTILE: %(projectile-project-root) + + Find File Search/Tags Buffers Cache + ------------------------------------------------------------------------------------------ + _s-f_: file _a_: ag _i_: Ibuffer _c_: cache clear + _ff_: file dwim _g_: update gtags _b_: switch to buffer _x_: remove known project + _fd_: file curr dir _o_: multi-occur _s-k_: Kill all buffers _X_: cleanup non-existing + _r_: recent file ^^^^_z_: cache current + _d_: dir + + " + ("a" projectile-ag) + ("b" projectile-switch-to-buffer) + ("c" projectile-invalidate-cache) + ("d" projectile-find-dir) + ("s-f" projectile-find-file) + ("ff" projectile-find-file-dwim) + ("fd" projectile-find-file-in-directory) + ("g" ggtags-update-tags) + ("s-g" ggtags-update-tags) + ("i" projectile-ibuffer) + ("K" projectile-kill-buffers) + ("s-k" projectile-kill-buffers) + ("m" projectile-multi-occur) + ("o" projectile-multi-occur) + ("s-p" projectile-switch-project "switch project") + ("p" projectile-switch-project) + ("s" projectile-switch-project) + ("r" projectile-recentf) + ("x" projectile-remove-known-project) + ("X" projectile-cleanup-known-projects) + ("z" projectile-cache-current-file) + ("`" hydra-projectile-other-window/body "other window") + ("q" nil "cancel" :color blue)) :config (projectile-mode) (jdormit/define-prefix "p" "projectile") (leader-def-key "pf" #'projectile-find-file) (leader-def-key "pg" #'projectile-grep) - (leader-def-key "pp" #'projectile-switch-project)) + (leader-def-key "pp" #'projectile-switch-project) + (leader-def-key "ph" 'hydra-projectile/body)) #+END_SRC * Mode line @@ -1597,9 +1890,23 @@ Some aliases: Syntax checking etc.: #+BEGIN_SRC emacs-lisp (use-package flycheck + :init + (defhydra hydra-flycheck + (:pre (flycheck-list-errors) + :post (quit-windows-on "*Flycheck errors*") + :hint nil) + "Errors" + ("f" flycheck-error-list-set-filter "Filter") + ("j" flycheck-next-error "Next") + ("k" flycheck-previous-error "Previous") + ("gg" flycheck-first-error "First") + ("G" (progn (goto-char (point-max)) (flycheck-previous-error)) "Last") + ("q" nil)) :config (setq-default flycheck-disabled-checkers '(emacs-lisp emacs-lisp-checkdoc)) - (global-flycheck-mode)) + (global-flycheck-mode) + :general + ((normal motion visual) flycheck-mode-map "ze" 'hydra-flycheck/body)) #+END_SRC * JSON @@ -1682,6 +1989,32 @@ Emacs support for the Language Server Protocol #+BEGIN_SRC emacs-lisp (use-package lsp-mode + :init + (defhydra hydra-lsp (:exit t :hint nil) + " + Buffer^^ Server^^ Symbol + ------------------------------------------------------------------------------------- + [_f_] format [_M-r_] restart [_d_] declaration [_i_] implementation [_o_] documentation + [_m_] imenu [_S_] shutdown [_D_] definition [_t_] type [_r_] rename + [_x_] execute action [_M-s_] describe session [_R_] references [_s_] signature" + ("d" lsp-find-declaration) + ("D" lsp-ui-peek-find-definitions) + ("R" lsp-ui-peek-find-references) + ("i" lsp-ui-peek-find-implementation) + ("t" lsp-find-type-definition) + ("s" lsp-signature-help) + ("o" lsp-describe-thing-at-point) + ("r" lsp-rename) + + ("f" lsp-format-buffer) + ("m" lsp-ui-imenu) + ("x" lsp-execute-code-action) + + ("M-s" lsp-describe-session) + ("M-r" lsp-restart-workspace) + ("S" lsp-shutdown-workspace)) + :general + (lsp-mode-map "C-c h" 'hydra-lsp/body) :config (setq lsp-prefer-flymake nil) :commands lsp-mode) @@ -2218,10 +2551,60 @@ This mode requires that [[https://github.com/ledger/ledger][ledger]] be installe #+BEGIN_SRC emacs-lisp (use-package pdf-tools :mode ("\\.pdf\\'" . pdf-view-mode) + :init + (defhydra hydra-pdftools (:color blue :hint nil) + " + ╭───────────┐ + Move History Scale/Fit Annotations Search/Link Do │ PDF Tools │ + ╭──────────────────────────────────────────────────────────────────┴───────────╯ + ^^_g_^^ _B_ ^↧^ _+_ ^ ^ [_al_] list [_s_] search [_u_] revert buffer + ^^^↑^^^ ^↑^ _H_ ^↑^ ↦ _W_ ↤ [_am_] markup [_o_] outline [_i_] info + ^^_p_^^ ^ ^ ^↥^ _0_ ^ ^ [_at_] text [_F_] link [_d_] dark mode + ^^^↑^^^ ^↓^ ╭─^─^─┐ ^↓^ ╭─^ ^─┐ [_ad_] delete [_f_] search link + _h_ ←pag_e_→ _l_ _N_ │ _P_ │ _-_ _b_ [_aa_] dired + ^^^↓^^^ ^ ^ ╰─^─^─╯ ^ ^ ╰─^ ^─╯ [_y_] yank + ^^_n_^^ ^ ^ _r_eset slice box + ^^^↓^^^ + ^^_G_^^ + -------------------------------------------------------------------------------- + " + ("\\" hydra-master/body "back") + ("" nil "quit") + ("al" pdf-annot-list-annotations) + ("ad" pdf-annot-delete) + ("aa" pdf-annot-attachment-dired) + ("am" pdf-annot-add-markup-annotation) + ("at" pdf-annot-add-text-annotation) + ("y" pdf-view-kill-ring-save) + ("+" pdf-view-enlarge :color red) + ("-" pdf-view-shrink :color red) + ("0" pdf-view-scale-reset) + ("H" pdf-view-fit-height-to-window) + ("W" pdf-view-fit-width-to-window) + ("P" pdf-view-fit-page-to-window) + ("n" pdf-view-next-page-command :color red) + ("p" pdf-view-previous-page-command :color red) + ("d" pdf-view-dark-minor-mode) + ("b" pdf-view-set-slice-from-bounding-box) + ("r" pdf-view-reset-slice) + ("g" pdf-view-first-page) + ("G" pdf-view-last-page) + ("e" pdf-view-goto-page) + ("o" pdf-outline) + ("s" pdf-occur) + ("i" pdf-misc-display-metadata) + ("u" pdf-view-revert-buffer) + ("F" pdf-links-action-perfom) + ("f" pdf-links-isearch-link) + ("B" pdf-history-backward :color red) + ("N" pdf-history-forward :color red) + ("l" image-forward-hscroll :color red) + ("h" image-backward-hscroll :color red)) :config (pdf-tools-install) :general - (pdf-view-mode-map "SPC" leader-map)) + (pdf-view-mode-map "SPC" leader-map) + ((normal motion visual) pdf-view-mode-map "." 'hydra-pdftools/body)) #+END_SRC * EPubs @@ -3059,15 +3442,66 @@ Or Gnus can read RSS feeds directly: #+END_SRC * Dired -Enable [[info:dired-x#Top][Dired-X]]: - +Set up a hydra for dired and enable [[info:dired-x#Top][Dired-X]]: #+BEGIN_SRC emacs-lisp - (require 'dired-x) -#+END_SRC + (use-package dired + :straight (:type built-in) + :init + (defhydra hydra-dired (:hint nil :color pink) + " + _+_ mkdir _v_iew _m_ark _(_ details _i_nsert-subdir wdired + _C_opy _O_ view other _U_nmark all _)_ omit-mode _$_ hide-subdir C-x C-q : edit + _D_elete _o_pen other _u_nmark _l_ redisplay _w_ kill-subdir C-c C-c : commit + _R_ename _M_ chmod _t_oggle _g_ revert buf _e_ ediff C-c ESC : abort + _Y_ rel symlink _G_ chgrp _E_xtension mark _s_ort _=_ pdiff + _S_ymlink ^ ^ _F_ind marked _._ toggle hydra \\ flyspell + _r_sync ^ ^ ^ ^ ^ ^ _?_ summary + _z_ compress-file _A_ find regexp + _Z_ compress _Q_ repl regexp -Preserve the leader key: -#+BEGIN_SRC emacs-lisp - (general-def dired-mode-map "SPC" leader-map) + T - tag prefix + " + ("\\" dired-do-ispell) + ("(" dired-hide-details-mode) + (")" dired-omit-mode) + ("+" dired-create-directory) + ("=" diredp-ediff) ;; smart diff + ("?" dired-summary) + ("$" diredp-hide-subdir-nomove) + ("A" dired-do-find-regexp) + ("C" dired-do-copy) ;; Copy all marked files + ("D" dired-do-delete) + ("E" dired-mark-extension) + ("e" dired-ediff-files) + ("F" dired-do-find-marked-files) + ("G" dired-do-chgrp) + ("g" revert-buffer) ;; read all directories again (refresh) + ("i" dired-maybe-insert-subdir) + ("l" dired-do-redisplay) ;; relist the marked or singel directory + ("M" dired-do-chmod) + ("m" dired-mark) + ("O" dired-display-file) + ("o" dired-find-file-other-window) + ("Q" dired-do-find-regexp-and-replace) + ("R" dired-do-rename) + ("r" dired-do-rsynch) + ("S" dired-do-symlink) + ("s" dired-sort-toggle-or-edit) + ("t" dired-toggle-marks) + ("U" dired-unmark-all-marks) + ("u" dired-unmark) + ("v" dired-view-file) ;; q to exit, s to search, = gets line # + ("w" dired-kill-subdir) + ("Y" dired-do-relsymlink) + ("z" diredp-compress-this-file) + ("Z" dired-do-compress) + ("q" nil) + ("." nil :color blue)) + :config + (require 'dired-x) + :general + ((normal visual motion insert emacs) dired-mode-map "." 'hydra-dired/body) + (dired-mode-map "SPC" leader-map)) #+END_SRC * Crontab