Browse Source

hyrda: Start moving hydras to their own directory

master
Peter J. Jones 1 month ago
parent
commit
ceaad10626
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
7 changed files with 107 additions and 37 deletions
  1. 1
    1
      default.nix
  2. 59
    0
      hydras/dired.el
  3. 26
    0
      hydras/haskell-mode.el
  4. 8
    11
      lisp/interactive.el
  5. 2
    0
      lisp/keys.el
  6. 11
    0
      lisp/modes.el
  7. 0
    25
      modes/haskell-mode-conf.el

+ 1
- 1
default.nix View File

@@ -38,7 +38,7 @@ pkgs.stdenv.mkDerivation rec {
38 38
     export emacspath="${emacsAndPackages}/bin"
39 39
 
40 40
     substituteAll ${src}/dot.emacs.el "$out/dot.emacs.el"
41
-    cp -r ${src}/lisp ${src}/modes "$out/emacs.d/"
41
+    cp -r ${src}/lisp ${src}/modes ${src}/hydras "$out/emacs.d/"
42 42
     chmod u+w "$out"/emacs.d/*
43 43
 
44 44
     for f in ${src}/bin/*; do

+ 59
- 0
hydras/dired.el View File

@@ -0,0 +1,59 @@
1
+;;; dired.el --- Hydras for `dired-mode'.
2
+
3
+;;; Commentary:
4
+;;
5
+;; My hydras for dired-mode.
6
+
7
+;;; Code:
8
+(require 'dired)
9
+(require 'dired-aux)
10
+(require 'dired-filter)
11
+(require 'dired-narrow)
12
+(require 'dired-x)
13
+(require 'hydra)
14
+(require 'noccur)
15
+
16
+;; External functions:
17
+(declare-function pjones:dired-mark-all-files "../modes/dired-conf.el")
18
+
19
+(defhydra pjones:hydras:dired-mode (:hint nil) "
20
+ ^Narrowing^        ^Marking^           ^Operations^
21
+-----------------------------------------------------------
22
+  _/ n_: name        _M n_: name         _o_: noccur marked
23
+  _/ r_: regexp      _M r_: regexp       _q_: query replace
24
+  _/ ._: ext         _M ._: ext          _C_: copy
25
+  _/ f_: files       _M f_: files        _d_: delete
26
+  _/ d_: dirs        _M d_: dirs         _R_: rename
27
+  _/ s_: symlinks    _M s_: symlinks     _T_: touch
28
+  _/ m_: mode        _M m_: mode         _S_: symlink
29
+  _/ p_: pop one     _M u_: none         _F_: find
30
+  _/ /_: pop all     _M a_: all
31
+"
32
+  ("/ n" dired-filter-by-name)
33
+  ("/ r" dired-filter-by-regexp)
34
+  ("/ ." dired-filter-by-extension)
35
+  ("/ f" dired-filter-by-file)
36
+  ("/ d" dired-filter-by-directory)
37
+  ("/ s" dired-filter-by-symlink)
38
+  ("/ m" dired-filter-by-mode)
39
+  ("/ p" dired-filter-pop)
40
+  ("/ /" dired-filter-pop-all)
41
+  ("M n" dired-filter-mark-by-name)
42
+  ("M r" dired-filter-mark-by-regexp)
43
+  ("M ." dired-filter-mark-by-extension)
44
+  ("M f" dired-filter-mark-by-file)
45
+  ("M d" dired-filter-mark-by-directory)
46
+  ("M s" dired-filter-mark-by-symlink)
47
+  ("M m" dired-filter-mark-by-mode)
48
+  ("M u" dired-unmark-all-marks)
49
+  ("M a" pjones:dired-mark-all-files)
50
+  ("o" noccur-dired)
51
+  ("q" dired-do-query-replace-regexp)
52
+  ("C" dired-do-copy)
53
+  ("d" dired-flag-file-deletion)
54
+  ("R" dired-do-rename)
55
+  ("T" dired-do-touch)
56
+  ("S" dired-do-relsymlink)
57
+  ("F" find-dired))
58
+
59
+;;; dired.el ends here

+ 26
- 0
hydras/haskell-mode.el View File

@@ -0,0 +1,26 @@
1
+;;; haskell-mode.el ;; Hydras for haskell-mode
2
+
3
+;;; Commentary:
4
+
5
+;;; Code:
6
+(require 'hydra)
7
+
8
+(defhydra pjones:hydras:haskell-mode (:hint nil)
9
+  "
10
+^Imports^          ^GHCi^              ^Insert/Edit^          ^Run
11
+^^^^^^^^^-------------------------------------------------------------------------
12
+_C-c C-i_: jump    _C-c C-;_: info     _C-c C-0_: cost center  _C-c c_: compile
13
+_C-c C-l_: return  _C-c C-r_: reload   _C-c C-n_: kill module
14
+_C-c C-s_: sort    _C-c C-t_: type     _C-c C-e_: edit cabal
15
+"
16
+  ("C-c C-;" dante-info)
17
+  ("C-c C-0" haskell-mode-toggle-scc-at-point :color blue)
18
+  ("C-c C-e" pjones:haskell-edit-cabal-file :color blue)
19
+  ("C-c C-i" haskell-navigate-imports)
20
+  ("C-c C-l" haskell-navigate-imports-return :color blue)
21
+  ("C-c C-n" pjones:haskell-module-name-to-kill-ring :color blue)
22
+  ("C-c C-r" dante-restart)
23
+  ("C-c C-s" pjones:haskell-sort-imports)
24
+  ("C-c C-t" dante-type-at :color blue))
25
+
26
+;;; haskell-mode ends here

+ 8
- 11
lisp/interactive.el View File

@@ -35,17 +35,6 @@ placing it in the kill ring)."
35 35
       (delete-region (point) (progn (funcall forward (- arg))
36 36
                                     (point))))))
37 37
 
38
-(defun pjones:exchange-point-and-mark (&optional arg)
39
-  "Exchange point and mark without changing if the region is active.
40
-
41
-If the region is active, keep it active.  If the region is
42
-inactive, keep it inactive.  When ARG is non-nil, negate this
43
-behavior."
44
-  (interactive "P")
45
-  (exchange-point-and-mark
46
-   (if (region-active-p) arg
47
-     (not arg))))
48
-
49 38
 (defun pjones:switch-to-previous-buffer ()
50 39
   "Switch back to the last buffer shown in this window."
51 40
   (interactive)
@@ -202,6 +191,14 @@ current buffer after point."
202 191
   (let ((switch-window-threshold 1))
203 192
     (switch-window-then-delete)))
204 193
 
194
+(defun pjones:show-hydra-for-mode ()
195
+  "Show a hydra for the current mode."
196
+  (interactive)
197
+  (let ((func (intern (format "pjones:hydras:%s/body" major-mode))))
198
+    (if (fboundp func)
199
+        (call-interactively func)
200
+      (message "no hydra for %s" major-mode))))
201
+
205 202
 ;; Local Variables:
206 203
 ;; byte-compile-warnings: (not noruntime)
207 204
 ;; End:

+ 2
- 0
lisp/keys.el View File

@@ -19,8 +19,10 @@
19 19
 (declare-function pjones:start-mail "./interactive.el")
20 20
 (declare-function pjones:start-term "./interactive.el")
21 21
 (declare-function pjones:switch-window-then-delete "./interactive.el")
22
+(declare-function pjones:show-hydra-for-mode "./interactive.el")
22 23
 
23 24
 ;; Overriding default key bindings
25
+(global-set-key (kbd "<f1>")      #'pjones:show-hydra-for-mode)
24 26
 (global-set-key (kbd "C-h M-m")   #'describe-mode)
25 27
 (global-set-key (kbd "C-r")       #'isearch-backward-regexp)
26 28
 (global-set-key (kbd "C-s")       #'isearch-forward-regexp)

+ 11
- 0
lisp/modes.el View File

@@ -7,6 +7,10 @@
7 7
   (concat (file-name-directory (directory-file-name (file-name-directory load-file-name))) "modes/")
8 8
   "The directory where I keep mode-specific configuration files.")
9 9
 
10
+(defvar pjones:hydras-dir
11
+  (concat (file-name-directory (directory-file-name pjones:modes-dir)) "hydras/")
12
+  "The directory where I keep mode-specific hydras.")
13
+
10 14
 ;; Automatically load my per-mode configuration files
11 15
 (dolist (file (directory-files pjones:modes-dir t))
12 16
   (let ((basename (file-name-nondirectory file)))
@@ -14,6 +18,13 @@
14 18
       (eval-after-load (intern (replace-match "" t t basename))
15 19
         `(load ,file)))))
16 20
 
21
+;; Automatically load my per-mode hydras:
22
+(dolist (file (directory-files pjones:hydras-dir t))
23
+  (let ((basename (file-name-nondirectory file)))
24
+    (when (string-match "\\(\\.elc\\)$" basename)
25
+      (eval-after-load (intern (replace-match "" t t basename))
26
+        `(load ,file)))))
27
+
17 28
 (defun pjones:maybe-start-edit-server ()
18 29
   "Start `edit-server' if this is the main Emacs instance."
19 30
   (if (string= "server" server-name)

+ 0
- 25
modes/haskell-mode-conf.el View File

@@ -151,31 +151,6 @@ Otherwise go totally crazy."
151 151
     (sort-regexp-fields
152 152
        nil "^import +\\(qualified \\)?\\(.+\\)$" "\\2" b e)))
153 153
 
154
-;; TODO:
155
-;; * Remove whitespace at end of line while typing?
156
-;;
157
-;; close frames when using q (think *grep* or *compilation*)
158
-
159
-(defhydra hydra-haskell (:hint nil)
160
-  "
161
-^Imports^          ^GHCi^              ^Insert/Edit^          ^Run
162
-^^^^^^^^^-------------------------------------------------------------------------
163
-_C-c C-i_: jump    _C-c C-;_: info     _C-c C-0_: cost center  _C-c C-c_: compile
164
-_C-c C-l_: return  _C-c C-r_: reload   _C-c C-p_: new module
165
-_C-c C-s_: sort    _C-c C-t_: type     _C-c C-n_: kill module
166
-^ ^                ^ ^                 _C-c C-e_: edit cabal
167
-"
168
-  ("C-c C-;" dante-info)
169
-  ("C-c C-0" haskell-mode-toggle-scc-at-point :color blue)
170
-  ("C-c C-c" pjones:haskell-compile :color blue)
171
-  ("C-c C-e" pjones:haskell-edit-cabal-file :color blue)
172
-  ("C-c C-i" haskell-navigate-imports)
173
-  ("C-c C-l" haskell-navigate-imports-return :color blue)
174
-  ("C-c C-n" pjones:haskell-module-name-to-kill-ring :color blue)
175
-  ("C-c C-p" pjones:haskell-new-module :color blue)
176
-  ("C-c C-r" dante-restart)
177
-  ("C-c C-s" pjones:haskell-sort-imports)
178
-  ("C-c C-t" dante-type-at :color blue))
179 154
 
180 155
 (defun pjones-haskell-process-wrapper-function (argv)
181 156
   "Run Haskell tools through nix-shell by modifying ARGV.

Loading…
Cancel
Save