gpt4 book ai didi

Emacs 右边距的相对行号

转载 作者:行者123 更新时间:2023-12-01 19:55:33 24 4
gpt4 key购买 nike

是否可以在 Emacs 缓冲区的右侧边缘显示相对行号,并在左侧边缘保留正常行号?

最佳答案

这可以作为一个起点。加载此定义并执行 M-x linum-mode

(defun linum-relative-right-set-margin ()
"Make width of right margin the same as left margin"
(let* ((win (get-buffer-window))
(width (car (window-margins win))))
(set-window-margins win width width)))

(defadvice linum-update-current (after linum-left-right-update activate)
"Advice to run right margin update"
(linum-relative-right-set-margin)
(linum-relative-right-update (line-number-at-pos)))

(defadvice linum-delete-overlays (after linum-relative-right-delete activate)
"Set margins width to 0"
(set-window-margins (get-buffer-window) 0 0))

(defun linum-relative-right-update (line)
"Put relative numbers to the right margin"
(dolist (ov (overlays-in (window-start) (window-end)))
(let ((str (overlay-get ov 'linum-str)))
(if str
(let ((nstr (number-to-string
(abs (- (string-to-number str) line)))))
;; copy string properties
(set-text-properties 0 (length nstr) (text-properties-at 0 str) nstr)
(overlay-put ov 'after-string
(propertize " " 'display `((margin right-margin) ,nstr))))))))

看截图

emacs screenshot

关于Emacs 右边距的相对行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612364/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com