Emacs - 模式行更新
我在我的笔记本电脑(emacs 23.3)上定制了我的模式行,它运行得很好。
但是,当我尝试让它在学校的桌面上运行(emacs 21.4)时,使用 Ctrl-f、Ctrl-b、Ctrl-a 等,除非我实际修改缓冲区。
点时模式行没有更新
我做了一个案例声明来根据我所在的计算机更改代码,因此所有功能都可以正常工作,只是在移动我尝试执行以下操作的
(add-hook 'move-beginning-of-line 'force-mode-line-update)
(add-hook 'move-end-of-line 'force-mode-line-update)
(add-hook 'forward-char 'force-mode-line-update)
(add-hook 'backward-char 'force-mode-line-update)
(add-hook 'next-line 'force-mode-line-update)
(add-hook 'previous-line 'force-mode-line-update)
但它仍然没有不更新
有什么建议吗?
代码:
(setq-default mode-line-format
(list
"---- "
;; Modified shows *
"["
'(:eval
(if (buffer-modified-p)
"*"
(if buffer-read-only
"!"
" "
)))
"] "
;; Buffer (tooltip - file name)
'(:eval (propertize "%b" 'face 'bold 'help-echo (buffer-file-name)))
" "
;; Spaces 12 - "buffer"
'(:eval
(make-string
(- 12
(min
12
(length (buffer-name))))
?-))
" "
;; Current (row,column)
"(" '(:eval (number-to-string (count-lines 1 (point))))
"," '(:eval (number-to-string (current-column)))
") "
;; Spaces 7 - "(r,c)"
'(:eval
(make-string
(- 7
(min
4
(length (number-to-string (current-column)))
)
(min
3
(length (number-to-string (1+ (count-lines 1 (point)))))))
?-))
;; Percentage of file traversed (current line/total lines)
" ["
'(:eval (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max)))) )
"%%] "
;; Spaces 3 - %
'(:eval
(make-string
(- 3 (length (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max))))))
?-))
;; Major Mode
" [" '(:eval mode-name) "] "
;; Spaces 16 + (6 - %)
'(:eval
(make-string
(- 22
(min
6
(length mode-name)))
?-))
" ("
;; Time
'(:eval (format-time-string "%H:%M"))
;; Fill with '-'
") %-"
))
提前致谢
I customized my mode-line on my laptop (emacs 23.3) and it works perfect.
But when I tried to get it to work on my desktop at school (emacs 21.4) it doesn't update when using Ctrl-f, Ctrl-b, Ctrl-a, etc. unless I actually modify the buffer.
I made a case statement to change the code depending on the computer I'm on, so all the functions work properly, its just that the mode-line doesn't update when moving the point
I tried doing the following
(add-hook 'move-beginning-of-line 'force-mode-line-update)
(add-hook 'move-end-of-line 'force-mode-line-update)
(add-hook 'forward-char 'force-mode-line-update)
(add-hook 'backward-char 'force-mode-line-update)
(add-hook 'next-line 'force-mode-line-update)
(add-hook 'previous-line 'force-mode-line-update)
But it still doesn't update
Any suggestions?
Code:
(setq-default mode-line-format
(list
"---- "
;; Modified shows *
"["
'(:eval
(if (buffer-modified-p)
"*"
(if buffer-read-only
"!"
" "
)))
"] "
;; Buffer (tooltip - file name)
'(:eval (propertize "%b" 'face 'bold 'help-echo (buffer-file-name)))
" "
;; Spaces 12 - "buffer"
'(:eval
(make-string
(- 12
(min
12
(length (buffer-name))))
?-))
" "
;; Current (row,column)
"(" '(:eval (number-to-string (count-lines 1 (point))))
"," '(:eval (number-to-string (current-column)))
") "
;; Spaces 7 - "(r,c)"
'(:eval
(make-string
(- 7
(min
4
(length (number-to-string (current-column)))
)
(min
3
(length (number-to-string (1+ (count-lines 1 (point)))))))
?-))
;; Percentage of file traversed (current line/total lines)
" ["
'(:eval (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max)))) )
"%%] "
;; Spaces 3 - %
'(:eval
(make-string
(- 3 (length (number-to-string (/ (* (1+ (count-lines 1 (point))) 100) (count-lines 1 (point-max))))))
?-))
;; Major Mode
" [" '(:eval mode-name) "] "
;; Spaces 16 + (6 - %)
'(:eval
(make-string
(- 22
(min
6
(length mode-name)))
?-))
" ("
;; Time
'(:eval (format-time-string "%H:%M"))
;; Fill with '-'
") %-"
))
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在原始帖子的评论中,您在模式行中提到了您想要的以下信息:
我使用的 emacs 永远并且所有 (1)、(3) 和 (5) 已经在每个缓冲区的默认 emacs 模式行中,并且已经存在很长时间了。要启用 (2) 和 (6),请添加
到
~/.emacs
。根据我在网上可以找到的信息,column-number-mode
晚于 emacs 21。请注意,这些都不需要显式地重新定义
mode-line
、覆盖任何函数或添加任何挂钩。我没有提供(4)的答案,因为我不知道你的意思。In the comments on the original post, you mention the following information you'd like in the mode line:
I've used emacs forever and all of (1), (3), and (5) are in the default emacs mode line for every buffer already, and have been for a very long time. To enable (2) and (6), add
to
~/.emacs
. From what I can find online,column-number-mode
postdates emacs 21.Note that none of this requires explicitly redefining
mode-line
, overriding any functions, or adding any hooks. I haven't provided an answer for (4) because I don't know what you mean by it.