-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrigpa-activity-mode.el
130 lines (112 loc) · 5.04 KB
/
rigpa-activity-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
;;; rigpa-activity-mode.el --- Self-reflective editing modes -*- lexical-binding: t -*-
;; URL: https://github.com/countvajhula/rigpa
;; This program is "part of the world," in the sense described at
;; http://drym.org. From your perspective, this is no different than
;; MIT or BSD or other such "liberal" licenses that you may be
;; familiar with, that is to say, you are free to do whatever you like
;; with this program. It is much more than BSD or MIT, however, in
;; that it isn't a license at all but an idea about the world and how
;; economic systems could be set up so that everyone wins. Learn more
;; at drym.org.
;;
;; This work transcends traditional legal and economic systems, but
;; for the purposes of any such systems within which you may need to
;; operate:
;;
;; This is free and unencumbered software released into the public domain.
;; The authors relinquish any copyright claims on this work.
;;
;;; Commentary:
;;
;; A mode to refer to your editing activity
;;
;;; Code:
(require 'evil)
(require 'hydra)
(require 'chimera)
(require 'chimera-hydra)
(evil-define-state activity
"Activity state."
:tag " <A> "
:message "-- ACTIVITY --"
:enable (normal))
(setq rigpa-activity-accumulate-buffer-name "MY-CLIPBOARD")
(defun rigpa-activity-yank-and-accumulate ()
"'Yank'/accumulate text in a temporary buffer."
(interactive)
(unless (get-buffer rigpa-activity-accumulate-buffer-name)
(rigpa-buffer-create rigpa-activity-accumulate-buffer-name))
(with-current-buffer rigpa-activity-accumulate-buffer-name
(goto-char (point-max)))
(append-to-buffer rigpa-activity-accumulate-buffer-name
(if (region-active-p)
(region-beginning)
(line-beginning-position))
(if (region-active-p)
(region-end)
(line-end-position)))
(with-current-buffer rigpa-activity-accumulate-buffer-name
(goto-char (point-max))
(insert "\n"))
(deactivate-mark))
(defun rigpa-activity-paste-and-clear ()
"Paste contents of paste buffer and empty it."
(interactive)
(insert-buffer rigpa-activity-accumulate-buffer-name)
(kill-buffer rigpa-activity-accumulate-buffer-name))
;; TODO: only stop at points that change the buffer location
;; in a "significant" way. either by number of lines, or
;; by whether it's a different top-level definition, or whether
;; there are blank lines between original/current point and
;; the change location. That way, navigating will always be
;; useful and we don't need to move multiple times before
;; there is a useful change.
(defun rigpa-activity-previous ()
"docstring"
(interactive)
(call-interactively 'goto-last-change))
(defun rigpa-activity-next ()
"docstring"
(interactive)
(when (eq last-command 'rigpa-activity-previous)
;; emacs only cycles "forwards" through the change list
;; if the previous command was a "backwards" navigation
;; through this list. Since we're wrapping the internal
;; commands, we need to manually indicate that the last
;; command was equivalent to the internal backwards
;; changelist navigation command
(setq last-command 'goto-last-change))
(call-interactively 'goto-last-change-reverse))
(defhydra hydra-activity (:columns 2
:body-pre (chimera-hydra-signal-entry chimera-activity-mode)
:post (chimera-hydra-portend-exit chimera-activity-mode t)
:after-exit (chimera-hydra-signal-exit chimera-activity-mode
#'chimera-handle-hydra-exit))
"Activity mode"
("h" rigpa-activity-previous "previous change in buffer")
("C-j" evil-jump-backward "jump backward") ;; TODO: these jumps don't work via hydra atm
("C-k" evil-jump-forward "jump forward")
("l" rigpa-activity-next "next change in buffer")
("m" evil-set-marker "set mark")
("g" evil-goto-mark "go to mark")
("y" rigpa-activity-yank-and-accumulate "yank and accumulate") ;; TODO: these don't work via hydra atm
("p" rigpa-activity-paste-and-clear "paste and clear")
("a" rigpa-activity-previous "previous change in buffer" :exit t)
("s-a" rigpa-activity-previous "previous change in buffer" :exit t)
("i" ignore "exit" :exit t)
("H-m" rigpa-toggle-menu "show/hide this menu")
("<return>" rigpa-enter-lower-level "enter lower level" :exit t)
("<escape>" rigpa-enter-higher-level "escape to higher level" :exit t))
(defvar chimera-activity-mode-entry-hook nil
"Entry hook for rigpa activity mode.")
(defvar chimera-activity-mode-exit-hook nil
"Exit hook for rigpa activity mode.")
(defvar chimera-activity-mode
(make-chimera-mode :name "activity"
:enter #'hydra-activity/body
:pre-entry-hook 'chimera-activity-mode-entry-hook
:post-exit-hook 'chimera-activity-mode-exit-hook
:entry-hook 'evil-activity-state-entry-hook
:exit-hook 'evil-activity-state-exit-hook))
(provide 'rigpa-activity-mode)
;;; rigpa-activity-mode.el ends here