Skip to content

Conversation

@slackline
Copy link

Closes #19

Finally remembered to finish this off, sorry its taken so long.

Adds the suggested numpydoc-newline-after-opening-quotes as a custom boolean variable with a default of t (as suggested) to the numpydoc group.

This is then used in numpydoc--insert-short-and-long-desc to conditionally insert a new line as per validation rule GL01.

Adds `numpydoc-newline-after-opening-quotes` as a custom boolean variable with a default of `t` to the `numpydoc` group.

This is then used in `numpydoc--insert-short-and-long-desc` to conditionally insert a new line as per [validation rule
GL01](https://numpydoc.readthedocs.io/en/latest/validation.html#built-in-validation-checks).
@slackline
Copy link
Author

Wondering if I need to update/modify any tests on this for it to be merged?

Copy link
Owner

@douglasdavis douglasdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is behavior changing for the package I'd prefer to keep the new defcustom as nil by default.

(numpydoc--insert indent
(concat (make-string 3 numpydoc-quote-char)
(if numpydoc-newline-after-opening-quotes
"\n ")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does numpydoc--insert with indent not take care of the extra spaces? (I haven't tested the code so I'm asking here)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean indenting to align with the docstring indent i.e. there may be no need for the spaces after the carriage return?

Suggested change
"\n ")
"\n")

Not sure, I'll check it out and report back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked this, if the spaces aren't there then the text isn't indented to align with the start of the """ so I think they are required, but appreciate there is likely a smarter way of doing this.

Looking at the code (not being very conversant in Emacs Lisp) it looks like its numpydoc--insert that is required.

I tried adding

Suggested change
"\n ")
"\n"
(numpydoc--insert indent ld))

..without any success, insert Short Description was at the start of the line. Then I realised there is numpydoc--insert-short-and-long-desc defined right after numpydoc--insert which only takes indent as an argument so tried...

Suggested change
"\n ")
"\n"
(numpydoc--insert-short-and-long-desc indent))

Next I tried placing it outside if the surrounding (if numpydoc-newline-afer-opening-quote-char "\n")

Suggested change
"\n ")
"\n")
(numpydoc--insert-short-and-long-desc indent)

...which didn't work either, it resulted in exceeding the nesting max-lisp-eval-depth, I think because that causes the function to be called recursively without any break-out clause!

Looking further down I see that the "Long description" I think the following...

    (if (numpydoc--prompt-p)
        (progn
          (setq ld (read-string (concat "Long description "
                                        "(or press return to skip): ")
                                nil nil "" nil))   ;; This captures the text to be inserted
          (unless (string-empty-p ld)
            (insert "\n")
            (numpydoc--insert indent ld)  ;; This inserts the value of ld
            (when numpydoc-auto-fill-paragraphs   ;; auto-fill/wrap paragraphs
              (numpydoc--fill-last-insertion))
            (insert "\n")))
      (insert "\n")
      (numpydoc--insert indent tmpl)
      (insert "\n"))))

So I tried using that as a template....

    (numpydoc--insert indent
                      (concat (make-string 3 numpydoc-quote-char)
                              (if numpydoc-newline-after-opening-quotes
                                "\n")
                              (if (numpydoc--prompt-p)
                                (progn
                                  (setq ld (read-string (format "Short description: ")
                                             tmps))
                                  (unless (string-empty-p ld)
                                    (insert "\n")
                                    (numpydoc--insert indent ld)
                                    (when numpydoc-auto-fill-paragraphs
                                      (numpydoc--fill-last-insertion))
                                    (insert "\n")))
                                (insert "\n")
                      (make-string 3 numpydoc-quote-char))

No dice, feel like I'm out of my depth here but keen to learn what it is I'm missing/not understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GL01 Compliance

2 participants