在Emacs GUI中创建框架的行为类似于终端中的框架

时间:2014-06-11 08:09:17

标签: emacs

在终端中,Emacs使用F1,F2等名称管理多个帧,因为它无法创建多个OS窗口。我希望GUI版本以这种方式运行,也就是说,我希望它在单个Emacs窗口中创建许多虚拟帧,而不是创建多个OS窗口。有办法吗?

2 个答案:

答案 0 :(得分:1)

如果您的意思是希望能够按名称访问框架,那么是的,您可以使用Icicles执行此操作。

默认情况下,C-x 5 o绑定到multi-command icicle-select-frame。这允许您按名称选择一个或多个帧。

框架的名称来自其name框架参数。根据需要[NUMBER]添加后缀 让它独一无二。例如,在以帧命名的上下文中 他们的缓冲区和你有两个框架显示缓冲区*Help*,其中一个 这些帧将被称为*Help*[2],以便与此命令一起使用。

C-x 5 o的帧选择使用完成和循环。完成可以是vanilla Emacs完成或regexp(当然包括子串)完成。 (它也可以是几个模糊完成中的任何一个。)

(如果由于某种原因,您希望帧名称只是F1F2等,就像终端Emacs一样,那么您只需要在帧级别执行此操作参数name。你可以使用钩子等来做到这一点。)

答案 1 :(得分:1)

有一种方法可以模仿GUI中终端emacs的帧切换行为。这是我所做的。基本上,它使用make-frame-invisible隐藏不活动的帧。它在带有i3的archlinux上运行良好。

(defsubst +amos--is-frame-daemons-frame (f)
(and (daemonp) (eq f terminal-frame)))

(defun +amos--frame-list-without-daemon ()
"Return a list of frames without the daemon's frame."
(if (daemonp)
    (filtered-frame-list
    #'(lambda (f) (not (+amos--is-frame-daemons-frame f))))
    (frame-list)))

(defun +amos/workspace-new ()
(interactive)
(let ((name (frame-parameter nil 'name))
        (oframe (selected-frame)))
    (select-frame (if (s-starts-with? "F" name)
                    (make-frame)
                    (make-frame `((name . ,name)))))
    (make-frame-invisible oframe t))
(setq +amos--frame-list (reverse (+amos--frame-list-without-daemon))))

(setq +amos-tmux-need-switch nil)

;; TODO ring lru
(defun +amos/workspace-delete ()
(interactive)
(let ((f (selected-frame)))
    (select-frame (previous-frame))
    (make-frame-visible)
    (delete-frame f))
(setq +amos--frame-list (reverse (+amos--frame-list-without-daemon)))
(+doom-modeline|set-selected-window)
(realign-windows)
(when +amos-tmux-need-switch
    (shell-command! "tmux switch-client -t amos\; run-shell -t amos '/home/amos/scripts/setcursor.sh $(tmux display -p \"#{pane_tty}\")'")
    (setq +amos-tmux-need-switch nil)))

(defun +amos/workspace-switch-to (index)
(interactive)
(when (< index (length +amos--frame-list))
    (let ((frame (nth index +amos--frame-list))
        (oframe (selected-frame)))
    (select-frame frame)
    (raise-frame frame)
    (make-frame-invisible oframe t)
    (setq +amos-tmux-need-switch nil)
    (realign-windows)
    (recenter))))

(defun +amos/workspace-switch-to-1 () (interactive) (+amos/workspace-switch-to 0))
(defun +amos/workspace-switch-to-2 () (interactive) (+amos/workspace-switch-to 1))
(defun +amos/workspace-switch-to-3 () (interactive) (+amos/workspace-switch-to 2))
(defun +amos/workspace-switch-to-4 () (interactive) (+amos/workspace-switch-to 3))
(defun +amos/workspace-switch-to-5 () (interactive) (+amos/workspace-switch-to 4))
(defun +amos/workspace-switch-to-6 () (interactive) (+amos/workspace-switch-to 5))
(defun +amos/workspace-switch-to-7 () (interactive) (+amos/workspace-switch-to 6))
(defun +amos/workspace-switch-to-8 () (interactive) (+amos/workspace-switch-to 7))
(defun +amos/workspace-switch-to-9 () (interactive) (+amos/workspace-switch-to 8))
(defun +amos-workspace-cycle (off)
(let* ((n (length +amos--frame-list))
        (index (-elem-index (selected-frame) +amos--frame-list))
        (i (% (+ off index n) n)))
    (+amos/workspace-switch-to i)))
(defun +amos/workspace-switch-left ()  (interactive) (+amos-workspace-cycle -1))
(defun +amos/workspace-switch-right () (interactive) (+amos-workspace-cycle +1))

(defun +amos|maybe-delete-frame-buffer (frame)
(let ((windows (window-list frame)))
    (dolist (window windows)
    (let ((buffer (window-buffer (car windows))))
        (when (eq 1 (length (get-buffer-window-list buffer nil t)))
        (kill-buffer buffer))))))
(add-to-list 'delete-frame-functions #'+amos|maybe-delete-frame-buffer)