Emacs - 模式行更新

发布于 2024-12-19 14:10:46 字数 2074 浏览 0 评论 0原文

我在我的笔记本电脑(emacs 23.3)上定制了我的模式行,它运行得很好。

但是,当我尝试让它在学校的桌面上运行(emacs 21.4)时,使用 Ctrl-fCtrl-bCtrl-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

可爱暴击 2024-12-26 14:10:46

在原始帖子的评论中,您在模式行中提到了您想要的以下信息:

  1. 修改或只读
  2. 列/行号
  3. 缓冲区名称
  4. 距离页面顶部有多远
  5. 主要模式
  6. 当前时间

我使用的 emacs 永远并且所有 (1)、(3) 和 (5) 已经在每个缓冲区的默认 emacs 模式行中,并且已经存在很长时间了。要启用 (2) 和 (6),请添加

(display-time-mode 1)
(setq line-number-mode t)
(setq column-number-mode t)

~/.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:

  1. modified or read only
  2. column / line number
  3. buffer name
  4. how far from the top of the page I am
  5. major mode
  6. current time

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

(display-time-mode 1)
(setq line-number-mode t)
(setq column-number-mode t)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文