summaryrefslogtreecommitdiff
path: root/cider-browse-ns.el
diff options
context:
space:
mode:
authormallt <mallt@users.noreply.github.com>2016-05-30 00:21:35 +0200
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2016-05-30 01:21:35 +0300
commitfca597a2964fd13cfba17220ebf45786502d8f1c (patch)
tree82fab0cf16f5acd405b344c2b531fe6b6068a775 /cider-browse-ns.el
parentafd5549baa005b9f7ad5652f18288f8a37ade306 (diff)
[Fix #1577] Show first line of docstring in ns browser (#1757)
Diffstat (limited to 'cider-browse-ns.el')
-rw-r--r--cider-browse-ns.el30
1 files changed, 27 insertions, 3 deletions
diff --git a/cider-browse-ns.el b/cider-browse-ns.el
index 14c81c64..d4963878 100644
--- a/cider-browse-ns.el
+++ b/cider-browse-ns.el
@@ -114,6 +114,31 @@ contents of the buffer are not reset before inserting TITLE and ITEMS."
'cider-browse-ns-current-ns ns)))
(goto-char (point-min)))))
+(defun cider-browse-ns--first-doc-line (doc)
+ "Return the first line of the given DOC string.
+If the first line of the DOC string contains multiple sentences, only
+the first sentence is returned. If the DOC string is nil, a Not documented
+string is returned."
+ (if doc
+ (let* ((split-newline (split-string (read doc) "\n"))
+ (first-line (car split-newline)))
+ (cond
+ ((string-match "\\. " first-line) (substring first-line 0 (match-end 0)))
+ ((= 1 (length split-newline)) first-line)
+ (t (concat first-line "..."))))
+ "Not documented."))
+
+(defun cider-browse-ns--items (namespace)
+ "Return the items to show in the namespace browser of the given NAMESPACE.
+Each item consists of a ns-var and the first line of its docstring."
+ (let* ((ns-vars-with-meta (cider-sync-request:ns-vars-with-meta namespace))
+ (propertized-ns-vars (nrepl-dict-map #'cider-browse-ns--properties ns-vars-with-meta)))
+ (mapcar (lambda (ns-var)
+ (let* ((doc (nrepl-dict-get-in ns-vars-with-meta (list ns-var "doc")))
+ (first-doc-line (cider-browse-ns--first-doc-line doc)))
+ (concat ns-var " " (propertize first-doc-line 'font-lock-face 'font-lock-doc-face))))
+ propertized-ns-vars)))
+
;; Interactive Functions
;;;###autoload
@@ -123,8 +148,7 @@ contents of the buffer are not reset before inserting TITLE and ITEMS."
(with-current-buffer (cider-popup-buffer cider-browse-ns-buffer t)
(cider-browse-ns--list (current-buffer)
namespace
- (nrepl-dict-map #'cider-browse-ns--properties
- (cider-sync-request:ns-vars-with-meta namespace)))
+ (cider-browse-ns--items namespace))
(setq-local cider-browse-ns-current-ns namespace)))
;;;###autoload
@@ -143,7 +167,7 @@ contents of the buffer are not reset before inserting TITLE and ITEMS."
(defun cider-browse-ns--thing-at-point ()
"Get the thing at point.
Return a list of the type ('ns or 'var) and the value."
- (let ((line (cider-string-trim (thing-at-point 'line))))
+ (let ((line (car (split-string (cider-string-trim (thing-at-point 'line)) " "))))
(if (string-match "\\." line)
(list 'ns line)
(list 'var (format "%s/%s"