我设置了如下的键绑定。
(global-set-key [M-down] 'shrink-window)
(global-set-key [M-up] 'enlarge-window)
因此,对于M-up,我可以放大窗口,否则使用M-down。 但是如果当前窗口是下侧,我想用M-up放大窗口。 如果当前窗口是M-up的上侧,我想调用缩小窗口函数。
同样地,如果当前窗口是下侧,我想缩小窗口M-down,如果当前窗口是上侧则放大。
换句话说,我想指出窗口分隔符的方向。
我该如何编写这个函数?
答案 0 :(得分:2)
当答案出现时,我刚刚完成了这段代码。哦,好吧。
(require 'windmove)
(global-set-key [M-up]
(lambda() (interactive)
(call-interactively
(if (windmove-find-other-window 'up)
'enlarge-window
'shrink-window))))
(global-set-key [M-down]
(lambda() (interactive)
(call-interactively
(if (not (windmove-find-other-window 'up))
'enlarge-window
'shrink-window))))
答案 1 :(得分:1)
利用windmove作为emacs的一部分,您可以这样做:
(require 'windmove)
(defun move-separator-up (arg)
(interactive "p")
(if (< (cdr (windmove-other-window-loc 'up)) 0)
(shrink-window arg)
(enlarge-window arg)))
(defun move-separator-down (arg)
(interactive "p")
(if (< (cdr (windmove-other-window-loc 'up)) 0)
(enlarge-window arg)
(shrink-window arg)))
当您有3个窗口时,enlarge-window
和shrink-window
规则可能无法始终执行您想要的操作,因此可能需要进一步自定义。