performance - 覆盖使 emacs 真的很慢

标签 performance emacs show-hide

我用 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 near POS, but slower for positions far away from POS.

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/

相关文章:

javascript - 如何在 Javascript 编辑模式下隐藏页脚面板?

jquery - 选择选项时显示隐藏的 div

JavaScript:更长的键是否会使对象查找变慢?

c# - 条件运算符慢吗?

linux - clock_gettime() 是否适合亚微秒计时?

Python 代码完成

emacs - 两种 Emacs 次要模式中的键盘快捷键冲突

emacs - 组织模式下的每周回顾

python - 为什么 numpy 平方根反比 "x**(-1/2)"比 "1/np.sqrt(x)"慢这么多

jQuery toggleClass - 回到普通类(class)?