我正在尝试唯一标识一个窗口, 如果我再按一次键,我可以选择并删除该窗口,但我在这方面遇到了麻烦。
(setq split-window-right-toggle-var nil)
(defun split-window-right-toggle ()
(interactive)
(if split-window-right-toggle-var
(progn
(right-split-undo)
(setq split-window-right-toggle-var nil))
(progn
(right-split-do)
(setq split-window-right-toggle-var t))))
(defun right-split-do ()
(interactive)
(split-window-right)
(other-window 1))
(defun right-split-undo ()
(interactive)
(other-window -1)
(delete-window))
这段代码的问题在于它在很大程度上取决于哪个窗口处于活动状态,哪个窗口可以 更改我的窗口状态并删除错误的窗口,我可以唯一地给我的窗口一个名称,然后将该窗口名称作为删除目标吗?我是Emacs lisp的新手,非常感谢任何帮助。
答案 0 :(得分:1)
(selected-window)
返回对当前窗口的引用。
(next-window)
返回下一个窗口。使用Emacs的自我记录功能
了解更多信息或参考手册。
(defvar ej-spit-window-saved nil)
(defun ej-split-window-right-toggle ()
"toggle split right"
(interactive)
(setq ej-split-window-saved
(if (and ej-split-window-saved
(frame-visible-p (window-frame ej-split-window-saved)))
(delete-window ej-split-window-saved)
(split-window-right))))
答案 1 :(得分:1)
你可以尝试这样的事情:
(setq window-names (make-hash-table :test 'equal ))
(defun name-window ()
(interactive)
(let ((name (read-input "Name: ")))
(setf (gethash name window-names) (selected-window))))
(defun del-window ()
(interactive)
(let ((name (read-input "Name: ")))
(delete-window (gethash name window-names))))