branch: elpa/cider
commit 9c1975ee67d080bc768046b698251a02f4422a17
Author: Kato Muso <m...@katomuso.io>
Commit: Bozhidar Batsov <bozhi...@batsov.dev>

    Refactor code used to insert sections into ClojureDocs buffer
---
 cider-clojuredocs.el | 93 +++++++++++++++++++++++++++++++++-------------------
 1 file changed, 60 insertions(+), 33 deletions(-)

diff --git a/cider-clojuredocs.el b/cider-clojuredocs.el
index c2b10cd1ad..cfdda9ad38 100644
--- a/cider-clojuredocs.el
+++ b/cider-clojuredocs.el
@@ -109,42 +109,69 @@ opposite of what that option dictates."
     (goto-char (point-min))
     (current-buffer)))
 
+(defun cider-clojuredocs--insert-overview (dict)
+  "Insert \"Overview\" section based on data from DICT."
+  (insert (format "= %s/%s\n"
+                  (nrepl-dict-get dict "ns")
+                  (nrepl-dict-get dict "name")))
+  (newline)
+  (when-let ((arglists (nrepl-dict-get dict "arglists")))
+    (dolist (arglist arglists)
+      (insert (format " [%s]\n" arglist)))
+    (newline))
+  (when-let* ((doc (nrepl-dict-get dict "doc"))
+              ;; As this is a literal docstring from the source code and
+              ;; there are two spaces at the beginning of lines in docstrings,
+              ;; we remove them to make it align nicely in ClojureDocs buffer.
+              (doc (replace-regexp-in-string "\n  " "\n" doc)))
+    (insert doc "\n")
+    (newline)))
+
+(defun cider-clojuredocs--insert-see-also (dict)
+  "Insert \"See Also\" section based on data from DICT."
+  (insert "== See Also\n")
+  (newline)
+  (if-let ((see-alsos (nrepl-dict-get dict "see-alsos")))
+      (dolist (see-also see-alsos)
+        (insert "* ")
+        (insert-text-button see-also
+                            'sym see-also
+                            'action (lambda (btn)
+                                      (cider-clojuredocs-lookup (button-get 
btn 'sym)))
+                            'help-echo (format "Press Enter or middle click to 
jump to %s" see-also))
+        (insert "\n"))
+    (insert "Not available\n"))
+  (newline))
+
+(defun cider-clojuredocs--insert-examples (dict)
+  "Insert \"Examples\" section based on data from DICT."
+  (insert "== Examples\n")
+  (newline)
+  (if-let ((examples (nrepl-dict-get dict "examples")))
+      (dolist (example examples)
+        (insert (cider-font-lock-as-clojure example) "\n")
+        (insert "-------------------------------------------------\n"))
+    (insert "Not available\n"))
+  (newline))
+
+(defun cider-clojuredocs--insert-notes (dict)
+  "Insert \"Notes\" section based on data from DICT."
+  (insert "== Notes\n")
+  (newline)
+  (if-let ((notes (nrepl-dict-get dict "notes")))
+      (dolist (note notes)
+        (insert note "\n")
+        (insert "-------------------------------------------------\n"))
+    (insert "Not available\n"))
+  (newline))
+
 (defun cider-clojuredocs--content (dict)
   "Generate a nice string from DICT."
   (with-temp-buffer
-    (insert "= " (nrepl-dict-get dict "ns") "/" (nrepl-dict-get dict "name") 
"\n\n")
-    (let ((arglists (nrepl-dict-get dict "arglists")))
-      (dolist (arglist arglists)
-        (insert (format " [%s]\n" arglist)))
-      (when-let* ((doc (nrepl-dict-get dict "doc"))
-                  ;; As this is a literal docstring from the source code and
-                  ;; there are two spaces at the beginning of lines in 
docstrings,
-                  ;; we remove them to make it align nicely in ClojureDocs 
buffer.
-                  (doc (replace-regexp-in-string "\n  " "\n" doc)))
-        (insert "\n" doc "\n")))
-    (insert "\n== See Also\n\n")
-    (if-let ((see-alsos (nrepl-dict-get dict "see-alsos")))
-        (dolist (see-also see-alsos)
-          (insert "* ")
-          (insert-text-button see-also
-                              'sym see-also
-                              'action (lambda (btn)
-                                        (cider-clojuredocs-lookup (button-get 
btn 'sym)))
-                              'help-echo (format "Press Enter or middle click 
to jump to %s" see-also))
-          (insert "\n"))
-      (insert "Not available\n"))
-    (insert "\n== Examples\n\n")
-    (if-let ((examples (nrepl-dict-get dict "examples")))
-        (dolist (example examples)
-          (insert (cider-font-lock-as-clojure example))
-          (insert "\n-------------------------------------------------\n"))
-      (insert "Not available\n"))
-    (insert "\n== Notes\n\n")
-    (if-let ((notes (nrepl-dict-get dict "notes")))
-        (dolist (note notes)
-          (insert note)
-          (insert "\n-------------------------------------------------\n"))
-      (insert "Not available\n"))
+    (cider-clojuredocs--insert-overview dict)
+    (cider-clojuredocs--insert-see-also dict)
+    (cider-clojuredocs--insert-examples dict)
+    (cider-clojuredocs--insert-notes dict)
     (buffer-string)))
 
 (defun cider-clojuredocs-lookup (sym)

Reply via email to