-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Split cider-docstring--dumb-trim
into two single-purpose functions
#3708
Conversation
To easily verify that it doesn't change the output, you can use the following snippet: (let* ((info (cider-var-info "clojure.core/reduce"))
(doc (nrepl-dict-get info "doc")))
(string= (cider-docstring--dumb-trim doc)
(cider-docstring--trim (cider-docstring--format doc)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I appreciate starting over more cleanly.
(cl-defun cider-docstring--trim (string &optional (max-lines cider-docstring-max-lines)) | ||
"Return MAX-LINES of STRING, adding \"...\" if trimming was necessary." | ||
(let* ((lines (split-string string "\n")) | ||
(string (string-join (seq-take lines max-lines) "\n"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nil value for the second argument of seq-take
appears to be undocumented, so I'd prefer to have an explicit default for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean if the max-lines
argument is nil
, right? Well, I don't really think there should be a default value because it should always be a number, but if anything, I think it should just return the input string
if max-lines
is nil
.
(if (> lines-length n) | ||
(concat result "...") | ||
result)))) | ||
(cl-defun cider-docstring--trim (string &optional (max-lines cider-docstring-max-lines)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cider-docstring-max-lines is unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of cider-docstring-max-lines
is the default for max-lines
if max-lines
is not specified explicitly, so there is no need to use it in the body. So, if we call cider-docstring--trim
without a second argument, cider-docstring-max-lines
is used, right? So I'm not sure what you mean by saying that cider-docstring-max-lines
is unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok! I wasn't immediately familar with that cl-defun syntax.
Thanks! |
The function
cider-docstring--dumb-trim
performs both formatting and trimming. I propose splitting it into two separate functions:cider-docstring--trim
andcider-docstring--format
because these two functionalities are needed in different contexts. For example, we need to format the docstring when displaying it in the documentation buffer, and we need to trim the docstring when displaying it in the minibuffer or in a popup along with completions.