diff options
| author | Fabián Ezequiel Gallina | 2012-10-05 10:42:08 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-10-05 10:42:08 -0300 |
| commit | 7fa36ccb71d0def28bc3f8eb17827fc870bd7ca2 (patch) | |
| tree | 133d8b9a7f381d144818f28d4ad6d21b5a2df182 | |
| parent | a65fbb5f0ef0e6929393750ec466f11cefc6ba60 (diff) | |
| download | emacs-7fa36ccb71d0def28bc3f8eb17827fc870bd7ca2.tar.gz emacs-7fa36ccb71d0def28bc3f8eb17827fc870bd7ca2.zip | |
Enhancements to docstring formatting when filling paragraphs.
* progmodes/python.el (python-fill-docstring-style): Rename from
python-fill-string-style. Added new style.
(python-fill-string): Use new style. Better checks for
docstrings.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 46 |
2 files changed, 40 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 16c64ae1394..1010fc0ae11 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-10-05 Fabián Ezequiel Gallina <fgallina@cuca> | ||
| 2 | |||
| 3 | Enhancements to docstring formatting when filling paragraphs. | ||
| 4 | * progmodes/python.el (python-fill-docstring-style): Rename from | ||
| 5 | python-fill-string-style. Added new style. | ||
| 6 | (python-fill-string): Use new style. Better checks for | ||
| 7 | docstrings. | ||
| 8 | |||
| 1 | 2012-10-05 Glenn Morris <rgm@gnu.org> | 9 | 2012-10-05 Glenn Morris <rgm@gnu.org> |
| 2 | 10 | ||
| 3 | * net/newst-treeview.el (newsticker-group-move-feed): Doc fix. | 11 | * net/newst-treeview.el (newsticker-group-move-feed): Doc fix. |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d5aa73f5ef3..b3b3b0181d7 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2290,15 +2290,15 @@ fill parens." | |||
| 2290 | :type 'symbol | 2290 | :type 'symbol |
| 2291 | :group 'python) | 2291 | :group 'python) |
| 2292 | 2292 | ||
| 2293 | (defcustom python-fill-string-style 'pep-257 | 2293 | (defcustom python-fill-docstring-style 'pep-257 |
| 2294 | "Style used to fill docstrings. | 2294 | "Style used to fill docstrings. |
| 2295 | This affects `python-fill-string' behavior with regards to | 2295 | This affects `python-fill-string' behavior with regards to |
| 2296 | triple quotes positioning. | 2296 | triple quotes positioning. |
| 2297 | 2297 | ||
| 2298 | Possible values are DJANGO, PEP-257, PEP-257-NN, SYMMETRIC and | 2298 | Possible values are DJANGO, ONETWO, PEP-257, PEP-257-NN, |
| 2299 | NIL. A value of NIL won't care about quotes position, will do | 2299 | SYMMETRIC, and NIL. A value of NIL won't care about quotes |
| 2300 | what `fill-paragraph' does, any other value may result in one of | 2300 | position and will treat docstrings a normal string, any other |
| 2301 | the following docstring styles: | 2301 | value may result in one of the following docstring styles: |
| 2302 | 2302 | ||
| 2303 | DJANGO: | 2303 | DJANGO: |
| 2304 | 2304 | ||
| @@ -2312,6 +2312,17 @@ DJANGO: | |||
| 2312 | If processing fails throw ProcessingError. | 2312 | If processing fails throw ProcessingError. |
| 2313 | \"\"\" | 2313 | \"\"\" |
| 2314 | 2314 | ||
| 2315 | ONETWO: | ||
| 2316 | |||
| 2317 | \"\"\"Process foo, return bar.\"\"\" | ||
| 2318 | |||
| 2319 | \"\"\" | ||
| 2320 | Process foo, return bar. | ||
| 2321 | |||
| 2322 | If processing fails throw ProcessingError. | ||
| 2323 | |||
| 2324 | \"\"\" | ||
| 2325 | |||
| 2315 | PEP-257: | 2326 | PEP-257: |
| 2316 | 2327 | ||
| 2317 | \"\"\"Process foo, return bar.\"\"\" | 2328 | \"\"\"Process foo, return bar.\"\"\" |
| @@ -2340,9 +2351,16 @@ SYMMETRIC: | |||
| 2340 | 2351 | ||
| 2341 | If processing fails throw ProcessingError. | 2352 | If processing fails throw ProcessingError. |
| 2342 | \"\"\"" | 2353 | \"\"\"" |
| 2343 | :type 'symbol | 2354 | :type '(choice |
| 2355 | (const :tag "Don't format docstrings" nil) | ||
| 2356 | (const :tag "Django's coding standards style." django) | ||
| 2357 | (const :tag "One newline and start and Two at end style." onetwo) | ||
| 2358 | (const :tag "PEP-257 with 2 newlines at end of string." pep-257) | ||
| 2359 | (const :tag "PEP-257 with 1 newline at end of string." pep-257-nn) | ||
| 2360 | (const :tag "Symmetric style." symmetric)) | ||
| 2344 | :group 'python | 2361 | :group 'python |
| 2345 | :safe (lambda (val) (memq val '(django pep-257 pep-257-nn symmetric nil)))) | 2362 | :safe (lambda (val) |
| 2363 | (memq val '(django onetwo pep-257 pep-257-nn symmetric nil)))) | ||
| 2346 | 2364 | ||
| 2347 | (defun python-fill-paragraph-function (&optional justify) | 2365 | (defun python-fill-paragraph-function (&optional justify) |
| 2348 | "`fill-paragraph-function' handling multi-line strings and possibly comments. | 2366 | "`fill-paragraph-function' handling multi-line strings and possibly comments. |
| @@ -2403,28 +2421,28 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2403 | ;; Docstring styles may vary for oneliners and multi-liners. | 2421 | ;; Docstring styles may vary for oneliners and multi-liners. |
| 2404 | (> (count-matches "\n" str-start-pos str-end-pos) 0)) | 2422 | (> (count-matches "\n" str-start-pos str-end-pos) 0)) |
| 2405 | (delimiters-style | 2423 | (delimiters-style |
| 2406 | (case python-fill-string-style | 2424 | (case python-fill-docstring-style |
| 2407 | ;; delimiters-style is a cons cell with the form | 2425 | ;; delimiters-style is a cons cell with the form |
| 2408 | ;; (START-NEWLINES . END-NEWLINES). When any of the sexps | 2426 | ;; (START-NEWLINES . END-NEWLINES). When any of the sexps |
| 2409 | ;; is NIL means to not add any newlines for start or end | 2427 | ;; is NIL means to not add any newlines for start or end |
| 2410 | ;; of docstring. See `python-fill-string-style' for a | 2428 | ;; of docstring. See `python-fill-docstring-style' for a |
| 2411 | ;; graphic idea of each style. | 2429 | ;; graphic idea of each style. |
| 2430 | (django (cons 1 1)) | ||
| 2431 | (onetwo (and multi-line-p (cons 1 2))) | ||
| 2412 | (pep-257 (and multi-line-p (cons nil 2))) | 2432 | (pep-257 (and multi-line-p (cons nil 2))) |
| 2413 | (pep-257-nn (and multi-line-p (cons nil 1))) | 2433 | (pep-257-nn (and multi-line-p (cons nil 1))) |
| 2414 | (django (cons 1 1)) | ||
| 2415 | (symmetric (and multi-line-p (cons 1 1))))) | 2434 | (symmetric (and multi-line-p (cons 1 1))))) |
| 2416 | (docstring-p (save-excursion | 2435 | (docstring-p (save-excursion |
| 2417 | ;; Consider docstrings those strings which | 2436 | ;; Consider docstrings those strings which |
| 2418 | ;; start on a line by themselves. | 2437 | ;; start on a line by themselves. |
| 2419 | (goto-char str-start-pos) | 2438 | (python-nav-beginning-of-statement) |
| 2420 | (skip-chars-backward (rx whitespace)) | 2439 | (and (= (point) str-start-pos)))) |
| 2421 | (= (point) (line-beginning-position)))) | ||
| 2422 | (fill-paragraph-function)) | 2440 | (fill-paragraph-function)) |
| 2423 | (save-restriction | 2441 | (save-restriction |
| 2424 | (narrow-to-region str-start-pos str-end-pos) | 2442 | (narrow-to-region str-start-pos str-end-pos) |
| 2425 | (fill-paragraph justify)) | 2443 | (fill-paragraph justify)) |
| 2426 | (save-excursion | 2444 | (save-excursion |
| 2427 | (when (and docstring-p python-fill-string-style) | 2445 | (when (and docstring-p python-fill-docstring-style) |
| 2428 | ;; Add the number of newlines indicated by the selected style | 2446 | ;; Add the number of newlines indicated by the selected style |
| 2429 | ;; at the start of the docstring. | 2447 | ;; at the start of the docstring. |
| 2430 | (goto-char (+ str-start-pos num-quotes)) | 2448 | (goto-char (+ str-start-pos num-quotes)) |