If there is a frame named "xyz", then switch to this frame

Can someone please give me a hand with a function that determines if a frame with the name "xyz" exists, and if so, switch to that frame. I use frame-cmds to give each frame a custom name: http://www.emacswiki.org/emacs/frame-cmds.el

I would suggest that it looks like a buffer, but I don't find 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-dedicated post: https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist


EDIT (September 15, 2014): The ido-switch-frame function has been changed to make frame-to valid variable and delete message . Previous changes have been removed since the get-a-frame and get-frame-name functions 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))))))))) 
+2
source share
2 answers

There may be more elegant solutions, but this does its job:

 (defun switch-to-frame (frame-name) (interactive "sFrame name:") (let ((frames (frame-list))) (catch 'break (while frames (let ((frame (car frames))) (if (equal (frame-parameter frame 'name) frame-name) (throw 'break (select-frame-set-input-focus frame)) (setq frames (cdr frames)))))))) 
+1
source
  • Enter your query for "a function that determines if a frame named" xyz "exists:" You already have this, because you say you use frame-cmds.el , which requires frame-fns.el --- Function get-a-frame does just that.

  • Icicles provides a multi-command icicle-select-frame that allows you to select frames by name using completion.

+1
source

Source: https://habr.com/ru/post/1493838/


All Articles