-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrigpa-tab-mode.el
145 lines (125 loc) · 5 KB
/
rigpa-tab-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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;;; rigpa-tab-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 tabs
;;
;;; Code:
(require 'evil)
(require 'hydra)
(require 'chimera)
(require 'chimera-hydra)
(require 'centaur-tabs)
(evil-define-state tab
"Tab state."
:tag " <T> "
:message "-- TAB --"
:enable (normal))
(defun rigpa-tab-setup-marks-table ()
"Initialize the tab marks hashtable and add an entry for the
current ('original') tab."
(interactive)
(defvar rigpa-tab-marks-hash
(make-hash-table :test 'equal))
(rigpa-tab-save 'original))
(defun rigpa-tab-save (key)
"Save current tab as original tab."
(interactive)
(puthash key (current-buffer)
rigpa-tab-marks-hash))
(defun rigpa-tab-load (key)
"Return to the buffer we were in at the time of entering
buffer mode."
(interactive)
(switch-to-buffer
(gethash key rigpa-tab-marks-hash)))
(defun rigpa-tab-flash-to-original ()
"Go momentarily to original tab and return.
This 'flash' allows the original tab, rather than the previous one
encountered while navigating to the present one, to be treated as the
last tab for 'flashback' ('Alt-tab') purposes. The flash should
happen quickly enough not to be noticeable."
(interactive)
(unless (equal (current-buffer) (rigpa-tab-original))
(let ((inhibit-redisplay t)) ;; not sure if this is doing anything but FWIW
(rigpa-tab-load 'original)
(rigpa-tab-save 'previous)
(evil-switch-to-windows-last-buffer))))
(defun rigpa-tab-original ()
"Get original tab identifier"
(interactive)
(gethash 'original rigpa-tab-marks-hash))
(defun rigpa-tab-return-to-original ()
"Return to the tab we were in at the time of entering
buffer mode."
(interactive)
(rigpa-tab-load 'original))
(defun rigpa-tab-switch-to-last ()
(interactive)
(rigpa-tab-save 'temp-previous)
(rigpa-tab-load 'previous)
(puthash 'previous (gethash 'temp-previous rigpa-tab-marks-hash)
rigpa-tab-marks-hash))
(defhydra hydra-tab (:columns 2
:body-pre (progn (rigpa-tab-setup-marks-table) ; maybe put in ad-hoc entry function
(chimera-hydra-signal-entry chimera-tab-mode))
:post (progn (rigpa-tab-flash-to-original)
(chimera-hydra-portend-exit chimera-tab-mode t))
:after-exit (chimera-hydra-signal-exit chimera-tab-mode
#'chimera-handle-hydra-exit))
"Tab mode"
("/" centaur-tabs-counsel-switch-group "search" :exit t)
("h" centaur-tabs-backward "previous")
("s-{" centaur-tabs-backward "previous") ; to "take over" from the global binding
("l" centaur-tabs-forward "next")
("s-}" centaur-tabs-forward "next") ; to "take over" from the global binding
("k" (lambda ()
(interactive)
(centaur-tabs-backward-group))
"previous group")
("j" (lambda ()
(interactive)
(centaur-tabs-forward-group)) "next group")
("H" centaur-tabs-move-current-tab-to-left "move left")
("L" centaur-tabs-move-current-tab-to-right "move right")
("s-t" rigpa-tab-switch-to-last "switch to last" :exit t)
("t" rigpa-tab-switch-to-last "switch to last" :exit t)
("n" (lambda ()
(interactive)
(rigpa-buffer-create nil nil :switch-p t))
"new" :exit t)
("x" kill-buffer "delete")
("?" rigpa-buffer-info "info" :exit t)
("q" rigpa-tab-return-to-original "return to original" :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-tab-mode-entry-hook nil
"Entry hook for rigpa tab mode.")
(defvar chimera-tab-mode-exit-hook nil
"Exit hook for rigpa tab mode.")
(defvar chimera-tab-mode
(make-chimera-mode :name "tab"
:enter #'hydra-tab/body
:pre-entry-hook 'chimera-tab-mode-entry-hook
:post-exit-hook 'chimera-tab-mode-exit-hook
:entry-hook 'evil-tab-state-entry-hook
:exit-hook 'evil-tab-state-exit-hook))
(provide 'rigpa-tab-mode)
;;; rigpa-tab-mode.el ends here