我用 hide-show折叠我的文本的某些部分,我使用下面的代码来显示隐藏行的数量。
但是,当文件足够大(例如 C++ 或 LaTeX)并且我折叠了所有区域(从而创建了数十个叠加层)时,Emacs 会变得非常慢,以至于无法使用。即使将标记从一行移动到另一行也需要半秒左右。
有没有办法解决这个问题?
(defun display-code-line-counts (ov)
(overlay-put ov 'display
(format "...%d..."
(count-lines (overlay-start ov)
(overlay-end ov))
))
(overlay-put ov 'face '(:foreground "red" :box (:line-width 1 :style none)))
)
(setq hs-set-up-overlay 'display-code-line-counts)
编辑:原来 emacs 变得非常慢的原因是因为 linum 次要模式创建了数千个(隐藏)叠加层,这些叠加层被隐藏显示折叠。有没有办法来解决这个问题?或者更好的行号模式?
最佳答案
正如您在标题中所说的,叠加会使 Emacs 变慢。
您可以做的一件事(有时会有所帮助)是围绕当前光标位置 ( point
) 重新调整叠加层集。你这样做使用功能
overlay-recenter
.
作为 Elisp 手册,节点 Managing Overlays告诉你:
This function recenters the overlays of the current buffer around position
POS
. That makes overlay lookup faster for positions nearPOS
, but slower for positions far away fromPOS
.A loop that scans the buffer forwards, creating overlays, can run faster if you do
(overlay-recenter (point-max))
first.
关于performance - 覆盖使 emacs 真的很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42023872/