2013-05-27 10 views
6

有没有办法在模式行的右端放置一个值?如何固定模式行右侧的值?

从我目前的理解来看,如果数值增加,模式行将“推动”它的值。如果某些价值观会从右侧开始并扩大到中间,我宁愿这样做。

我已经尝试过像powerline这样的解决方案,但它们似乎相当分散注意力,并且在安装过程中显示与标准modeline相同数量的信息。

回答

1

据我所知,这是不可能通过直接定制普通模式行来完成的。您可以修改mode-line-format变量以在一定程度上改变其外观和内容,但就内置的文本对齐结构而言,我相当确定您仅限于通过以下方式控制模式行组件的宽度:填充或截断。然而,在mode-line-format变量(使用(:eval ...)和/或(list ...)表单)中使用一些聪明的hackery来实现所需的结果可能是可行的。有关详细信息,请参阅Emacs Lisp Reference Manual page on the mode-line-format variable。除此之外,你必须使用一些第三方软件包。

4

这是一种方法。关键是要添加空格,直到行减去,以显示你的文本所需的地方结束(从电力线的代码中提取的Emacs的维基):

(defun mode-line-fill (face reserve) 
    "Return empty space using FACE and leaving RESERVE space on the right." 
    (unless reserve 
    (setq reserve 20)) 
    (when (and window-system (eq 'right (get-scroll-bar-mode))) 
    (setq reserve (- reserve 3))) 
    (propertize " " 
       'display `((space :align-to (- (+ right right-fringe right-margin) ,reserve))) 
       'face face)) 


;; Set the modeline to tell me the filename, hostname, etc.. 
(setq-default mode-line-format (list 
    " " 
    mode-line-mule-info 
    'mode-line-modified 
    "- " 
    'mode-line-buffer-identification 
    " (%l, %c) " 
    'mode-line-modes 
    " -- " 
    `(vc-mode vc-mode) 

    ;; Fill until the end of line but 10 characters 
    (mode-line-fill 'mode-line 10) 
    "Some text" 
    ) 
) 
+0

目前尚不清楚为什么你要选择一个脸填充物。如果指定'mode-line'面,它将用于活动和非活动模式行,这看起来很奇怪,因为非活动模式行使用'mode-line-inactive'面。相反,不要指定脸部,并使用正确的默认脸部。 –

相关问题