;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/switch-to-buffer-regexp.el (require 'cl-lib) (require 'buc) (defun switch-to-buffer-regexp (buf-re) (let*((ori-buf (buffer-name (current-buffer))) (hits (cl-remove-if-not (lambda (b) (string-match buf-re b)) (buffer-names) ))) (when hits (let ((new-hits (cl-remove ori-buf hits))) (when new-hits (when (string-match buf-re ori-buf) (bury-buffer ori-buf) ) (switch-to-buffer (car new-hits)) ))))) ;; try it! ;; (require 'gnus) ;; (dotimes (i 4) (gnus-post-news 'post "")) ; create 4 posts (keymap-global-set "C-c u" (lambda () (interactive) (switch-to-buffer-regexp "\*unsent posting\*.*"))) ;; hit again to iterate (provide 'switch-to-buffer-regexp)