summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina <fgallina@gnu.org>2015-02-07 16:43:47 -0300
committerFabián Ezequiel Gallina <fgallina@gnu.org>2015-02-07 16:43:47 -0300
commit2d467a0ff0cd446ec0d83044a0be819cbf874cdf (patch)
treef719433f1e65da7a6a70f4bd3f1d9231eb626f9d /lisp/progmodes/python.el
parent86c50b9af1e68ca87bfc9e6d0cdb28ae2e53cc32 (diff)
Fix hideshow integration.
Fixes: debbugs:19761 * lisp/progmodes/python.el (python-hideshow-forward-sexp-function): New function based on Carlos Pita <carlosjosepita@gmail.com> patch. (python-mode): Make `hs-special-modes-alist` use it and initialize the end regexp with the empty string to avoid skipping parens. * test/automated/python-tests.el (python-tests-visible-string): New function. (python-parens-electric-indent-1) (python-triple-quote-pairing): Fix indentation, move require calls. (python-hideshow-hide-levels-1) (python-hideshow-hide-levels-2): New tests.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el26
1 files changed, 21 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index de251181c14..3399429538f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3958,6 +3958,17 @@ Interactively, prompt for symbol."
(message (python-eldoc--get-doc-at-point symbol)))
+;;; Hideshow
+
+(defun python-hideshow-forward-sexp-function (arg)
+ "Python specific `forward-sexp' function for `hs-minor-mode'.
+Argument ARG is ignored."
+ arg ; Shut up, byte compiler.
+ (python-nav-end-of-defun)
+ (unless (python-info-current-line-empty-p)
+ (backward-char)))
+
+
;;; Imenu
(defvar python-imenu-format-item-label-function
@@ -4693,11 +4704,16 @@ Arguments START and END narrow the buffer region to work on."
(add-function :before-until (local 'eldoc-documentation-function)
#'python-eldoc-function))
- (add-to-list 'hs-special-modes-alist
- `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
- ,(lambda (_arg)
- (python-nav-end-of-defun))
- nil))
+ (add-to-list
+ 'hs-special-modes-alist
+ `(python-mode
+ "\\s-*\\(?:def\\|class\\)\\>"
+ ;; Use the empty string as end regexp so it doesn't default to
+ ;; "\\s)". This way parens at end of defun are properly hidden.
+ ""
+ "#"
+ python-hideshow-forward-sexp-function
+ nil))
(set (make-local-variable 'outline-regexp)
(python-rx (* space) block-start))