home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / emacs / 3500 < prev    next >
Encoding:
Text File  |  1992-11-09  |  3.3 KB  |  103 lines

  1. Newsgroups: comp.emacs
  2. Path: sparky!uunet!destroyer!gatech!cc.gatech.edu!news.cc.gatech.edu!jack
  3. From: jack@multimedia.news.cc.gatech.edu (Tom Rodriguez)
  4. Subject: Other buffer switching stuff - next-similar-buffer
  5. In-Reply-To: ejh@khonshu.colorado.edu's message of 4 Nov 92 13:29:05
  6. Message-ID: <1992Nov9.232003.15499@cc.gatech.edu>
  7. Sender: news@cc.gatech.edu
  8. Organization: Software Research Center / Georgia Tech
  9. References: <EJH.92Nov4132905@khonshu.colorado.edu>
  10. Distribution: usa
  11. Date: Mon, 9 Nov 1992 23:20:03 GMT
  12. Lines: 89
  13.  
  14.  
  15. ;;; --------------------------------------------------------------------------
  16. ;;; Author: Tom Rodriguez (jack@cc.gatech.edu)
  17. ;;; Copyright (C) 1992.
  18. ;;; Here are some functions i find useful that are related to buffer
  19. ;;; switching in emacs.  They allow you to keep several buffers around
  20. ;;; with names like foo, foo<2>, foo<3> and cycle through them.  You
  21. ;;; can also push and pop foo, changing foo to foo<2> and foo<2> to
  22. ;;; foo, respectively.  I find these very useful with multiple shells
  23. ;;; compiles, and man pages.
  24. ;;;
  25. ;;;  
  26. ;;;  Here are the key bindings I normally use.
  27. ;;; (define-key global-map "\C-x4n" 'next-similar-buffer)
  28. ;;; (define-key global-map "\C-x4p" 'push-buffer-name)
  29. ;;; (define-key global-map "\C-x4t" 'pop-buffer-to-top)
  30. ;;;
  31. ;;; this function renames a buffer to an unused name so that 
  32. ;;; buffers that are reused by packages can be stuffed away
  33. ;;; to be used later.
  34.  
  35. (defun push-buffer-name (&optional name)
  36.   (interactive)
  37.   (if name
  38.       (if (not (stringp name))
  39.       (setq name (buffer-name name)))
  40.       (setq name (buffer-name)))
  41.   (save-excursion
  42.     (set-buffer name)
  43.     (let (new-buffer new-buffer-name)
  44.       (setq new-buffer (generate-new-buffer 
  45.             (buffer-basename name)))
  46.       (setq new-buffer-name (buffer-name new-buffer))
  47.       (kill-buffer new-buffer)
  48.       (rename-buffer new-buffer-name)
  49.       (set-buffer-modified-p (buffer-modified-p)))))
  50.  
  51.  
  52. (defun pop-buffer-to-top (&optional name)
  53.   (interactive)
  54.   (if name
  55.       (if (not (stringp name))
  56.       (setq name (buffer-name name)))
  57.       (setq name (buffer-name)))
  58.   (let ((basename (buffer-basename name)))
  59.     (if (not (eq basename (buffer-name)))
  60.     (progn 
  61.       (if (get-buffer basename)
  62.           (progn
  63.         ;; push it so that the old buffer goes where this one is
  64.         (push-buffer-name)
  65.         ;; push the other buffer out of the way
  66.         (save-excursion
  67.           (switch-to-buffer basename)
  68.         (push-buffer-name))))
  69.       ;; push this one into place
  70.       (push-buffer-name)))))
  71.  
  72.  
  73. (defun next-similar-buffer ()
  74. "Switch to the next buffer in the buffer-list with a name similar to
  75. current buffer.  Similar in this case means that it has the same base
  76. and may end with <[2-9]>."
  77.   (interactive)
  78.   (defun next-match (regex blist)
  79.     (cond ((null blist) nil)
  80.       ((string-match regex (car blist))
  81.        (switch-to-buffer (car blist)))
  82.       (t (next-match regex (cdr blist)))))
  83.  
  84.   (defun buffer-basename (name)
  85.     (if (string-match "\\(<[2-9]+>\\)$" name)
  86.     (substring name 0 (match-beginning 0))
  87.       name))
  88.  
  89.   (let ((case-fold-search nil))    
  90.     (next-match
  91.      (concat "^" (regexp-quote
  92.           (buffer-basename (buffer-name (current-buffer)))))
  93.      (reverse (cdr (mapcar (function buffer-name) (buffer-list)))))))
  94.  
  95.  
  96.  
  97.  
  98. --
  99. Tom Rodriguez  (jack@cc.gatech.edu)
  100. Multimedia Computing Group - GVU Lab
  101. Georgia Institute of Technology
  102. Atlanta, Georgia 30332-0280
  103.