diff options
author | Bozhidar Batsov <bozhidar@batsov.com> | 2015-08-09 11:00:28 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@batsov.com> | 2015-08-09 11:00:28 +0300 |
commit | 6d70bcc20ac11049cff0385420dd7de6b1d88e40 (patch) | |
tree | c458410243ab76710cf993f8d8d58f39a9bb9e2d /cider-util.el | |
parent | a84e2c10a7571a219e90a669386a82a2d064d8da (diff) |
[Fix #1079] Don't font-lock very long results
Font-locking extremely long strings is pretty slow (and might generate
errors in some cases), so it's now conditional. This behavior is
adjustable via `cider-font-lock-max-length`.
Diffstat (limited to 'cider-util.el')
-rw-r--r-- | cider-util.el | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/cider-util.el b/cider-util.el index 429e6797..8e7c0b3b 100644 --- a/cider-util.el +++ b/cider-util.el @@ -34,6 +34,9 @@ (require 'cl-lib) (require 'clojure-mode) +(defconst cider-font-lock-max-length 10000 + "The max length of strings to fontify in `cider-font-lock-as'.") + (defun cider-util--hash-keys (hashtable) "Return a list of keys in HASHTABLE." (let ((keys '())) @@ -83,15 +86,17 @@ PROP is the name of a text property." (defun cider-font-lock-as (mode string) "Use MODE to font-lock the STRING." - (with-temp-buffer - (insert string) - ;; suppress major mode hooks as we care only about their font-locking - ;; otherwise modes like whitespace-mode and paredit might interfere - (setq-local delay-mode-hooks t) - (setq delayed-mode-hooks nil) - (funcall mode) - (font-lock-ensure) - (buffer-string))) + (if (< (length string) cider-font-lock-max-length) + (with-temp-buffer + (insert string) + ;; suppress major mode hooks as we care only about their font-locking + ;; otherwise modes like whitespace-mode and paredit might interfere + (setq-local delay-mode-hooks t) + (setq delayed-mode-hooks nil) + (funcall mode) + (font-lock-ensure) + (buffer-string)) + string)) (defun cider-font-lock-region-as (mode beg end &optional buffer) "Use MODE to font-lock text between BEG and END. |