Skip to content

Commit 3ab1722

Browse files
committed
Improve lsp--buffer-string-visible performance, avoide headvy generate-new-buffer
1 parent 09f16c7 commit 3ab1722

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

lsp-mode.el

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5554,23 +5554,21 @@ MODE is the mode used in the parent frame."
55545554
(goto-char end))))))
55555555

55565556
(defun lsp--buffer-string-visible ()
5557-
"Return visible buffer string.
5558-
Stolen from `org-copy-visible'."
5559-
(let ((temp (generate-new-buffer " *temp*"))
5560-
(beg (point-min))
5561-
(end (point-max)))
5562-
(while (/= beg end)
5563-
(when (get-char-property beg 'invisible)
5564-
(setq beg (next-single-char-property-change beg 'invisible nil end)))
5565-
(let* ((next (next-single-char-property-change beg 'invisible nil end))
5566-
(substring (buffer-substring beg next)))
5567-
(with-current-buffer temp (insert substring))
5568-
;; (setq result (concat result substring))
5569-
(setq beg next)))
5570-
(setq deactivate-mark t)
5571-
(prog1 (with-current-buffer temp
5572-
(s-chop-suffix "\n" (buffer-string)))
5573-
(kill-buffer temp))))
5557+
"Return a string of the buffer's visible text."
5558+
(let ((beg (point-min))
5559+
(end (point-max))
5560+
(parts '()))
5561+
(while (< beg end)
5562+
(when (get-char-property beg 'invisible)
5563+
(setq beg (next-single-char-property-change beg 'invisible nil end)))
5564+
(let ((next (next-single-char-property-change beg 'invisible nil end)))
5565+
(push (buffer-substring-no-properties beg next) parts)
5566+
(setq beg next)))
5567+
(setq parts (nreverse parts))
5568+
(let ((result (apply #'concat parts)))
5569+
(if (string-suffix-p "\n" result)
5570+
(substring result 0 -1)
5571+
result))))
55745572

55755573
(defvar lsp-buffer-major-mode nil
55765574
"Holds the major mode when fontification function is running.

0 commit comments

Comments
 (0)