[hydra] add window hydra, rename cp/prog-hydra

This commit is contained in:
contrapunctus 2021-02-17 22:10:54 +05:30
parent 487c829e89
commit 48cc0bc0fe
3 changed files with 49 additions and 30 deletions

View File

@ -138,7 +138,6 @@
("p" org-set-property "property" :color blue)
("b" cp-org-src/body "source block" :color blue)
("t" cp-org-set-tags "tags" :color blue)
("e" (literate-elisp-load-file (buffer-file-name)) "eval buffer" :color blue)
("i" org-previous-visible-heading "previous heading")
("o" org-next-visible-heading "next heading")
@ -154,7 +153,7 @@
("s" save-buffer "save" :color blue)
("m" magit-status "Magit" :color blue)
("u" contrapunctus-general/body "up" :color blue)
("u" contrapunctus-general-hydra/body "up" :color blue)
("G" elpher "Elpher" :color blue))
;; (use-package org-src-mode

37
init.el
View File

@ -425,14 +425,22 @@ Return nil (and run `magit-status') if the user answers no."
(use-package hydra
:commands defhydra)
(defhydra contrapunctus-general (:color blue)
(defhydra contrapunctus-window-hydra (:color blue)
"Window"
("d" delete-window "delete")
("s" delete-other-windows "single")
("e" split-window-below "split below")
("r" split-window-right "split right"))
(defhydra contrapunctus-general-hydra (:color blue)
"What command?"
("c" chronometrist "chronometrist")
("G" elpher "elpher")
("o" cp-org/body "org")
("p" cp/prog-hydra "programming")
("p" contrapunctus-programming-hydra-dispatch-language "programming")
("i" (find-file "~/.emacs.d/init.org") "open init")
("l" launch-file "launch-file")
("w" contrapunctus-window-hydra/body "window")
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
@ -964,7 +972,7 @@ and eval it."
(cd (locate-dominating-file default-directory file))
(compile cmd))
(defhydra cp-prog (:color blue)
(defhydra contrapunctus-programming-hydra (:color blue)
"Which language?"
("e" cp-el/body "Emacs Lisp")
("c" cp-cs/body "CHICKEN Scheme")
@ -974,14 +982,14 @@ and eval it."
("o" cp-org/body "Org")
("p" cp-prolog/body "Prolog")
("u" contrapunctus-general/body "up" :color blue)
("u" contrapunctus-general-hydra/body "up" :color blue)
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
("E" toggle-debug-on-error "tdoe")
("Q" toggle-debug-on-quit "tdoq")
("m" magit-status "Magit"))
(defun cp/prog-hydra ()
(defun contrapunctus-programming-hydra-dispatch-language ()
(interactive)
(cond ((or (derived-mode-p 'emacs-lisp-mode 'ielm-mode)
;; ;; Similar problems with this as the f-glob below;
@ -1005,10 +1013,10 @@ and eval it."
((derived-mode-p 'org-mode)
(cp-org/body))
((derived-mode-p 'prog-mode)
(cp-prog/body))
(t (contrapunctus-general/body))))
(contrapunctus-programming-hydra/body))
(t (contrapunctus-general-hydra/body))))
(define-key boon-command-map (kbd "m") #'cp/prog-hydra)
(define-key boon-command-map (kbd "m") #'contrapunctus-programming-hydra-dispatch-language)
(use-package elisp-mode
:diminish
@ -1061,7 +1069,8 @@ and eval it."
("C" (cp/compile-project "Cask" "cask clean-elc") "clean")
("t" (cp/compile-project "Cask" "cask exec buttercup -L . --traceback pretty") "Test")
("u" cp-prog/body "up" :color blue)
("w" contrapunctus-window-hydra/body "window")
("u" contrapunctus-programming-hydra/body "up")
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
("E" toggle-debug-on-error "tdoe")
@ -1083,7 +1092,7 @@ and eval it."
("e" cp-cl-eval/body "Eval")
("r" slime "REPL")
("u" cp-prog/body "up" :color blue)
("u" contrapunctus-programming-hydra/body "up" :color blue)
("s" save-buffer "save")
("m" magit-status "Magit"))
@ -1096,7 +1105,7 @@ and eval it."
("e" cp-scm-eval/body "Eval")
("r" run-chicken "REPL")
("m" magit-status "Magit")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
(defhydra cp-guile (:color blue)
"Guile"
@ -1104,20 +1113,20 @@ and eval it."
("r" run-guile "REPL")
("m" magit-status "Magit")
("G" elpher "Elpher")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
(defhydra cp-ly (:color blue)
"Lilypond"
("c" (cp/compile-project "main.ly" "~/bin/mkly dev") "Compile")
("m" magit-status "Magit")
("G" elpher "Elpher")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
(use-package ediprolog
:commands ediprolog-dwim)
(defhydra cp-prolog (:color blue)
"Prolog"
("u" cp-prog/body "up" :color blue)
("u" contrapunctus-programming-hydra/body "up")
("r" ediprolog-dwim "REPL"))
(use-package cc-mode)

View File

@ -570,6 +570,8 @@ Return nil (and run `magit-status') if the user answers no."
#+END_SRC
** TODO hydra [50%]
I started off using Hydra for programming modes, when I noticed that Elisp, Common Lisp, and Scheme all had some semantically-analogous operations with different names, which could be abstracted away behind a generic interface. Then, around the time I got into using Org for literate programs, I added an Org hydra, and then a general hydra for frequently-used operations.
Add these common operations to the hydra -
1. [ ] =enlarge-window=, =enlarge-window-horizontally=
2. [X] =save-buffer=, =kill-buffer=
@ -579,14 +581,22 @@ Add these common operations to the hydra -
(use-package hydra
:commands defhydra)
(defhydra contrapunctus-general (:color blue)
(defhydra contrapunctus-window-hydra (:color blue)
"Window"
("d" delete-window "delete")
("s" delete-other-windows "single")
("e" split-window-below "split below")
("r" split-window-right "split right"))
(defhydra contrapunctus-general-hydra (:color blue)
"What command?"
("c" chronometrist "chronometrist")
("G" elpher "elpher")
("o" cp-org/body "org")
("p" cp/prog-hydra "programming")
("p" contrapunctus-programming-hydra-dispatch-language "programming")
("i" (find-file "~/.emacs.d/init.org") "open init")
("l" launch-file "launch-file")
("w" contrapunctus-window-hydra/body "window")
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
@ -1295,7 +1305,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
(cd (locate-dominating-file default-directory file))
(compile cmd))
(defhydra cp-prog (:color blue)
(defhydra contrapunctus-programming-hydra (:color blue)
"Which language?"
("e" cp-el/body "Emacs Lisp")
("c" cp-cs/body "CHICKEN Scheme")
@ -1305,14 +1315,14 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("o" cp-org/body "Org")
("p" cp-prolog/body "Prolog")
("u" contrapunctus-general/body "up" :color blue)
("u" contrapunctus-general-hydra/body "up" :color blue)
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
("E" toggle-debug-on-error "tdoe")
("Q" toggle-debug-on-quit "tdoq")
("m" magit-status "Magit"))
(defun cp/prog-hydra ()
(defun contrapunctus-programming-hydra-dispatch-language ()
(interactive)
(cond ((or (derived-mode-p 'emacs-lisp-mode 'ielm-mode)
;; ;; Similar problems with this as the f-glob below;
@ -1336,10 +1346,10 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
((derived-mode-p 'org-mode)
(cp-org/body))
((derived-mode-p 'prog-mode)
(cp-prog/body))
(t (contrapunctus-general/body))))
(contrapunctus-programming-hydra/body))
(t (contrapunctus-general-hydra/body))))
(define-key boon-command-map (kbd "m") #'cp/prog-hydra)
(define-key boon-command-map (kbd "m") #'contrapunctus-programming-hydra-dispatch-language)
#+END_SRC
*** Emacs Lisp
@ -1410,7 +1420,8 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("C" (cp/compile-project "Cask" "cask clean-elc") "clean")
("t" (cp/compile-project "Cask" "cask exec buttercup -L . --traceback pretty") "Test")
("u" cp-prog/body "up" :color blue)
("w" contrapunctus-window-hydra/body "window")
("u" contrapunctus-programming-hydra/body "up")
("s" save-buffer "save")
("k" (kill-buffer (current-buffer)) "kill")
("E" toggle-debug-on-error "tdoe")
@ -1435,7 +1446,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("e" cp-cl-eval/body "Eval")
("r" slime "REPL")
("u" cp-prog/body "up" :color blue)
("u" contrapunctus-programming-hydra/body "up" :color blue)
("s" save-buffer "save")
("m" magit-status "Magit"))
@ -1455,7 +1466,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("e" cp-scm-eval/body "Eval")
("r" run-chicken "REPL")
("m" magit-status "Magit")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
#+END_SRC
**** Guile
@ -1466,7 +1477,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("r" run-guile "REPL")
("m" magit-status "Magit")
("G" elpher "Elpher")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
#+END_SRC
*** Lilypond
#+BEGIN_SRC emacs-lisp
@ -1475,7 +1486,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
("c" (cp/compile-project "main.ly" "~/bin/mkly dev") "Compile")
("m" magit-status "Magit")
("G" elpher "Elpher")
("u" cp-prog/body "up" :color blue))
("u" contrapunctus-programming-hydra/body "up"))
#+END_SRC
*** Prolog
@ -1485,7 +1496,7 @@ It'd be really cool to (recenter 3) when you /open/ a section, and (recenter) wh
(defhydra cp-prolog (:color blue)
"Prolog"
("u" cp-prog/body "up" :color blue)
("u" contrapunctus-programming-hydra/body "up")
("r" ediprolog-dwim "REPL"))
#+END_SRC