-
Notifications
You must be signed in to change notification settings - Fork 55
/
jdee-bookmark.el
113 lines (94 loc) · 4 KB
/
jdee-bookmark.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
;;; jdee-bookmark.el -- Organize bookmarked classes.
;; Author: Paul Landes <landes <at> mailc dt net>
;; Maintainer: Paul Landes
;; Keywords: java bookmark
;; Copyright (C) 2009 by Paul Landes
;; GNU Emacs 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 2, or (at your option)
;; any later version.
;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Like bookmark.el but classes are bookmarked instead of files. No file
;; information is kept, everything uses JDEE project information to find
;; bookmarked classes.
;;; Code:
(require 'jdee-parse)
(require 'jdee-util)
(defgroup jdee-bookmark nil
"JDEE Bookmarks"
:group 'jdee
:prefix "jdee-bookmark-")
(defcustom jdee-bookmark-class-bookmarks nil
"*A list of fully qualified class names to quickly visit.
Function `jdee-find-class-source' is used to visit these Java source files (see
`jdee-bookmark-visit')."
:group 'jdee-bookmark
:type '(repeat (cons :tag "Entry"
(string :tag "Name")
(string :tag "Class"))))
(defvar jdee-bookmark-history nil
"History item list for `jdee-bookmark-prompt'.")
(defun jdee-bookmark-prompt (&optional prompt)
(let ((default (car jdee-bookmark-history)))
(setq prompt (or prompt
(format "Class%s"
(if default
(format " (default %s): " default)
": "))))
(completing-read prompt
(mapcar #'car jdee-bookmark-class-bookmarks)
nil t nil 'jdee-bookmark-history
(car jdee-bookmark-history))))
(defun jdee-bookmark-class (key)
(cdr (assoc key jdee-bookmark-class-bookmarks)))
;;;###autoload
(defun jdee-bookmark-visit (key)
"Visit a class by bookmark name."
(interactive (list (jdee-bookmark-prompt)))
(let ((class (jdee-bookmark-class key)))
(message (format "Finding class `%s'..." class))
(jdee-find-class-source class)))
;;;###autoload
(defun jdee-bookmark-add (key &optional fq-class)
"Add the current visited class as a bookmark."
(interactive
(list (read-string "Class entry: " (jdee-parse-get-buffer-class t))))
(jdee-assert-mode)
(setq fq-class (or fq-class (jdee-parse-get-buffer-class)))
(message (format "Adding bookmark `%s' as class `%s'"
key fq-class))
(customize-save-variable 'jdee-bookmark-class-bookmarks
(append jdee-bookmark-class-bookmarks
(list (cons key fq-class)))))
;;;###autoload
(defun jdee-bookmark-list ()
"List bookmarks."
(interactive)
;; a more dynamnic display is needed, like what's currently in bookmark.el
;; would be nice
(let ((max-name-len (apply #'max
(mapcar #'(lambda (arg)
(length (car arg)))
jdee-bookmark-class-bookmarks))))
(with-current-buffer (get-buffer-create "*JDEE Bookmarks*")
(setq buffer-read-only nil)
(erase-buffer)
(dolist (entry jdee-bookmark-class-bookmarks)
(insert (format "%s:%s%s\n"
(car entry)
(make-string (+ 1 (- max-name-len
(length (car entry)))) ? )
(cdr entry))))
(setq buffer-read-only t)
(set-buffer-modified-p nil)
(display-buffer (current-buffer)))))
(provide 'jdee-bookmark)
;;; jdee-bookmark.el ends here