From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: find buffer by regexp, then iterate (very cool) Date: Thu, 30 Jun 2016 15:45:52 +0200 Organization: Aioe.org NNTP Server Message-ID: <86d1myu6wf.fsf@student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1467294796 25645 80.91.229.3 (30 Jun 2016 13:53:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 30 Jun 2016 13:53:16 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 30 15:53:15 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bIcOz-00013E-T6 for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Jun 2016 15:53:10 +0200 Original-Received: from localhost ([::1]:49545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bIcOz-0002rY-6O for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Jun 2016 09:53:09 -0400 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 45 Original-NNTP-Posting-Host: EoOtCC1fCYcttx6jjhWUlA.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Mail-Copies-To: never X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:JssKI4ukj1PAG0GTaArhpA4FPmY= Original-Xref: usenet.stanford.edu gnu.emacs.help:218363 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110672 Archived-At: (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 -