[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

switch-to-buffer-regexp.el to iterate buffer groups

From: Emanuel Berg
Subject: switch-to-buffer-regexp.el to iterate buffer groups
Date: Wed, 01 Jul 2020 20:18:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

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:

(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
                  (message "this buffer is the only hit")
                  (switch-to-buffer ori-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 
;; (global-set-key "\C-ch" (lambda () (interactive) (switch-to-buffer-regexp 
;; (global-set-key "\C-cc" (lambda () (interactive) (switch-to-buffer-regexp 
;; - 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 

(provide 'switch-to-buffer-regexp)

underground experts united

reply via email to

[Prev in Thread] Current Thread [Next in Thread]