我想在我的模式行中的某处显示(getenv"HOSTNAME")的输出.我的显示时间模式设置为't',所以我已经在模式行中显示时间,负载级别和邮件标志.是否有一种简单的方法来获取主机名?
我想拥有这个,因为我正在使用3个远程计算机,所有正在运行的emacs来自一组常见的初始化文件,我想要一些快速简单的不显眼方式来了解我正在使用哪台计算机.
以Sean Bright的答案为基础,特别是你可以这样做:
(let ((pos (memq 'mode-line-modes mode-line-format)))
(setcdr pos (cons (getenv "HOSTNAME") (cdr pos))))
Run Code Online (Sandbox Code Playgroud)
这假定它'mode-line-modes是您的一部分,'mode-line-format默认情况下是它的一部分.因为您正在修改变量指向的列表'mode-line-format,所以您不必设置默认值.如果您自己设置变量,则必须执行以下操作:
(setq-default mode-line-format (build-list-that-contains-(getenv "HOSTNAME")))
Run Code Online (Sandbox Code Playgroud)
我尝试了上面的答案并没有特别成功(我正在运行emacs 23).经过大量调查后,我最终只是把system-name到我的mode-line-format如下:
;; Set the modeline to tell me the filename, hostname, etc..
(setq-default mode-line-format
(list " "
; */% indicators if the file has been modified
'mode-line-modified
"--"
; the name of the buffer (i.e. filename)
; note this gets automatically highlighted
'mode-line-buffer-identification
"--"
; major and minor modes in effect
'mode-line-modes
; if which-func-mode is in effect, display which
; function we are currently in.
'(which-func-mode ("" which-func-format "--"))
; line, column, file %
'mode-line-position
"--"
; if vc-mode is in effect, display version control
; info here
`(vc-mode vc-mode)
"--"
; hostname
'system-name
; dashes sufficient to fill rest of modeline.
"-%-"
)
)
Run Code Online (Sandbox Code Playgroud)
我在我的网站上发布的帖子中详细介绍了这个以及我发现的关于emacs模式的其他内容.
| 归档时间: |
|
| 查看次数: |
3188 次 |
| 最近记录: |