Skip to content

Commit ded24d8

Browse files
authored
Inspector: render Java items using java-mode syntax coloring (#3547)
Fixes #3546
1 parent 4c99c02 commit ded24d8

File tree

4 files changed

+407
-16
lines changed

4 files changed

+407
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Changes
6+
7+
- [#3546](https://github.com/clojure-emacs/cider/issues/3546): Inspector: render Java items using `java-mode` syntax coloring.
8+
59
### Bugs fixed
610

711
- Inspector: avoid `Symbol's value as variable is void: text-scale-mode-amount` under certain Emacs clients.

cider-docstring.el

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,11 @@
2929
(require 'cl-lib)
3030
(require 'shr)
3131

32-
(defun cider--to-java-string (s)
33-
"Convert string S to a Java-formatted string with syntax highlighting."
34-
(with-temp-buffer
35-
(insert s)
36-
(java-mode)
37-
(font-lock-ensure)
38-
(buffer-string)))
39-
4032
(defsubst cider--render-pre* (dom)
4133
"Render DOM nodes, formatting them them as Java if they are strings."
4234
(dolist (sub (dom-children dom))
4335
(if (stringp sub)
44-
(shr-insert (cider--to-java-string sub))
36+
(shr-insert (cider-font-lock-as 'java-mode sub))
4537
(shr-descend sub))))
4638

4739
(defun cider--render-pre (dom)

cider-inspector.el

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,20 +427,42 @@ MAX-COLL-SIZE if non nil."
427427
(error (insert "\nInspector error for: " str))))
428428
(goto-char (point-min))))
429429

430+
(defvar cider-inspector-looking-at-java-p nil)
431+
430432
(defun cider-inspector-render* (elements)
431433
"Render ELEMENTS."
434+
(setq cider-inspector-looking-at-java-p nil)
432435
(dolist (el elements)
433436
(cider-inspector-render-el* el)))
434437

438+
(defconst cider--inspector-java-headers
439+
'("--- Interfaces:" "--- Constructors:" "--- Fields:" "--- Methods:" "--- Imports:"))
440+
435441
(defun cider-inspector-render-el* (el)
436442
"Render EL."
437-
(cond ((symbolp el) (insert (symbol-name el)))
438-
((stringp el) (insert (propertize el 'font-lock-face 'font-lock-keyword-face)))
439-
((and (consp el) (eq (car el) :newline))
440-
(insert "\n"))
441-
((and (consp el) (eq (car el) :value))
442-
(cider-inspector-render-value (cadr el) (cl-caddr el)))
443-
(t (message "Unrecognized inspector object: %s" el))))
443+
(let ((header-p (or (member el cider--inspector-java-headers)
444+
(and (stringp el)
445+
(string-prefix-p "--- " el)))))
446+
;; Headers reset the Java syntax coloring:
447+
(when header-p
448+
(setq cider-inspector-looking-at-java-p nil))
449+
450+
(cond ((symbolp el) (insert (symbol-name el)))
451+
((stringp el) (insert (if cider-inspector-looking-at-java-p
452+
(cider-font-lock-as 'java-mode el)
453+
(propertize el 'font-lock-face (if header-p
454+
'font-lock-comment-face
455+
'font-lock-keyword-face)))))
456+
((and (consp el) (eq (car el) :newline))
457+
(insert "\n"))
458+
((and (consp el) (eq (car el) :value))
459+
(cider-inspector-render-value (cadr el) (cl-caddr el)))
460+
(t (message "Unrecognized inspector object: %s" el))))
461+
462+
;; Java-related headers indicate that the next elements to be rendered
463+
;; should be syntax-colored as Java:
464+
(when (member el cider--inspector-java-headers)
465+
(setq cider-inspector-looking-at-java-p t)))
444466

445467
(defun cider-inspector-render-value (value idx)
446468
"Render VALUE at IDX."

0 commit comments

Comments
 (0)