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

  1. Newsgroups: comp.emacs
  2. Path: sparky!uunet!pmafire!mica.inel.gov!ux1!news.byu.edu!eff!iWarp.intel.com|ichips!pdx025!jabram
  3. From: jabram@pdx025 (Jeff Abramson)
  4. Subject: Re: anyone got a way to cycle through buffers with a keystroke?
  5. Message-ID: <1992Nov6.162055.29554@ichips.intel.com>
  6. Sender: news@ichips.intel.com (News Account)
  7. Organization: Intel Corp., Hillsboro, Oregon
  8. References: <EJH.92Nov4132905@khonshu.colorado.edu> <Bx94Fp.3t5@da_vinci.it.uswc.uswest.com>
  9. Distribution: usa
  10. Date: Fri, 6 Nov 1992 16:20:55 GMT
  11. Lines: 84
  12.  
  13. I've seen some good options on how to do this, but I wrote my own
  14. functions to work with a specific list of buffers, not the entire buffer list.
  15.  
  16. Below is a list definition, and four subroutines:  The first loads all the
  17. named files into buffers.  The second saves them with a single keystroke.
  18. The third and fourth cycle through the list.  
  19.  
  20. This is really the first set of emacs functions I have written, and they seem
  21. to be working out well for me.  So there is probably a better way to do it,
  22. but isn't that always the case...
  23.  
  24.  
  25. (defvar foo-buffer-list
  26.   (list
  27.     "foo.hdl"
  28.     "fooa.hdl"
  29.     "foob.hdl"
  30.     "fooc.hdl"
  31.     "food.hdl"
  32.     "fooe.hdl"
  33.     "foof.hdl"))
  34.  
  35. ;; saves all files in foo-buffer-list
  36. ;;
  37. (global-set-key "\C-x\C-m" 'save-all-foo-hdl-file)
  38. (defun save-all-foo-hdl-file ()
  39.   (interactive)
  40.   (dotimes (i (length foo-buffer-list))
  41.     (set-buffer (nth i foo-buffer-list))
  42.     (save-buffer)))
  43.  
  44. ;; loads all files in foo-buffer-list
  45. ;;
  46. (defun load-all-foo-hdl-files ()
  47.   (interactive)
  48.     (dotimes (i (length foo-buffer-list))
  49.       (find-file (nth i foo-buffer-list))))
  50.  
  51.  
  52. ;; These two defuns allow me to move around in the foo-buffer-list easily.
  53. ;;
  54. ;; Bound to M-p and M-n.
  55. ;;
  56. (global-set-key "≡" 'foo-prev-buffer)
  57. (global-set-key "ε" 'foo-next-buffer)
  58.  
  59. (defun foo-next-buffer ()
  60.   "Switch to next buffer in foo list.  Basically, split
  61.    the list at that buffer, and move the sublist from that
  62.    buffer to the end of the list, to the beginning
  63.  
  64.    (foo-next-buffer) does:
  65.       (a b c d e)  --> (b c d e a)"
  66.  
  67.   (interactive)
  68.   (setq foo-buffer-list
  69.          (append (cdr foo-buffer-list)
  70.                  (list (car foo-buffer-list))))
  71.   (switch-to-buffer (car foo-buffer-list)))
  72.  
  73. (defun foo-prev-buffer ()
  74.   "Switch to next buffer in foo list.  Basically, split
  75.    the list at that buffer, and move the sublist from that
  76.    buffer to the end of the list, to the beginning
  77.  
  78.    (foo-next-buffer) does:
  79.       (a b c d e)  --> (e a b c d)"
  80.  
  81.   (interactive)
  82.   (let ((last (nth (- (length foo-buffer-list) 1) foo-buffer-list))
  83.         (rest (delq (nth (- (length foo-buffer-list) 1) foo-buffer-list) foo-buffer-list)))
  84.  
  85.        (setq foo-buffer-list
  86.               (append (list last) rest)))
  87.   (switch-to-buffer (car foo-buffer-list)))
  88.  
  89.  
  90. --Jeff Abramson
  91.   Microprocessor Division 6
  92.   Intel Corporation, Hillsboro OR                       (503) 696-4784
  93. -- 
  94.   Jeff Abramson
  95.   Microprocessor Division 6
  96.   Intel Corporation, Hillsboro OR                       (503) 696-4784
  97.