Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the way cider-docstring--format performs formatting #3712

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions cider-clojuredocs.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

;;; Code:

(require 'subr-x)
(require 'url-vars)

(require 'cider-client)
(require 'cider-common)
(require 'subr-x)
(require 'cider-docstring)
(require 'cider-popup)
(require 'cider-util)

(require 'nrepl-dict)

(require 'url-vars)

(defconst cider-clojuredocs-url "https://clojuredocs.org/")

(defconst cider-clojuredocs-buffer "*cider-clojuredocs*")
Expand Down Expand Up @@ -120,10 +120,7 @@ opposite of what that option dictates."
(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)))
(doc (cider-docstring--format doc)))
(insert doc "\n")
(newline)))

Expand Down
17 changes: 9 additions & 8 deletions cider-docstring.el
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,15 @@ Prioritize rendering as much as possible while staying within `cider-docstring-m
(concat string (when (> (length lines) max-lines) "..."))))

(defun cider-docstring--format (string)
"Return a nicely formatted STRING to be displayed to the user."
(let* ((string (replace-regexp-in-string "\\. " ".\n\n" string)) ;; improve the formatting of e.g. clojure.core/reduce
(string (mapconcat (lambda (line)
;; Remove spaces at the beginning of each line, as it is common in many clojure.core defns:
(replace-regexp-in-string "\\`[ ]+" "" line))
(split-string string "\n")
"\n")))
string))
"Return a nicely formatted STRING to be displayed to the user.

We need to format the docstring before displaying it to the user
because it is obtained from the source code. For example, this means
that it usually has two spaces before each line used for indentation
\(see https://guide.clojure.style/#docstring-indentation). While displaying
the docstring to the user, we usually want to control indentation and
other aspects of the presentation, so we format it before displaying."
(replace-regexp-in-string "\n " "\n" string))

(provide 'cider-docstring)
;;; cider-docstring.el ends here
Loading