Skip to content

Commit

Permalink
Adjusting some customization options; add yasnippet support. (#3)
Browse files Browse the repository at this point in the history
* yasnippet works; needs more documenation.

* Improving prompt insertion configuration.

* helper -> style

* add NEWS and improve docs.
  • Loading branch information
douglasdavis authored Mar 5, 2021
1 parent fcbdeca commit 1549f36
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 71 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.elc
numpydoc-autoloads.el
.DS_Store
README.html

# Added automatically by ‘eldev init’.
/.eldev
Expand Down
39 changes: 39 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
numpydoc.el NEWS -- history of user visable changes

* Unreleased

** Changes
TBD

* 0.2.0 (Mar 5, 2021)

** Changes

*** Added support for yasnippet
If yasnippet is installed we we `yas-expand-snippet' to on-the-fly add
the docstring components in buffer.

*** Added customization `numpydoc-insertion-style'.
Use this single customization to direct the insertion style instead of
multiple boolean customization. Can take on:
- 'prompt (prompt in minibuffer)
- 'yas (use yasnippet)
- nil (use insertion helper, just use templates)

*** Added interactive convenience functions for toggling insertion style.
`numpydoc-use-yasnippet', `numpydoc-use-prompt', and
`numpydoc-use-templates' are new interactive convenience functions to
adjust `numpydoc-insertion-style' without having to use
`eval-expression' and `setq'.

** Removed

*** Removed variable `numpydoc-prompt-for-input'.
Not needed anymore (use `numpydoc-insertion-style').

*** Removed function `numpydoc-toggle-prompt'.
Not needed anymore (use numpydoc-use-{yasnippet,prompt,templates}).

* 0.1.0

Initial release
59 changes: 35 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ An Emacs Lisp package to automatically insert [NumPy style
docstrings](https://numpydoc.readthedocs.io/en/latest/format.html) for
Python functions.

Calling `numpydoc-generate` parses a function signature and body
(corresponding to the current cursor location; just have the cursor
somewhere in the function you want to document) detecting argument
Calling `numpydoc-generate` parses the function at point (the cursor
can be anywhere in the function body). The parsing detects argument
names, type hints, exceptions, and the return type hint. This
information is used to generate a docstring.

The default behavior is to prompt the user, in the minibuffer, for a
(short and long) description of the function, a description for each
function argument, a description for each possible exception, and the
returned value. If the prompt is off (`numpydoc-prompt-for-input` is
`nil`), then some customizable template text will be inserted into the
docstring. If an existing docstring is detected, you'll be asked if
you'd like to delete it and start fresh.
The default behavior is to prompt the user (in the minibuffer) for a
short & long description of the function, a description for each
function argument, a description for each possible exception, and a
description for the return. It's also possible to either disable the
minibuffer prompt or use
[yasnippet](https://github.com/joaotavora/yasnippet) insertion. See
[customization](#customization) for more information. You'll also find
a few [examples](#examples) below. See the
[NEWS](https://github.com/douglasdavis/numpydoc.el/blob/main/NEWS)
file to see recent changes.

## Setup

Expand Down Expand Up @@ -67,14 +69,20 @@ writing this), so you may want to give yourself a convenient shortcut:
See inside Emacs with <kbd>M-x customize-group RET numpydoc</kbd>

<dl>
<dt>numpydoc-prompt-for-input</dt>
<dt>numpydoc-insertion-style</dt>
<dd>
If <code>t</code> you will be prompted to enter a short description
and long description, a description for each function argument, and
a description for the return (if a return type hint is provided). An
interactive convenience function
(<code>numpydoc-toggle-prompt</code>) is provided to toggle the
value of this variable.
The method used to insert components of the docstring (default is
<code>'prompt</code>).
<ul>
<li> <code>'prompt</code> will trigger a request for each description
in the minibuffer.</li>
<li> <code>'yas</code> (requires <code>yasnippet</code> to be
installed) will generate a template and call
<code>yas-expand-snippet</code>, providing an insertion method
familiar to <code>yasnippet</code> users.</li>
<li> <code>nil</code> will disable any interactive insertion (template
text will be inserted).</li>
</ul>
</dd>
<dt>numpydoc-quote-char</dt>
<dd>
Expand Down Expand Up @@ -117,18 +125,21 @@ See inside Emacs with <kbd>M-x customize-group RET numpydoc</kbd>

## Examples

<kbd>M-x numpydoc-generate</kbd> with the default configuration that
will prompt for input in the minibuffer (notice how long text is
<kbd>M-x numpydoc-generate</kbd> with the default configuration,
`numpydoc-insertion-style` set to `'prompt` (notice how long text is
automatically paragraph-filled):

<p align="center">
<img src="doc/example.gif" style="border-radius:10px"/>
<img src="doc/ex1.gif" width="65%"/>
</p>

Or, <kbd>M-x numpydoc-generate</kbd> with
`numpydoc-prompt-for-input` set to `nil`:
Using `yasnippet` (`numpydoc-insertion-style` set to `'yas`):

Before:
<p align="center">
<img src="doc/ex2.gif" width="65%"/>
</p>

With `numpydoc-insertion-style` set to `nil`; before:

```python
def plot_histogram(
Expand All @@ -145,7 +156,7 @@ def plot_histogram(
pass
```

After:
After <kbd>M-x numpydoc-generate</kbd>:

```python
def plot_histogram(
Expand Down
Binary file added doc/ex1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/ex2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/example.gif
Binary file not shown.
Loading

0 comments on commit 1549f36

Please sign in to comment.