branch: elpa/cider
commit 78cff168ac780d0e40d1514147acf985900a1984
Author: Kato Muso <m...@katomuso.io>
Commit: Kato Muso <m...@katomuso.io>

    Split cider-docstring--dumb-trim into two single-purpose functions
---
 cider-doc.el       |  3 ++-
 cider-docstring.el | 26 ++++++++++++++++----------
 cider-eldoc.el     |  4 +++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/cider-doc.el b/cider-doc.el
index 88a4ac17ff..addfdeb829 100644
--- a/cider-doc.el
+++ b/cider-doc.el
@@ -429,7 +429,8 @@ in a COMPACT format is specified, FOR-TOOLTIP if specified."
          (fetched-doc (nrepl-dict-get info "doc"))
          (doc     (or rendered-fragments
                       (if compact
-                          (cider-docstring--dumb-trim fetched-doc)
+                          (cider-docstring--trim
+                           (cider-docstring--format fetched-doc))
                         fetched-doc)
                       (unless compact
                         "Not documented.")))
diff --git a/cider-docstring.el b/cider-docstring.el
index 0b3ceebaab..6a176631fb 100644
--- a/cider-docstring.el
+++ b/cider-docstring.el
@@ -28,6 +28,7 @@
 
 (require 'cl-lib)
 (require 'shr)
+(require 'subr-x)
 
 (defsubst cider--render-pre* (dom)
   "Render DOM nodes, formatting them them as Java if they are strings."
@@ -139,27 +140,32 @@ Prioritize rendering as much as possible while staying 
within `cider-docstring-m
         second-attempt
         first-attempt)))
 
-(defun cider-docstring--dumb-trim (s &optional n)
+(defun cider-docstring--trim (s &optional n)
   "Returns up to the first N lines of string S,
 adding \"...\" if trimming was necessary.
 
-N defaults to `cider-docstring-max-lines'.
-
-Also performs some bare-bones formatting, cleaning up some common whitespace 
issues."
+N defaults to `cider-docstring-max-lines'."
   (when s
-    (let* ((s (replace-regexp-in-string "\\.  " ".\n\n" s)) ;; improve the 
formatting of e.g. clojure.core/reduce
-           (n (or n cider-docstring-max-lines))
+    (let* ((n (or n cider-docstring-max-lines))
            (lines (split-string s "\n"))
            (lines-length (length lines))
            (selected-lines (cl-subseq lines 0 (min n lines-length)))
+           (result (string-join selected-lines "\n")))
+      (if (> lines-length n)
+          (concat result "...")
+        result))))
+
+(defun cider-docstring--format (s)
+  "Performs formatting of S, cleaning up some common whitespace issues."
+  (when s
+    (let* ((s (replace-regexp-in-string "\\.  " ".\n\n" s)) ;; improve the 
formatting of e.g. clojure.core/reduce
+           (lines (split-string s "\n"))
            (result (mapconcat (lambda (f)
                                 ;; Remove spaces at the beginning of each 
line, as it is common in many clojure.core defns:
                                 (replace-regexp-in-string "\\`[ ]+" "" f))
-                              selected-lines
+                              lines
                               "\n")))
-      (if (> lines-length n)
-          (concat result "...")
-        result))))
+      result)))
 
 (provide 'cider-docstring)
 ;;; cider-docstring.el ends here
diff --git a/cider-eldoc.el b/cider-eldoc.el
index f0ceeec8b7..4c094b06c0 100644
--- a/cider-eldoc.el
+++ b/cider-eldoc.el
@@ -218,7 +218,9 @@ information."
          (symbol (lax-plist-get eldoc-info "symbol"))
          (docstring (or (cider--render-docstring-first-sentence eldoc-info)
                         (cider--render-docstring eldoc-info)
-                        (cider-docstring--dumb-trim (lax-plist-get eldoc-info 
"docstring"))))
+                        (cider-docstring--trim
+                         (cider-docstring--format
+                          (lax-plist-get eldoc-info "docstring")))))
          ;; if it's a single class (and not multiple class candidates), that's 
it
          (maybe-class (car (lax-plist-get eldoc-info "class")))
          (formatted-var (or (when maybe-class

Reply via email to