* find buffer by regexp, then iterate (very cool)
@ 2016-06-30 13:45 Emanuel Berg
0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2016-06-30 13:45 UTC (permalink / raw)
To: help-gnu-emacs
(require 'cl-lib)
(defun buffer-names ()
"Get a list of all `buffer-name's."
(mapcar #'buffer-name (buffer-list)) )
(defun switch-to-buffer-regexp (buffer-regexp &optional ori-buffer)
(let*((original-buffer (or ori-buffer (current-buffer)))
(hit (cl-find-if
(lambda (b) (string-match buffer-regexp b))
(buffer-names) ))
(hit-buffer (when hit (get-buffer hit)))
(same-buffer (when hit-buffer (eq original-buffer hit-buffer))) )
(if hit-buffer
(if same-buffer
(if ori-buffer
(progn
(message "(This buffer is the only hit!)")
(switch-to-buffer ori-buffer) )
(progn
(bury-buffer)
(switch-to-buffer-regexp buffer-regexp original-buffer) ))
(switch-to-buffer hit-buffer) )
(error "No hit: %s" buffer-regexp) )))
;; Try these -
;; (global-set-key "\C-ca" (lambda () (interactive) (switch-to-buffer-regexp "\*Article\*")))
;; (global-set-key "\C-ch" (lambda () (interactive) (switch-to-buffer-regexp "\*Help\*")))
;; (global-set-key "\C-cc" (lambda () (interactive) (switch-to-buffer-regexp "\*compilation\*")))
;; - and this, the most interesting case:
;; create four posts, go to a post, then hit
;; again to iterate!
;; (require 'gnus)
;; (dotimes (i 4) (gnus-post-news 'post "")) ;; create 4 posts
;; (global-set-key "\C-cu" (lambda () (interactive) (switch-to-buffer-regexp "\*unsent posting\*.*")))
(provide 'switch-to-buffer-regexp)
--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 55 Blogomatic articles -
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-06-30 13:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-30 13:45 find buffer by regexp, then iterate (very cool) Emanuel Berg
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.