diff options
author | Bozhidar Batsov <bozhidar@tradeo.com> | 2014-06-06 12:46:26 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@tradeo.com> | 2014-06-06 12:46:26 +0300 |
commit | 4e8ec7d2b3f01a59207c4efb0998010b67d46978 (patch) | |
tree | f394011545df5d0d47b530958a54ce91d438cfe6 /cider-util.el | |
parent | 4d1ea2effcd1d99435b0051a0b74d706cfc813b6 (diff) |
Some work in progress on a more efficient way to fontify a region as Clojure code
Diffstat (limited to 'cider-util.el')
-rw-r--r-- | cider-util.el | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cider-util.el b/cider-util.el index 9af18cb5..04b1fbba 100644 --- a/cider-util.el +++ b/cider-util.el @@ -87,6 +87,43 @@ Unless you specify a BUFFER it will default to the current one." "Font-lock STRING as Clojure code." (cider-font-lock-as 'clojure-mode string)) +;; More efficient way to fontify a region, without having to delete it +;; Unfortunately still needs work, since the font-locking code in clojure-mode +;; is pretty convoluted +(defun cider-fontify-region + (beg end keywords syntax-table syntactic-keywords syntax-propertize-fn) + "Fontify a region between BEG and END using another mode's fontification. + +KEYWORDS, SYNTAX-TABLE, SYNTACTIC-KEYWORDS and +SYNTAX-PROPERTIZE-FN are the values of that mode's +`font-lock-keywords', `font-lock-syntax-table', +`font-lock-syntactic-keywords', and `syntax-propertize-function' +respectively." + (save-excursion + (save-match-data + (let ((font-lock-keywords keywords) + (font-lock-syntax-table syntax-table) + (font-lock-syntactic-keywords syntactic-keywords) + (syntax-propertize-function syntax-propertize-fn) + (font-lock-multiline 'undecided) + (font-lock-dont-widen t) + font-lock-keywords-only + font-lock-extend-region-functions + font-lock-keywords-case-fold-search) + (save-restriction + (narrow-to-region (1- beg) end) + ;; font-lock-fontify-region apparently isn't inclusive, + ;; so we have to move the beginning back one char + (font-lock-fontify-region (1- beg) end)))))) + +(defun cider-fontify-region-as-clojure (beg end) + "Use Clojure's font-lock variables to fontify the region between BEG and END." + (cider-fontify-region beg end + clojure-font-lock-keywords + clojure-mode-syntax-table + nil + nil)) + (defun cider-format-pprint-eval (form) "Return a string of Clojure code that will eval and pretty-print FORM." (format "(let [x %s] (clojure.pprint/pprint x) x)" form)) |