about summary refs log tree commit diff
path: root/users/tazjin
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-02-07T18·55+0300
committertazjin <tazjin@tvl.su>2022-02-07T19·08+0000
commitd522e75554bb6b3f123d53986b33a359c5ce7683 (patch)
tree61a7c33d39f8860cb9933dd90b3b899953b0f227 /users/tazjin
parente00dd88b666b686add1f9bc2d09c2b18b70d88cc (diff)
feat(tazjin/emacs): emulate i3's "jump back-and-forth" feature r/3780
this feature makes it so that if you jump to a workspace by index, and
then ask to jump that same index again, you end up where you started.

this is useful for quickly jumping to something to look at it, and
then back.

Change-Id: I12f5bba88c0d5b3ae5956d2b6a606f49146551f7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/5244
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin')
-rw-r--r--users/tazjin/emacs/config/desktop.el21
1 files changed, 19 insertions, 2 deletions
diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el
index f9ed77f63b6b..84decd493dd3 100644
--- a/users/tazjin/emacs/config/desktop.el
+++ b/users/tazjin/emacs/config/desktop.el
@@ -132,13 +132,30 @@
 (fringe-mode 3)
 (exwm-enable)
 
-;; 's-N': Switch to certain workspace
+;; Create 10 EXWM workspaces
 (setq exwm-workspace-number 10)
+
+;; 's-N': Switch to certain workspace, but switch back to the previous
+;; one when tapping twice (emulates i3's `back_and_forth' feature)
+(defvar *exwm-workspace-from-to* '(-1 . -1))
+(defun exwm-workspace-switch-back-and-forth (target-idx)
+  ;; If the current workspace is the one we last jumped to, and we are
+  ;; asked to jump to it again, set the target back to the previous
+  ;; one.
+  (when (and (eq exwm-workspace-current-index (cdr *exwm-workspace-from-to*))
+             (eq target-idx exwm-workspace-current-index))
+    (setq target-idx (car *exwm-workspace-from-to*)))
+
+  (setq *exwm-workspace-from-to*
+        (cons exwm-workspace-current-index target-idx))
+
+  (exwm-workspace-switch-create target-idx))
+
 (dotimes (i 10)
   (exwm-input-set-key (kbd (format "s-%d" i))
                       `(lambda ()
                          (interactive)
-                         (exwm-workspace-switch-create ,i))))
+                         (exwm-workspace-switch-back-and-forth ,i))))
 
 ;; Implement MRU functionality for EXWM workspaces, making it possible
 ;; to jump to the previous/next workspace very easily.