diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2020-08-12 17:47:06 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2020-08-12 17:47:06 -0700 |
commit | 92273fd7f9fc83f943117e0e044c22aa433e6447 (patch) | |
tree | 5ee27a2cf7095dd1b26277c89c1b045408445a04 | |
parent | bf05c4eb673fa6dff7ec4b5b7afeb2e46d4834dd (diff) | |
download | dotfiles-92273fd7f9fc83f943117e0e044c22aa433e6447.tar.gz |
make C-x t o work like C-x o
-rw-r--r-- | .emacs.d/init-spw.el | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/.emacs.d/init-spw.el b/.emacs.d/init-spw.el index 4a614a4f..86c16a2d 100644 --- a/.emacs.d/init-spw.el +++ b/.emacs.d/init-spw.el @@ -723,6 +723,44 @@ add places the library might be available to `load-path'." (setq tab-bar-show 1 tab-bar-new-button-show nil tab-bar-close-button-show nil) +;; this makes C-x t o like my (customised) C-x o +(let (recent-tab-old-time) + (defun spw/tab-bar-switch-to-recent-tab () + (interactive) + ;; If the most recent tab is not the one we end up at after exiting the + ;; transient map, we will want to set that tab's time back to what it was + ;; before we changed tabs, as if we had never selected it. So record that + ;; info so we can do that. + (setq recent-tab-old-time + (apply #'min + (mapcar (lambda (tab) (alist-get 'time tab)) + (cl-remove-if (lambda (tab) + (eq (car tab) 'current-tab)) + (funcall tab-bar-tabs-function))))) + (call-interactively #'tab-bar-switch-to-recent-tab)) + (spw/bind-command-with-cycling + ([remap tab-next] . spw/tab-bar-switch-to-recent-tab) + (lambda (count) + (interactive "p") + ;; We are moving away from the current tab, so restore its time as if we + ;; had never selected it, and store the time of the tab we're moving to + ;; in case we need to do that a second time. + (let ((next-tab-old-time + (let* ((tabs (funcall tab-bar-tabs-function)) + (current-index (seq-position (mapcar #'car tabs) + 'current-tab)) + (new-index (mod (+ current-index count) + (length tabs)))) + (alist-get 'time (nth new-index tabs))))) + (tab-bar-switch-to-next-tab count) + (setf (alist-get + 'time + (car (seq-sort-by (lambda (tab) (alist-get 'time tab)) #'> + (seq-remove (lambda (tab) + (eq (car tab) 'current-tab)) + (funcall tab-bar-tabs-function))))) + recent-tab-old-time) + (setq recent-tab-old-time next-tab-old-time))))) ;;;; TRAMP |