James Thomas writes:

> Sacha Chua <> writes:
>
>>  * Surprisingly, Emacs on
>>  Android is pretty good |
>>  Kristoffer Balintona
>
> I'd been dying to share this hack (and this is excuse enough):
>
> ...
>

And here's an (arguably) better buffer-switcher:

--8<---------------cut here---------------start------------->8---
(defun my/mode-line-other-buffer nil
  "Keep tapping mode-line buffer name to switch to a recent buffer. Only
the final one is recorded."
  (interactive)
  (unless (bound-and-true-p my/mode-line-other-buffer)
    ;; First time.
    (setq
     my/mode-line-other-buffer
     (cdr
      (seq-remove
       (apply-partially 'string-prefix-p " ")
       (mapcar 'buffer-name (buffer-list)))))
    (add-hook 'pre-command-hook 'my/mode-line-other-buffer-hook)
    (advice-add 'select-window :filter-args 'my/mode-line-other-buffer-advice))
  (switch-to-buffer (pop my/mode-line-other-buffer) t))

(defun my/mode-line-other-buffer-advice (args)
  ;; Which is not caught in pre-command-hook.
  (if
      (not this-command)
      (prog1
          (cons (car args) (list t)))
    args))

(defun my/mode-line-other-buffer-hook nil
  (unless (eq this-command 'my/mode-line-other-buffer)
  (remove-hook 'pre-command-hook 'my/mode-line-other-buffer-hook)
  (advice-remove 'select-window 'my/mode-line-other-buffer-advice)
  (setq my/mode-line-other-buffer nil)))

(keymap-set mode-line-buffer-identification-keymap "<mode-line> <down-mouse-1>" 
nil)
(global-set-key [mode-line down-mouse-1] nil)

(keymap-set mode-line-buffer-identification-keymap "<mode-line> <mouse-1>" 
#'my/mode-line-other-buffer)
--8<---------------cut here---------------end--------------->8---

...for those who might be interested (and if there might be a simpler
way, I'm all ears)

--

---
via emacs-tangents mailing list 
(https://lists.gnu.org/mailman/listinfo/emacs-tangents)
  • ... James Thomas via Emacs news and miscellaneous discussions outside the scope of other Emacs mailing lists
    • ... James Thomas via Emacs news and miscellaneous discussions outside the scope of other Emacs mailing lists

Reply via email to