diff options
author | Bozhidar Batsov <bozhidar@tradeo.com> | 2014-09-01 16:07:55 +0300 |
---|---|---|
committer | Bozhidar Batsov <bozhidar@tradeo.com> | 2014-09-01 16:07:55 +0300 |
commit | f43a272d6dca186cedf915eaaaee496083d0c619 (patch) | |
tree | 040ed4858b1dc342d3d78da8b36194eacabe00cd /cider-classpath.el | |
parent | d8d3db5c8a8ae73951393ab4abb4a7f46700e052 (diff) |
Add a basic Java classpath browser
Diffstat (limited to 'cider-classpath.el')
-rw-r--r-- | cider-classpath.el | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/cider-classpath.el b/cider-classpath.el new file mode 100644 index 00000000..1cf430e9 --- /dev/null +++ b/cider-classpath.el @@ -0,0 +1,103 @@ +;;; cider-classpath.el --- Basic Java classpath browser + +;; Copyright © 2014 Bozhidar Batsov + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;; This file is not part of GNU Emacs. + +;;; Commentary: + +;; Basic Java classpath browser for CIDER. + +;;; Code: + +(require 'cider-client) +(require 'cider-interaction) + +(defvar cider-classpath-buffer "*Classpath*") + +(defvar cider-classpath-mode-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map cider-popup-buffer-mode-map) + (define-key map [return] 'cider-classpath-operate-on-point) + (define-key map "n" 'next-line) + (define-key map "p" 'previous-line) + map)) + +(define-derived-mode cider-classpath-mode special-mode "classpath" + "Major mode for browsing the entries in Java's classpath. + +\\{cider-classpath-mode-map}" + (setq buffer-read-only t) + (setq-local electric-indent-chars nil) + (setq-local truncate-lines t)) + +(defun cider-classpath-list (buffer items) + "Populate BUFFER with ITEMS." + (with-current-buffer buffer + (cider-classpath-mode) + (let ((inhibit-read-only t)) + (erase-buffer) + (dolist (item items) + (insert item) + (newline)) + (goto-char (point-min))))) + +(defun cider-classpath-properties (text) + "Decorate TEXT with a clickable keymap and function face." + (let ((face (cond + ((not (file-exists-p text)) 'font-lock-warning-face) + ((file-directory-p text) 'dired-directory) + (t 'default)))) + (propertize text + 'font-lock-face face + 'mouse-face 'highlight + 'keymap cider-classpath-mouse-map))) + +(defun cider-classpath-operate-on-point () + "Expand browser according to thing at current point." + (interactive) + (let* ((bol (line-beginning-position)) + (eol (line-end-position)) + (line (buffer-substring-no-properties bol eol))) + (if (file-directory-p line) + (dired line) + (find-file-other-window line)))) + +(defun cider-classpath-handle-mouse (event) + "Handle mouse click EVENT." + (interactive "e") + (cider-classpath-operate-on-point)) + +;;;###autoload +(defun cider-classpath () + "List all classpath entries." + (interactive) + (with-current-buffer (cider-popup-buffer cider-classpath-buffer t) + (let ((names (plist-get + (nrepl-send-sync-request (list "op" "classpath" + "session" (nrepl-current-session))) + :value))) + (cider-classpath-list (current-buffer) + (mapcar (lambda (name) + (cider-classpath-properties name)) + names))))) + +(defvar cider-classpath-mouse-map (make-sparse-keymap)) +(define-key cider-classpath-mouse-map [mouse-1] 'cider-classpath-handle-mouse) + +(provide 'cider-classpath) + +;;; cider-classpath.el ends here |