Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: douglasdavis/numpydoc.el
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.8
Choose a base ref
...
head repository: douglasdavis/numpydoc.el
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 5 commits
  • 4 files changed
  • 1 contributor

Commits on Mar 20, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    douglasdavis Doug Davis
    Copy the full SHA
    cedbff0 View commit details
  2. improve NEWS entry

    douglasdavis committed Mar 20, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    douglasdavis Doug Davis
    Copy the full SHA
    bccb0b0 View commit details
  3. tested versions update

    douglasdavis committed Mar 20, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    douglasdavis Doug Davis
    Copy the full SHA
    935e6cb View commit details

Commits on Jul 25, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5cb26db View commit details

Commits on Aug 11, 2023

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    77e2893 View commit details
Showing with 72 additions and 38 deletions.
  1. +1 −3 .github/workflows/ci.yml
  2. +20 −2 NEWS.md
  3. +5 −0 README.md
  4. +46 −33 numpydoc.el
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -14,11 +14,9 @@ jobs:
strategy:
matrix:
emacs_version:
- 25.1
- 25.2
- 25.3
- 26.3
- 27.2
- 28.2

steps:
- name: Setup GNU Emacs
22 changes: 20 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
# numpydoc.el NEWS -- history of user visible changes

## Unreleased

### Changes

- Emit a useful warning if function signature parsing fails
([#18](https://github.com/douglasdavis/numpydoc.el/pull/18)).

## 0.9 (July 24, 2023)

### Changes

- Add new `defcustom`: `numpydoc-auto-fill-paragraphs`, which when set
to `t` (the default) will enable automatic paragraph filling for
(somewhat) long descriptions.
([#16](https://github.com/douglasdavis/numpydoc.el/pull/16)).

## 0.8 (March 20, 2023)

### Changes

- Add support for customizing ignored function arguments (function
`Parameters` section). Contributed by
[@pakelly](https://github.com/pakelley) in #13.
`Parameters` section) with new `defcustom`:
`numpydoc-ignored-params`. Contributed by
[@pakelly](https://github.com/pakelley) in
[#13](https://github.com/douglasdavis/numpydoc.el/pull/13).

## 0.7 (March 4, 2022)

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -135,6 +135,11 @@ RET numpydoc</kbd>
All function parameters with names listed here will be ignored
when generating a docstring.
</dd>
<dt>numpydoc-auto-fill-paragraphs</dt>
<dd>
If <code>t</code> text that is inserted in a prompt will be
automatically paragraph-filled.
</dd>
</dl>

## Examples
79 changes: 46 additions & 33 deletions numpydoc.el
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
;; Maintainer: Doug Davis <ddavis@ddavis.io>
;; URL: https://github.com/douglasdavis/numpydoc.el
;; SPDX-License-Identifier: GPL-3.0-or-later
;; Version: 0.8
;; Version: 0.9
;; Package-Requires: ((emacs "25.1") (s "1.12.0") (dash "2.18.0"))
;; Keywords: convenience

@@ -133,6 +133,13 @@ when generating a docstring."
:group 'numpydoc
:type '(repeat string))

(defcustom numpydoc-auto-fill-paragraphs t
"Flag to control automatic paragraph filling.
If set to t text that is inserted in a prompt will be automatically
paragraph-filled."
:group 'numpydoc
:type 'boolean)

;;; package implementation code.

(cl-defstruct numpydoc--def
@@ -249,35 +256,38 @@ This function assumes the cursor to be in the function body."
(defun numpydoc--parse-def (buffer-substr)
"Parse the BUFFER-SUBSTR; return instance of numpydoc--def."
(save-excursion
(let* ((fnsig buffer-substr)
;; trimmed string of the function signature
(trimmed (s-collapse-whitespace fnsig))
;; split into parts (args and return type)
(parts (s-split "->" trimmed))
;; raw return
(rawret (if (nth 1 parts)
(s-trim (nth 1 parts))
nil))
;; save return type as a string (or nil)
(rtype (when rawret
(substring rawret 0 (1- (length rawret)))))
;; raw signature without return type as a string
(rawsig (cond (rtype (substring (s-trim (car parts)) 0 -1))
(t (substring (s-trim (car parts)) 0 -2))))
;; function args as strings
(rawargs (-map #'s-trim
(numpydoc--split-args
(substring rawsig
(1+ (string-match-p (regexp-quote "(")
rawsig))))))
;; function args as a list of structures (remove some special cases)
(args (-remove (lambda (x)
(-contains-p numpydoc-ignored-params
(numpydoc--arg-name x)))
(-map #'numpydoc--arg-str-to-struct rawargs)))
;; look for exceptions in the function body
(exceptions (numpydoc--find-exceptions)))
(make-numpydoc--def :args args :rtype rtype :raises exceptions))))
(condition-case nil
(progn
(let* ((fnsig buffer-substr)
;; trimmed string of the function signature
(trimmed (s-collapse-whitespace fnsig))
;; split into parts (args and return type)
(parts (s-split "->" trimmed))
;; raw return
(rawret (if (nth 1 parts)
(s-trim (nth 1 parts))
nil))
;; save return type as a string (or nil)
(rtype (when rawret
(substring rawret 0 (1- (length rawret)))))
;; raw signature without return type as a string
(rawsig (cond (rtype (substring (s-trim (car parts)) 0 -1))
(t (substring (s-trim (car parts)) 0 -2))))
;; function args as strings
(rawargs (-map #'s-trim
(numpydoc--split-args
(substring rawsig
(1+ (string-match-p (regexp-quote "(")
rawsig))))))
;; function args as a list of structures (remove some special cases)
(args (-remove (lambda (x)
(-contains-p numpydoc-ignored-params
(numpydoc--arg-name x)))
(-map #'numpydoc--arg-str-to-struct rawargs)))
;; look for exceptions in the function body
(exceptions (numpydoc--find-exceptions)))
(make-numpydoc--def :args args :rtype rtype :raises exceptions)))
(error "Failed to parse function signature (bad Python syntax)."))))

(defun numpydoc--has-existing-docstring-p ()
"Check for an existing docstring.
@@ -391,7 +401,8 @@ This function assumes the cursor to be in the function body."
(unless (string-empty-p ld)
(insert "\n")
(numpydoc--insert indent ld)
(numpydoc--fill-last-insertion)
(when numpydoc-auto-fill-paragraphs
(numpydoc--fill-last-insertion))
(insert "\n")))
(insert "\n")
(numpydoc--insert indent tmpl)
@@ -429,7 +440,8 @@ This function assumes the cursor to be in the function body."
element))
tmpd))))
(numpydoc--insert indent desc)
(numpydoc--fill-last-insertion)
(when numpydoc-auto-fill-paragraphs
(numpydoc--fill-last-insertion))
(insert "\n")))

(defun numpydoc--insert-parameters (indent fnargs)
@@ -466,7 +478,8 @@ This function assumes the cursor to be in the function body."
(if (numpydoc--prompt-p)
(read-string "Description for return: ")
tmpr)))
(numpydoc--fill-last-insertion)
(when numpydoc-auto-fill-paragraphs
(numpydoc--fill-last-insertion))
(insert "\n"))))

(defun numpydoc--insert-exceptions (indent fnexcepts)