help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: next-frame / cycle through all frames?


From: Alan Mackenzie
Subject: Re: next-frame / cycle through all frames?
Date: Sat, 8 Apr 2006 11:52:44 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

David Reitter <david.reitter@gmail.com> wrote on Fri, 7 Apr 2006 18:52:39
+0100:
> What's a good way to cycle through all frames?

> I have defined

> (defun switch-to-next-frame ()
>    (interactive)
>    (select-frame-set-input-focus (next-frame)))

> which lets me switch to the next frame. But unfortunately, at least  
> in current CVS versions, it seems to be adding the current frame to  
> the top of the list so that the next call to  `next-frame' will  
> return the previously selected frame. In other words, if you have  
> three frames open, it'll only let you cycle between two of them.

> Is that actually the intended behavior? (It might be analogous to  
> windows.)

> If that's so, what's the easiest way to cycle between all frames?

I don't like Emacs's standard frame swapping stuff.  I switch to specific
frames with F1, F2, ...., rather than cycling through them.  Like this:

#########################################################################
(defvar frame-no-initialised nil)
(when (not frame-no-initialised)       ; run only at emacs startup.
  (modify-frame-parameters (selected-frame) '((acm-no . 0))))

(defun assign-acm-no (frame)
  "FRAME is a (typically newly created) frame.  Give it an acm-no 
frame-parameter
if there is one free (in the range 0..11).  Return that number or nil."
  (let ((assigned (make-bool-vector 12 nil)) (f (frame-list)) n)
    (while f
      (if (setq n (frame-parameter (car f) 'acm-no))
          (aset assigned n t))
      (setq f (cdr f)))
    (setq n 0)
    (while (and (< n 12) (aref assigned n))
      (setq n (1+ n)))
    (if (= n 12)
        nil
      (modify-frame-parameters frame `((acm-no . ,n)))
      n)))

(defun find-acm-no-frame (n)
  "Return the frame with parameter (acm-no . N), or nil."
  (let ((f (frame-list)))
    (while (and f (not (eq (frame-parameter (car f) 'acm-no) n)))
      (setq f (cdr f)))
    (car f)))

(add-hook 'after-make-frame-functions 'assign-acm-no)
(defun select-frame-acm-no (n)
  "Select the frame with acm-no frame-parameter N, or do nothing."
  (let ((frame (find-acm-no-frame n)))
    (if frame (select-frame-set-input-focus frame))))

(global-set-key [f1] (lambda () "Switch to frame F1" (interactive) 
(select-frame-acm-no 0)))
(global-set-key [f2] (lambda () "Switch to frame F2" (interactive) 
(select-frame-acm-no 1)))
(global-set-key [f3] (lambda () "Switch to frame F3" (interactive) 
(select-frame-acm-no 2)))
(global-set-key [f4] (lambda () "Switch to frame F4" (interactive) 
(select-frame-acm-no 3)))
(global-set-key [f5] (lambda () "Switch to frame F5" (interactive) 
(select-frame-acm-no 4)))
(global-set-key [f6] (lambda () "Switch to frame F6" (interactive) 
(select-frame-acm-no 5)))
(global-set-key [f7] (lambda () "Switch to frame F7" (interactive) 
(select-frame-acm-no 6)))
(global-set-key [f8] (lambda () "Switch to frame F8" (interactive) 
(select-frame-acm-no 7)))
(global-set-key [f9] (lambda () "Switch to frame F9" (interactive) 
(select-frame-acm-no 8)))
(global-set-key [f10] (lambda () "Switch to frame F10" (interactive) 
(select-frame-acm-no 9)))
(global-set-key [f11] (lambda () "Switch to frame F11" (interactive) 
(select-frame-acm-no 10)))
(global-set-key [f12] (lambda () "Switch to frame F12" (interactive) 
(select-frame-acm-no 11)))
#########################################################################

> Thanks for your help!

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").



reply via email to

[Prev in Thread] Current Thread [Next in Thread]