Could someone please give me hand with a function that detects whether a frame named "xyz" exists, and if so, then switch to that frame. I'm using frame-cmds
to give each frame a user-defined name: ?http://www.emacswiki.org/emacs/frame-cmds.el
I would imagine it is similar to a buffer, but I'm not finding anything on Google. Here is the buffer function:
(defun buffer-exists (bufname)
(not (eq nil (get-buffer bufname))))
(defun lawlist-switch-to-buffer-xyz ()
(interactive)
(if (buffer-exists "xyz")
(switch-to-buffer "xyz") ))
Here is a semi-related post: ?https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist
EDIT (September 15, 2014): ?Modified the function ido-switch-frame
to make frame-to
a let-bound variable, and removed the message
. Removed previous edits as the functions get-a-frame
and get-frame-name
written by Drew Adams are sufficient when used in conjunction with select-frame-set-input-focus
-- see his answer below.
(defun ido-switch-frame ()
(interactive)
(when (not (minibufferp))
(let* (
(frames (frame-list))
(frame-to (ido-completing-read "Select Frame: "
(mapcar (lambda (frame) (frame-parameter frame 'name)) frames))))
(catch 'break
(while frames
(let ((frame (car frames)))
(if (equal (frame-parameter frame 'name) frame-to)
(throw 'break (select-frame-set-input-focus frame))
(setq frames (cdr frames)))))))))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…