• Stars
    star
    123
  • Rank 288,391 (Top 6 %)
  • Language
    Emacs Lisp
  • Created almost 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generate Sphinx friendly docstrings for Python functions in Emacs

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

More Repositories

1

lookupy

Django QuerySet like interface to query simple Python collections
Python
67
star
2

GuitarJs

A small javascript library for guitar notes, scales, chords
JavaScript
16
star
3

toolbox

A lazy developer's toolbox. Mostly command line scripts.
Python
10
star
4

ansible-role-pyfsrc

Ansible role to install a specific version of Python from source
9
star
5

emacs-config

My emacs config
Emacs Lisp
6
star
6

dupenukem

A command line file deduplication tool
Rust
4
star
7

jquery-sticky-buttons

jQuery plugin to make buttons stick to the top of the page as user scrolls down
JavaScript
3
star
8

core_python

My solutions to the exercises from the book Core Python
Python
3
star
9

phpDbMigrations

South (Django) like, but minimalist db migrations for php and mysql applications
PHP
3
star
10

blog-src

Source files for my pelican based blog
JavaScript
3
star
11

twolegged

Simple two legged authentication to secure server to server API access
Python
3
star
12

attercop

A web scraping library inspired by Scrapy using core.async
Clojure
3
star
13

ten-chord-workout

A fun way do your daily Chords (Music) workout!
JavaScript
2
star
14

bugcrawler

Simple tool to automatically crawl website pages looking for php errors
Python
2
star
15

jinger

(Yet another) Jinja2 based static site generator
Python
2
star
16

upacker

A simple utility to copy only some files of a project preserving the directory structure thereby making it convenient to upload them at once
Python
2
star
17

sicp-study

Learning and solving SICP exercises in scheme
Scheme
1
star
18

davis

Amateur experiments in Data Analysis and VISualizations
Python
1
star
19

logan

Web based log analysis tool using Flask and D3.js
Python
1
star
20

nozzle

(Even more) Quick and simple nose tests
Python
1
star
21

kodeplay-puzzles

Solutions to Puzzles/Programming competition problems at Kodeplay
Erlang
1
star
22

naiquevin.github.com

My blog
JavaScript
1
star