From 2d467a0ff0cd446ec0d83044a0be819cbf874cdf Mon Sep 17 00:00:00 2001 From: Fabián Ezequiel Gallina Date: Sat, 7 Feb 2015 16:43:47 -0300 Subject: Fix hideshow integration. Fixes: debbugs:19761 * lisp/progmodes/python.el (python-hideshow-forward-sexp-function): New function based on Carlos Pita 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. --- lisp/progmodes/python.el | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lisp/progmodes/python.el') 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)) -- cgit v1.2.1