* switch-to-buffer-regexp.el to iterate buffer groups
@ 2020-07-01 18:18 Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-01 19:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 2+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-01 18:18 UTC (permalink / raw)
To: help-gnu-emacs
Check out examples last!
Note what child play it is to add support for more
buffer groups - perceived groups - because it is all
based on regexps - in this file, unsent messages and
shell buffers shows this...
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/emacs-init/switch-to-buffer-regexp.el
;;; https://dataswamp.org/~incal/emacs-init/switch-to-buffer-regexp.el
(require 'cl-lib)
(defun buffer-names ()
(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) )
(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 it 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\*.*")))
;;
;; - or all the shells
;;
;; (global-set-key "\C-cp" (lambda () (interactive) (switch-to-buffer-regexp "\*shell\*.*")))
(provide 'switch-to-buffer-regexp)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: switch-to-buffer-regexp.el to iterate buffer groups
2020-07-01 18:18 switch-to-buffer-regexp.el to iterate buffer groups Emanuel Berg via Users list for the GNU Emacs text editor
@ 2020-07-01 19:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 2+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-07-01 19:06 UTC (permalink / raw)
To: help-gnu-emacs
If all modes kept tidy lists of their buffers it
would be as simple as
(defun erc-next-buffer ()
"Go to the next ERC buffer, if available."
(interactive)
(let*((erc-buffers (erc-buffer-list))
(current (car erc-buffers))
(next (cadr erc-buffers)) )
(when next
(bury-buffer current)
(switch-to-buffer next) )))
(defun erc-prev-buffer ()
"Go to the prev ERC buffer, if available."
(interactive)
(let*((erc-buffers (erc-buffer-list))
(prev (car (last erc-buffers))) )
(when prev (switch-to-buffer prev)) ))
https://dataswamp.org/~incal/emacs-init/erc-my.el
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-07-01 19:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-01 18:18 switch-to-buffer-regexp.el to iterate buffer groups Emanuel Berg via Users list for the GNU Emacs text editor
2020-07-01 19:06 ` Emanuel Berg via Users list for the GNU Emacs text editor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).