[英]window--display-buffer: How to precisely set window width at time of creation
With respect to the function window--display-buffer
, I have been unable to precisely set the window width using a number -- eg, '((window-width . 82))
. 关于函数
window--display-buffer
,我无法使用数字精确设置窗口宽度,例如'((window-width . 82))
。 The width is always slightly less than it should be. 宽度始终略小于应有的宽度。 Any assistance to reliably use a number to set the window width would be greatly appreciated.
可靠地使用数字来设置窗口宽度的任何帮助将不胜感激。
The documentation ( https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Action-Functions.html ) states as follows: 文档( https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Action-Functions.html )指出如下:
To adjust the window's width, use an entry whose car is window-width
and whose cdr is one of: 要调整窗口的宽度,请使用以下项: car为
window-width
, cdr为以下项之一:
nil
means to leave the width of the new window alone. nil
表示nil
新窗口的宽度。
A number specifies the desired width of the new window. 一个数字指定新窗口的所需宽度。 An integer number specifies the number of columns of the window.
整数指定窗口的列数。 A floating point number gives the fraction of the window's width with respect to the width of the frame's root window.
浮点数给出了窗口宽度相对于框架根窗口宽度的分数。
If the cdr
specifies a function , that function is called with one argument: the new window . 如果
cdr
指定了一个函数 ,则使用一个参数调用该函数: new window 。 The function is supposed to adjust the width of the window; 该功能应该调整窗口的宽度; its return value is ignored.
其返回值将被忽略。
Here is a broken-example
that demonstrates the problem with window--display-buffer
when using a number -- eg, '((window-width . 82))
这是一个不完整
broken-example
,展示了使用数字时window--display-buffer
的问题-例如'((window-width . 82))
(defun broken-example ()
(interactive)
(window--display-buffer
;; buffer
(get-buffer-create "*test*")
;; window
(split-window (selected-window) nil 'right)
;; type
'window
;; alist
'((window-width . 82))
;; dedicated
t)
(message "Window Width: %s" (window-width (get-buffer-window "*test*"))) )
Here is a working-example
that uses the third option -- ie, a function whose argument is the new window : 这是一个使用第三个选项的
working-example
,即一个参数为新窗口 的函数 :
(defun working-example ()
(interactive)
(window--display-buffer
;; buffer
(get-buffer-create "*test*")
;; window
(split-window (selected-window) nil 'right)
;; type
'window
;; alist
'((window-width . set-window-width))
;; dedicated
t)
(message "Window Width: %s" (window-width (get-buffer-window "*test*"))) )
(defun set-window-width (window)
"Set the selected window's width."
(window-resize window (- 82 (window-width)) t) )
As to a current version of Emacs Trunk built on March 19, 2014, the following modification of line 5944 of window.el
from
to (delta (- new-width (window-total-width window))))
(delta (- new-width (window-width window))))
resolves this issue. 对于构建于2014年3月19日的Emacs Trunk的当前版本,
window.el
的第5944行从
(delta (- new-width (window-total-width window))))
window.el
到(delta (- new-width (window-total-width window))))
(delta (- new-width (window-width window))))
解决了此问题。
EDIT (March 22, 2014): Here is a link to the open bug report on this issue -- http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17065 编辑 (2014年3月22日):以下是此问题的未解决错误报告的链接-http://debbugs.gnu.org/cgi/bugreport.cgi?bug= 17065
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.