home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.emacs
- Path: sparky!uunet!destroyer!gatech!cc.gatech.edu!news.cc.gatech.edu!jack
- From: jack@multimedia.news.cc.gatech.edu (Tom Rodriguez)
- Subject: Other buffer switching stuff - next-similar-buffer
- In-Reply-To: ejh@khonshu.colorado.edu's message of 4 Nov 92 13:29:05
- Message-ID: <1992Nov9.232003.15499@cc.gatech.edu>
- Sender: news@cc.gatech.edu
- Organization: Software Research Center / Georgia Tech
- References: <EJH.92Nov4132905@khonshu.colorado.edu>
- Distribution: usa
- Date: Mon, 9 Nov 1992 23:20:03 GMT
- Lines: 89
-
-
- ;;; --------------------------------------------------------------------------
- ;;; Author: Tom Rodriguez (jack@cc.gatech.edu)
- ;;; Copyright (C) 1992.
- ;;; Here are some functions i find useful that are related to buffer
- ;;; switching in emacs. They allow you to keep several buffers around
- ;;; with names like foo, foo<2>, foo<3> and cycle through them. You
- ;;; can also push and pop foo, changing foo to foo<2> and foo<2> to
- ;;; foo, respectively. I find these very useful with multiple shells
- ;;; compiles, and man pages.
- ;;;
- ;;;
- ;;; Here are the key bindings I normally use.
- ;;; (define-key global-map "\C-x4n" 'next-similar-buffer)
- ;;; (define-key global-map "\C-x4p" 'push-buffer-name)
- ;;; (define-key global-map "\C-x4t" 'pop-buffer-to-top)
- ;;;
- ;;; this function renames a buffer to an unused name so that
- ;;; buffers that are reused by packages can be stuffed away
- ;;; to be used later.
-
- (defun push-buffer-name (&optional name)
- (interactive)
- (if name
- (if (not (stringp name))
- (setq name (buffer-name name)))
- (setq name (buffer-name)))
- (save-excursion
- (set-buffer name)
- (let (new-buffer new-buffer-name)
- (setq new-buffer (generate-new-buffer
- (buffer-basename name)))
- (setq new-buffer-name (buffer-name new-buffer))
- (kill-buffer new-buffer)
- (rename-buffer new-buffer-name)
- (set-buffer-modified-p (buffer-modified-p)))))
-
-
- (defun pop-buffer-to-top (&optional name)
- (interactive)
- (if name
- (if (not (stringp name))
- (setq name (buffer-name name)))
- (setq name (buffer-name)))
- (let ((basename (buffer-basename name)))
- (if (not (eq basename (buffer-name)))
- (progn
- (if (get-buffer basename)
- (progn
- ;; push it so that the old buffer goes where this one is
- (push-buffer-name)
- ;; push the other buffer out of the way
- (save-excursion
- (switch-to-buffer basename)
- (push-buffer-name))))
- ;; push this one into place
- (push-buffer-name)))))
-
-
- (defun next-similar-buffer ()
- "Switch to the next buffer in the buffer-list with a name similar to
- current buffer. Similar in this case means that it has the same base
- and may end with <[2-9]>."
- (interactive)
- (defun next-match (regex blist)
- (cond ((null blist) nil)
- ((string-match regex (car blist))
- (switch-to-buffer (car blist)))
- (t (next-match regex (cdr blist)))))
-
- (defun buffer-basename (name)
- (if (string-match "\\(<[2-9]+>\\)$" name)
- (substring name 0 (match-beginning 0))
- name))
-
- (let ((case-fold-search nil))
- (next-match
- (concat "^" (regexp-quote
- (buffer-basename (buffer-name (current-buffer)))))
- (reverse (cdr (mapcar (function buffer-name) (buffer-list)))))))
-
-
-
-
- --
- Tom Rodriguez (jack@cc.gatech.edu)
- Multimedia Computing Group - GVU Lab
- Georgia Institute of Technology
- Atlanta, Georgia 30332-0280
-