Skip to content

Instantly share code, notes, and snippets.

@mjkramer
Created October 11, 2018 01:32
Show Gist options
  • Save mjkramer/b69f067fed503e4694b16168aab74547 to your computer and use it in GitHub Desktop.
Save mjkramer/b69f067fed503e4694b16168aab74547 to your computer and use it in GitHub Desktop.
(defun mjk/buffer-flippy ()
(interactive)
(let ((now (cadr (current-time)))
(then (or (bound-and-true-p mjk//last-flippy-time) 0))
(prev-counter (or (bound-and-true-p mjk//flippy-counter) 0)))
(setq mjk//last-flippy-time now
mjk//flippy-counter (+ 1 prev-counter))
(if (> (- now then) 2)
(setq mjk//flippy-counter 1))
(if (<= mjk//flippy-counter 2)
; replace with `other-buffer' if you don't want window-local history?
(spacemacs/alternate-buffer)
(previous-buffer))))
(defun spacemacs/alternate-buffer (&optional window)
"Switch back and forth between current and last buffer in the
current window."
(interactive)
(let ((current-buffer (window-buffer window)))
;; if no window is found in the windows history, `switch-to-buffer' will
;; default to calling `other-buffer'.
(switch-to-buffer
(cl-find-if (lambda (buffer)
(not (eq buffer current-buffer)))
(mapcar #'car (window-prev-buffers window))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment