Skip to content

Commit df7ca24

Browse files
committed
Inspector: render Java items using java-mode syntax coloring
Fixes #3546
1 parent 4c99c02 commit df7ca24

File tree

3 files changed

+415
-7
lines changed

3 files changed

+415
-7
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-inspector.el

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,21 +429,52 @@ MAX-COLL-SIZE if non nil."
429429

430430
(defun cider-inspector-render* (elements)
431431
"Render ELEMENTS."
432+
(setq cider-inspector-looking-at-java-p nil)
432433
(dolist (el elements)
433434
(cider-inspector-render-el* el)))
434435

436+
(defvar cider-inspector-looking-at-java-p nil)
437+
438+
(defun cider--to-java-string (s)
439+
"Given `S`, returns a propertized string with Java syntax coloring."
440+
(with-temp-buffer
441+
(insert s)
442+
(java-mode)
443+
(font-lock-ensure)
444+
(buffer-string)))
445+
446+
(defconst cider--inspector-java-headers
447+
'("--- Interfaces:" "--- Constructors:" "--- Fields:" "--- Methods:" "--- Imports:"))
448+
435449
(defun cider-inspector-render-el* (el)
436450
"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))))
451+
(let ((header-p (or (member el cider--inspector-java-headers)
452+
(and (stringp el)
453+
(string-prefix-p "--- " el)))))
454+
;; Headers reset the Java syntax coloring:
455+
(when header-p
456+
(setq cider-inspector-looking-at-java-p nil))
457+
458+
(cond ((symbolp el) (insert (symbol-name el)))
459+
((stringp el) (insert (if cider-inspector-looking-at-java-p
460+
(cider--to-java-string el)
461+
(propertize el 'font-lock-face (if header-p
462+
'font-lock-comment-face
463+
'font-lock-keyword-face)))))
464+
((and (consp el) (eq (car el) :newline))
465+
(insert "\n"))
466+
((and (consp el) (eq (car el) :value))
467+
(cider-inspector-render-value (cadr el) (cl-caddr el)))
468+
(t (message "Unrecognized inspector object: %s" el))))
469+
470+
;; Java-related headers indicate that the next elements to be rendered
471+
;; should be syntax-colored as Java:
472+
(when (member el cider--inspector-java-headers)
473+
(setq cider-inspector-looking-at-java-p t)))
444474

445475
(defun cider-inspector-render-value (value idx)
446476
"Render VALUE at IDX."
477+
(setq cider-inspector-looking-at-java-p nil)
447478
(cider-propertize-region
448479
(list 'cider-value-idx idx
449480
'mouse-face 'highlight)

0 commit comments

Comments
 (0)