Skip to content

Commit

Permalink
Enforce documentation of argument types; adds another defcustom.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasdavis committed Mar 5, 2021
1 parent e0dff37 commit fcbdeca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# numpydoc.el

[![MELPA](https://melpa.org/packages/numpydoc-badge.svg)](https://melpa.org/#/numpydoc)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![CI](https://github.com/douglasdavis/numpydoc.el/actions/workflows/ci.yml/badge.svg)](https://github.com/douglasdavis/numpydoc.el/actions/workflows/ci.yml)
[![builds.sr.ht status](https://builds.sr.ht/~ddavis/numpydoc.el/commits/.build.yml.svg)](https://builds.sr.ht/~ddavis/numpydoc.el/commits/.build.yml?)

Expand Down Expand Up @@ -108,6 +107,12 @@ See inside Emacs with <kbd>M-x customize-group RET numpydoc</kbd>
description if <code>numpydoc-prompt-for-input</code> is
<code>nil</code>.
</dd>
<dt>numpydoc-template-type-desc</dt>
<dd>
Template text that will be used for each function argument type
description if <code>numpydoc-prompt-for-input</code> is
<code>nil</code>.
</dd>
</dl>

## Examples
Expand Down
21 changes: 18 additions & 3 deletions numpydoc.el
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ text, and below the Examples section."
:group 'numpydoc
:type 'string)

(defcustom numpydoc-template-type-desc "FIXME: Add type."
"Template text for individual component type descriptions."
:group 'numpydoc
:type 'string)

;;; package implementation code.

(cl-defstruct numpydoc--def
Expand Down Expand Up @@ -329,6 +334,16 @@ This function assumes the cursor to be in the function body."
(format "%s : %s\n" name type)
(format "%s\n" name))))

(defun numpydoc--insert-item-and-type (indent name type)
"Insert parameter with NAME and TYPE at level INDENT."
(let ((tp type))
(unless tp
(setq tp (if numpydoc-prompt-for-input
(read-string (format "Type of %s: "
name))
numpydoc-template-type-desc)))
(numpydoc--insert indent (format "%s : %s\n" name tp))))

(defun numpydoc--insert-item-desc (indent element)
"Insert ELEMENT parameter description at level INDENT."
(let ((desc (concat (make-string 4 ?\s)
Expand All @@ -348,9 +363,9 @@ This function assumes the cursor to be in the function body."
"Parameters\n"
"----------\n")
(dolist (element fnargs)
(numpydoc--insert-item indent
(numpydoc--arg-name element)
(numpydoc--arg-type element))
(numpydoc--insert-item-and-type indent
(numpydoc--arg-name element)
(numpydoc--arg-type element))
(numpydoc--insert-item-desc indent
(numpydoc--arg-name element)))))

Expand Down

0 comments on commit fcbdeca

Please sign in to comment.