unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: switch-to-buffer-regexp.el to iterate buffer groups
Date: Wed, 01 Jul 2020 20:18:50 +0200	[thread overview]
Message-ID: <87blkzrtdh.fsf@ebih.ebihd> (raw)

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




             reply	other threads:[~2020-07-01 18:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 18:18 Emanuel Berg via Users list for the GNU Emacs text editor [this message]
2020-07-01 19:06 ` switch-to-buffer-regexp.el to iterate buffer groups Emanuel Berg via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blkzrtdh.fsf@ebih.ebihd \
    --to=help-gnu-emacs@gnu.org \
    --cc=moasenwood@zoho.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).