Overlays make emacs very slow

I use hide-show to collapse some parts of my text, and I use the code below to show the number of hidden lines.

However, when the file is large enough (e.g. C ++ or LaTeX) and I destroy all regions (thus creating dozens of overlays), Emacs becomes very slow to the point of being unusable. Even moving a marker from one line to another takes half a second or so.

Is there any way to resolve this?

(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)

EDIT: It turns out the reason emacs gets really slow is caused by the small linum mode, which creates thousands of (hidden) overlays that crashed with hide-show. Is there any way to fix this? Or the best line number mode?

+4
1

, Emacs.

, , , (point). , overlay-recenter.

Elisp, node :

      POS.      POS, POS.

, , , , (overlay-recenter (point-max)).

+3

Source: https://habr.com/ru/post/1668729/


All Articles