From d522e75554bb6b3f123d53986b33a359c5ce7683 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 7 Feb 2022 21:55:00 +0300 Subject: feat(tazjin/emacs): emulate i3's "jump back-and-forth" feature 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 Tested-by: BuildkiteCI --- users/tazjin/emacs/config/desktop.el | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el index f9ed77f63b..84decd493d 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. -- cgit 1.4.1