home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / emacs / help / 4829 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.3 KB  |  68 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsm!cbnewsl!att-out!cbfsb!cbnewsb!mviae!mvjrs
  3. From: mvjrs@mviae.ATT.COM (Rick Sladkey)
  4. Subject: Re: cycling window positions
  5. In-Reply-To: lynn@urbana.mcd.mot.com's message of Mon, 16 Nov 1992 13:22:56 GMT
  6. Message-ID: <MVJRS.92Nov17130906@mviae.ATT.COM>
  7. Originator: news@cbnewsb.cb.att.com
  8. Lines: 52
  9. Sender: news@cbfsb.cb.att.com
  10. Nntp-Posting-Host: mviae-gw.cnet.att.com
  11. Organization: AT&T Network Systems
  12. References: <LYNN.92Nov16082256@ives.urbana.mcd.mot.com>
  13. Distribution: gnu
  14. Date: Tue, 17 Nov 1992 18:09:06 GMT
  15.  
  16. >>>>> On Mon, 16 Nov 1992 13:22:56 GMT, lynn@urbana.mcd.mot.com (Lynn
  17. >>>>> D. Newton) said:
  18.  
  19.  
  20. Lynn> Has anybody out there already written a function that is able to
  21. Lynn> cycle the position of windows in the following way? I'll use 3
  22. Lynn> windows for example. I have:
  23.  
  24. I've wanted that before so I just wrote one.  Here it is.
  25. -----
  26. ;;; rotbuf.el - rotate buffers in windows - rick sladkey
  27.  
  28. ;; example .emacs usage:
  29. ;;
  30. ;; (global-set-key "\C-c\C-r" 'rotate-window-buffers)
  31. ;; (autoload 'rotate-window-buffers "rotbuf" "Rotate buffers in windows." t)
  32.  
  33. (defun window-buffer-lists ()
  34.   (let* ((first-window (selected-window))
  35.      (window (next-window first-window 'no-minibuf))
  36.      (win-list (list first-window))
  37.      (buf-list (list (window-buffer first-window))))
  38.     (while (not (eq window first-window))
  39.       (setq win-list (cons window win-list))
  40.       (setq buf-list (cons (window-buffer window) buf-list))
  41.       (setq window (next-window window 'no-minibuf)))
  42.     (cons (nreverse win-list) (nreverse buf-list))))
  43.  
  44. (defun rotate-window-buffers (n)
  45.   "Rotate visible buffers within their respective windows.
  46. With an argument, rotate them through ARG windows."
  47.   (interactive "p")
  48.   (let* ((lists (window-buffer-lists))
  49.      (win-list (car lists))
  50.      (buf-list (cdr lists))
  51.      (length (length win-list)))
  52.     (setq n (mod (+ (mod n length) length) length))
  53.     (if (= n 0)
  54.     (message "Thanks, but no thanks.")
  55.       (let* ((last (nthcdr (1- n) buf-list))
  56.          (rest (cdr last)))
  57.     (setcdr last nil)
  58.     (setq buf-list (nconc rest buf-list)))
  59.       (while win-list
  60.     (set-window-buffer (car win-list) (car buf-list))
  61.     (setq win-list (cdr win-list))
  62.     (setq buf-list (cdr buf-list))))))
  63.  
  64.  
  65. --
  66. Rick Sladkey
  67. mvjrs@mviae.ATT.COM
  68.