Skip to content

Commit f43a272

Browse files
author
Bozhidar Batsov
committed
Add a basic Java classpath browser
1 parent d8d3db5 commit f43a272

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ simpler to gain understanding of what you're using.
1515
* Enhance stacktrace to definition navigation to work for interactively defined vars.
1616
* New vars: `cider-to-nrepl-filename-function` and `cider-from-nrepl-filename-function`
1717
are used to translate filenames from/to the nREPL server (default Cygwin implementation provided).
18+
* Java classpath browser (`M-x cider-classpath`).
1819

1920
### Changes
2021

cider-classpath.el

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
;;; cider-classpath.el --- Basic Java classpath browser
2+
3+
;; Copyright © 2014 Bozhidar Batsov
4+
5+
;; This program is free software: you can redistribute it and/or modify
6+
;; it under the terms of the GNU General Public License as published by
7+
;; the Free Software Foundation, either version 3 of the License, or
8+
;; (at your option) any later version.
9+
10+
;; This program is distributed in the hope that it will be useful,
11+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
;; GNU General Public License for more details.
14+
15+
;; You should have received a copy of the GNU General Public License
16+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
;; This file is not part of GNU Emacs.
19+
20+
;;; Commentary:
21+
22+
;; Basic Java classpath browser for CIDER.
23+
24+
;;; Code:
25+
26+
(require 'cider-client)
27+
(require 'cider-interaction)
28+
29+
(defvar cider-classpath-buffer "*Classpath*")
30+
31+
(defvar cider-classpath-mode-map
32+
(let ((map (make-sparse-keymap)))
33+
(set-keymap-parent map cider-popup-buffer-mode-map)
34+
(define-key map [return] 'cider-classpath-operate-on-point)
35+
(define-key map "n" 'next-line)
36+
(define-key map "p" 'previous-line)
37+
map))
38+
39+
(define-derived-mode cider-classpath-mode special-mode "classpath"
40+
"Major mode for browsing the entries in Java's classpath.
41+
42+
\\{cider-classpath-mode-map}"
43+
(setq buffer-read-only t)
44+
(setq-local electric-indent-chars nil)
45+
(setq-local truncate-lines t))
46+
47+
(defun cider-classpath-list (buffer items)
48+
"Populate BUFFER with ITEMS."
49+
(with-current-buffer buffer
50+
(cider-classpath-mode)
51+
(let ((inhibit-read-only t))
52+
(erase-buffer)
53+
(dolist (item items)
54+
(insert item)
55+
(newline))
56+
(goto-char (point-min)))))
57+
58+
(defun cider-classpath-properties (text)
59+
"Decorate TEXT with a clickable keymap and function face."
60+
(let ((face (cond
61+
((not (file-exists-p text)) 'font-lock-warning-face)
62+
((file-directory-p text) 'dired-directory)
63+
(t 'default))))
64+
(propertize text
65+
'font-lock-face face
66+
'mouse-face 'highlight
67+
'keymap cider-classpath-mouse-map)))
68+
69+
(defun cider-classpath-operate-on-point ()
70+
"Expand browser according to thing at current point."
71+
(interactive)
72+
(let* ((bol (line-beginning-position))
73+
(eol (line-end-position))
74+
(line (buffer-substring-no-properties bol eol)))
75+
(if (file-directory-p line)
76+
(dired line)
77+
(find-file-other-window line))))
78+
79+
(defun cider-classpath-handle-mouse (event)
80+
"Handle mouse click EVENT."
81+
(interactive "e")
82+
(cider-classpath-operate-on-point))
83+
84+
;;;###autoload
85+
(defun cider-classpath ()
86+
"List all classpath entries."
87+
(interactive)
88+
(with-current-buffer (cider-popup-buffer cider-classpath-buffer t)
89+
(let ((names (plist-get
90+
(nrepl-send-sync-request (list "op" "classpath"
91+
"session" (nrepl-current-session)))
92+
:value)))
93+
(cider-classpath-list (current-buffer)
94+
(mapcar (lambda (name)
95+
(cider-classpath-properties name))
96+
names)))))
97+
98+
(defvar cider-classpath-mouse-map (make-sparse-keymap))
99+
(define-key cider-classpath-mouse-map [mouse-1] 'cider-classpath-handle-mouse)
100+
101+
(provide 'cider-classpath)
102+
103+
;;; cider-classpath.el ends here

0 commit comments

Comments
 (0)