|
28 | 28 |
|
29 | 29 | (require 'cl-lib)
|
30 | 30 | (require 'shr)
|
| 31 | +(require 'subr-x) |
31 | 32 |
|
32 | 33 | (defsubst cider--render-pre* (dom)
|
33 | 34 | "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
|
139 | 140 | second-attempt
|
140 | 141 | first-attempt)))
|
141 | 142 |
|
142 |
| -(defun cider-docstring--dumb-trim (s &optional n) |
| 143 | +(defun cider-docstring--trim (s &optional n) |
143 | 144 | "Returns up to the first N lines of string S,
|
144 | 145 | adding \"...\" if trimming was necessary.
|
145 | 146 |
|
146 |
| -N defaults to `cider-docstring-max-lines'. |
147 |
| -
|
148 |
| -Also performs some bare-bones formatting, cleaning up some common whitespace issues." |
| 147 | +N defaults to `cider-docstring-max-lines'." |
149 | 148 | (when s
|
150 |
| - (let* ((s (replace-regexp-in-string "\\. " ".\n\n" s)) ;; improve the formatting of e.g. clojure.core/reduce |
151 |
| - (n (or n cider-docstring-max-lines)) |
| 149 | + (let* ((n (or n cider-docstring-max-lines)) |
152 | 150 | (lines (split-string s "\n"))
|
153 | 151 | (lines-length (length lines))
|
154 | 152 | (selected-lines (cl-subseq lines 0 (min n lines-length)))
|
| 153 | + (result (string-join selected-lines "\n"))) |
| 154 | + (if (> lines-length n) |
| 155 | + (concat result "...") |
| 156 | + result)))) |
| 157 | + |
| 158 | +(defun cider-docstring--format (s) |
| 159 | + "Performs formatting of S, cleaning up some common whitespace issues." |
| 160 | + (when s |
| 161 | + (let* ((s (replace-regexp-in-string "\\. " ".\n\n" s)) ;; improve the formatting of e.g. clojure.core/reduce |
| 162 | + (lines (split-string s "\n")) |
155 | 163 | (result (mapconcat (lambda (f)
|
156 | 164 | ;; Remove spaces at the beginning of each line, as it is common in many clojure.core defns:
|
157 | 165 | (replace-regexp-in-string "\\`[ ]+" "" f))
|
158 |
| - selected-lines |
| 166 | + lines |
159 | 167 | "\n")))
|
160 |
| - (if (> lines-length n) |
161 |
| - (concat result "...") |
162 |
| - result)))) |
| 168 | + result))) |
163 | 169 |
|
164 | 170 | (provide 'cider-docstring)
|
165 | 171 | ;;; cider-docstring.el ends here
|
0 commit comments