本文介绍了如果框架名为“xyz"存在,然后切换到该帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一个函数来检测是否存在名为xyz"的框架,如果存在,则切换到该框架.我正在使用 frame-cmds 为每个框架指定一个用户定义的名称:http://www.emacswiki.org/emacs/frame-cmds.el

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

我认为它类似于缓冲区,但我在 Google 上找不到任何内容.这是缓冲函数:

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") ))

这是一个半相关的帖子:https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist

Here is a semi-related post:  https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist

EDIT(2014 年 9 月 15 日):修改函数 ido-switch-frame 使 frame-to 成为 let-bound 变量,并删除了message.删除了以前的编辑,因为 Drew Adams 编写的函数 get-a-frameget-frame-name 在与 select-frame-set 结合使用时就足够了-input-focus -- 见下面他的回答.

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)))))))))

推荐答案

可能有更优雅的解决方案,但这可以完成工作:

There may be more elegant solutions but this gets the job done:

(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))))))))

这篇关于如果框架名为“xyz"存在,然后切换到该帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:09