Giter Club home page Giter Club logo

sphinx-doc.el's Introduction

sphinx-doc.el

What is it?

sphinx-doc is an emacs minor mode for inserting docstring skeleton for Python functions and methods. The structure of the docstring is as per the requirement of the Sphinx documentation generator.

Installation

This package can be installed from MELPA. To do so, run M-x package-list-packages, then search for "sphinx-doc". Mark it with i and finally press x to install.

To install manually, download and copy the sphinx-doc.el file somewhere in the load path.

Configuration

Add the following line to your .emacs (or the equivalent config file)

    (add-hook 'python-mode-hook (lambda ()
                                  (require 'sphinx-doc)
                                  (sphinx-doc-mode t)))

This will enable the sphinx-doc-mode and bind the interactive function sphinx-doc to C-c M-d.

To include type parameters in your docstring, set sphinx-doc-include-types to t.

Usage

Inside a Python file, move the cursor to some function/method definition and hit C-c M-d (see gif demo below).

Demo

Sphinx-doc

Known Issues

  • The parser is whitespace-sensitive. If there are trailing spaces at the end of the function definition line, then the parser will fail. Also, if you do not have at before the type name in your type-hints, then the parser will fail.

  • When calling the function interactively, if the cursor is not on the head of a function definition (ie. the keyword def, function name or the parenthesized list of the formal parameters) it either shows a "search failed" message in the minibuffer or inserts documentation for a valid function definition closer to the current line! Although both behaviours are quite harmless, it's annoying and definitely needs to be fixed. Patches welcome!

See also

  • The autodoc extension needs to be enabled for the sphinx instance in order to generate documentation from the docstrings.

  • If anyone's interested, there is a similar functionality I wrote to generate docstrings for Javscript functions based on the style of Natural Docs. It's not packaged as a mode but can be installed manually. Natural Docs for Javascript in Emacs

License

MIT

sphinx-doc.el's People

Contributors

bookest avatar naiquevin avatar nightblues avatar peterewills avatar syohex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinx-doc.el's Issues

Support trailing commas?

In some codebases I have seen that trailing commas are used in function definitions, especially when functions take a lot of keyword parameters and people frequently change or add them. Trailing commas then help with version control and guard against forgotten commas. You might argue whether this is good stile, but the following is valid python:

def foo(arg1, arg2, arg3,):
    return bar

sphinx-doc then fails, because sphinx-doc-fun-args creates an empy string "" as the last arg. I fixed that in place by just removing empty strings from the argument list with remove "". But maybe there is a better place to implement a fix. I didn't go really went into understanding your code, so I refrained from a PR.

(defun sphinx-doc-fun-args (argstrs)
  "Extract list of arg objects from string ARGSTRS.
ARGSTRS is the string representing function definition in Python.
Note that the arguments self, *args and **kwargs are ignored."
  (when (not (string= argstrs ""))
    (mapcar #'sphinx-doc-str->arg
            (-filter
             (lambda (str)
               (and (not (string= (substring str 0 1) "*"))
                    (not (string= str "self"))))
             (remove ""
              (mapcar #'s-trim
                      (split-string argstrs ",")))))))

How can we add compact single line?

Before:

def helloworld():
    pass

after:

def helloworld():
    """TODO describe function

    :returns:

    """
    pass

Instead, for an empty function can we remove returns: value and we have more compact as follows:

def helloworld():
    """TODO describe function."""
    pass

How can I ignore new-line after param or returns?

When I apply C-c M-d it creates the doc section having new line at the end. Would it be possible to ignore the newline that applid at the end of docs?

Example output:

"""TODO describe function

:param provider:
:param _from:
:param job:
:returns:

"""

Wanted:

"""TODO describe function

:param provider:
:param _from:
:param job:
:returns:
"""

Do not enable mode globally on require

The init-value parameter for define-minor-mode is set to t. This enables the mode in non-python buffers as well, which is unfortunate. As far as I can tell from the documentation of define-minor-mode, there is no reason to set it to t initially. As with other minor modes, I'd prefer to enable it from python-mode-hook.

Error when inserting docstring; inserting docstring kills any existing docstring

Hi:

I just installed the elisp package from MELPA, and tried using it with my Python code. I keep getting the following error message when attempting to insert a new docstring into my code, and additionally, it always kills any existing docstring inside it, instead of updating it.

Suspicious state from syntax checker python-pycompile: Checker python-pycompile returned non-zero exit code 1, but no errors from output: Sorry: IndentationError: ('unexpected indent', ('/tmp/flycheck15795ZS0/app_utils.py', 84, 9, '         callback = mari.utils.connec()\n')) Checker definition probably flawed.

Is there anything I can do to resolve this?

Thanks!

dash version locked at 2.10.0

Would you mind revising for a newer dash? Currently dash is on 2.16.1. Whenever I want to use sphinx doc, I get error because it requires 2.10.0

Feature request: "warning" and "note"

It would be nice to have functions that automatically generate a skeleton for 'warning' and 'note'. For example:

    def function(array, key):
        """
        This function does ...

        .. warning::

            Possible warnings tba. 

        Docstring continued...

        .. note::

            The syntax should be ... 

        Parameters
        ----------
        value : list
            Array read from the parameter file
        key : str
            Name of the parameter

        """

Feature request: numpydoc syntax

Sphinx has an extension, numpydoc, which enables a very popular docstring style that is used by numpy, scipy, and many other packages. It would be nice if sphinx-doc could generate docstrings using the syntax of numpydoc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.