Skip to content

Commit

Permalink
cider-doc now renders spec using cider-browse-spec--pprint-indented
Browse files Browse the repository at this point in the history
There is also a button to jump to the browser
  • Loading branch information
jpmonettas committed Jan 9, 2018
1 parent 49f5775 commit 32c6243
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changes

* [#2029](https://github.com/clojure-emacs/cider/pull/2154) Make cider-doc use cider-browse-spec functionality to print the spec part of the doc buffer
* [#2151](https://github.com/clojure-emacs/cider/pull/2151) Improve formatting of spec in `cider-doc` buffer.

## 0.16.0 (2017-12-28)
Expand Down
27 changes: 18 additions & 9 deletions cider-browse-spec.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

(require 'cider-client)
(require 'cider-compat)
(require 'cider-interaction)
(require 'cider-util)
(require 'cl-lib)
(require 'nrepl-dict)
Expand Down Expand Up @@ -233,16 +232,31 @@ Display TITLE at the top and SPECS are indented underneath."
;; prettier (s/fspec )
((cider--spec-fn-p form-tag "fspec")
(thread-last (seq-partition (cl-rest form) 2)
(cl-remove-if (lambda (s) (and (stringp (cl-second s))
(string-empty-p (cl-second s)))))
(mapcar (lambda (s)
(concat "\n" (cl-first s) " " (cider-browse-spec--pprint (cl-second s)))))
(format "\n%-11s: %s" (pcase (cl-first s)
(":args" "arguments")
(":ret" "returns")
(":fn" "invariants"))
(cider-browse-spec--pprint (cl-second s)))))
(cl-reduce #'concat)
(format "(s/fspec \n %s)")))
(format "%s")))
;; every other with no special management
(t (format "(%s %s)"
(cider-browse-spec--pprint form-tag)
(string-join (mapcar #'cider-browse-spec--pprint (cl-rest form)) " "))))))
(t (format "%s" form))))

(defun cider-browse-spec--pprint-indented (spec-form)
"Given a SPEC-FORM returns a string with it pretty printed, indented and clojure font locked."
(with-temp-buffer
(clojure-mode)
(insert (cider-browse-spec--pprint spec-form))
(indent-region (point-min) (point-max))
(cider--font-lock-ensure)
(buffer-string)))

(defun cider-browse-spec--draw-spec-buffer (buffer spec spec-form)
"Reset contents of BUFFER and draws everything needed to browse the SPEC-FORM.
Display SPEC as a title and uses `cider-browse-spec--pprint' to display
Expand All @@ -252,12 +266,7 @@ a more user friendly representation of SPEC-FORM."
(cider--help-setup-xref (list #'cider-browse-spec spec) nil buffer)
(goto-char (point-max))
(insert (cider-font-lock-as-clojure spec) "\n\n")
(insert (with-temp-buffer
(clojure-mode)
(insert (cider-browse-spec--pprint spec-form))
(indent-region (point-min) (point-max))
(cider--font-lock-ensure)
(buffer-string)))
(insert (cider-browse-spec--pprint-indented spec-form))
(cider--make-back-forward-xrefs)
(current-buffer))))

Expand Down
21 changes: 9 additions & 12 deletions cider-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(require 'org-table)
(require 'button)
(require 'easymenu)
(require 'cider-browse-spec)


;;; Variables
Expand Down Expand Up @@ -461,18 +462,14 @@ Tables are marked to be ignored by line wrap."
(insert ".\n"))
(insert "\n")
(when spec
(emit "Spec: " 'font-lock-function-name-face)
(dolist (part spec)
(let ((role (car part))
(desc (cadr part)))
(insert (format "%-4s: " role))
(thread-first desc
cider-sync-request:format-code
cider-font-lock-as-clojure
(split-string "\n")
insert-rectangle))
(insert "\n"))
(insert "\n"))
(emit "Spec:" 'font-lock-function-name-face)
(insert (cider-browse-spec--pprint-indented spec))
(insert "\n\n")
(insert-text-button "Browse spec"
'follow-link t
'action (lambda (x)
(cider-browse-spec (format "%s/%s" ns name))))
(insert "\n\n"))
(if cider-docview-file
(progn
(insert (propertize (if class java-name clj-name)
Expand Down

0 comments on commit 32c6243

Please sign in to comment.