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 + helper/interface file
Date: Sat, 19 Dec 2020 04:03:33 +0100 [thread overview]
Message-ID: <87r1nmebui.fsf@zoho.eu> (raw)
Got this old idea working, finally! Works great :) And it
didn't take me very long, either... 2 files. See comments
for instructions.
;;; -*- 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 (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
(global-set-key "\C-cu" (lambda () (interactive) (switch-to-buffer-regexp "\*unsent posting\*.*")))
(global-set-key "\C-ck" (lambda () (interactive) (switch-to-buffer-regexp ".*\.txt")))
;; hit again to iterate
(provide 'switch-to-buffer-regexp)
;;; -*- lexical-binding: t -*-
;;;
;;; this file:
;;; http://user.it.uu.se/~embe8573/emacs-init/switch-to-buffer.el
;;; https://dataswamp.org/~incal/emacs-init/switch-to-buffer.el
;;;
;;; bind these and similar to one-button keys, e.g. from the buffer-menu
(require 'switch-to-buffer-regexp)
(defun switch-to-compilation-buffer ()
(interactive)
(switch-to-buffer-regexp "\*compilation\*") )
(defun switch-to-help-buffer ()
(interactive)
(switch-to-buffer-regexp "\*Help\*") )
(defun switch-to-info-buffer ()
(interactive)
(switch-to-buffer-regexp "\*info\*") )
(defun switch-to-manpage-buffer ()
(interactive)
(switch-to-buffer-regexp "\*Man .*\*") )
(defun switch-to-summary-buffer ()
(interactive)
(switch-to-buffer-regexp "\*Summary.*\*") )
(defun switch-to-article-buffer ()
(interactive)
(switch-to-buffer-regexp "\*Article\*") )
(defun switch-to-unsent-buffer ()
(interactive)
(switch-to-buffer-regexp "\*unsent .*\*") )
(provide 'switch-to-buffer)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
reply other threads:[~2020-12-19 3:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87r1nmebui.fsf@zoho.eu \
--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).