comparison lisp/progmodes/python.el @ 70219:7a59f2600206

(python-continuation-line-p, python-beginning-of-statement): syntax-ppss may return a negative depth.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 26 Apr 2006 05:26:39 +0000
parents 15278e681be3
children 2657308de2f6 2ecafc6d5db7
comparison
equal deleted inserted replaced
70218:d84cbfb84b06 70219:7a59f2600206
290 "Return non-nil if current line continues a previous one. 290 "Return non-nil if current line continues a previous one.
291 The criteria are that the previous line ends in a backslash outside 291 The criteria are that the previous line ends in a backslash outside
292 comments and strings, or that the bracket/paren nesting depth is nonzero." 292 comments and strings, or that the bracket/paren nesting depth is nonzero."
293 (or (and (eq ?\\ (char-before (line-end-position 0))) 293 (or (and (eq ?\\ (char-before (line-end-position 0)))
294 (not (syntax-ppss-context (syntax-ppss)))) 294 (not (syntax-ppss-context (syntax-ppss))))
295 (/= 0 (syntax-ppss-depth 295 (< 0 (syntax-ppss-depth
296 (save-excursion ; syntax-ppss with arg changes point 296 (save-excursion ; syntax-ppss with arg changes point
297 (syntax-ppss (line-beginning-position))))))) 297 (syntax-ppss (line-beginning-position)))))))
298 298
299 (defun python-comment-line-p () 299 (defun python-comment-line-p ()
300 "Return non-nil iff current line has only a comment." 300 "Return non-nil iff current line has only a comment."
301 (save-excursion 301 (save-excursion
302 (end-of-line) 302 (end-of-line)
717 (while (python-backslash-continuation-line-p) 717 (while (python-backslash-continuation-line-p)
718 (forward-line -1)) 718 (forward-line -1))
719 (python-beginning-of-string) 719 (python-beginning-of-string)
720 ;; Skip forward out of nested brackets. 720 ;; Skip forward out of nested brackets.
721 (condition-case () ; beware invalid syntax 721 (condition-case () ; beware invalid syntax
722 (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t) 722 (let ((depth (syntax-ppss-depth (syntax-ppss))))
723 ;; Beware negative depths.
724 (if (> depth 0) (backward-up-list depth))
725 t)
723 (error (throw 'foo nil)))))) 726 (error (throw 'foo nil))))))
724 (back-to-indentation)) 727 (back-to-indentation))
725 728
726 (defun python-end-of-statement () 729 (defun python-end-of-statement ()
727 "Go to the end of the current statement and return point. 730 "Go to the end of the current statement and return point.
1753 nil) 1756 nil)
1754 hs-special-modes-alist))) 1757 hs-special-modes-alist)))
1755 (if (featurep 'hippie-exp) 1758 (if (featurep 'hippie-exp)
1756 (set (make-local-variable 'hippie-expand-try-functions-list) 1759 (set (make-local-variable 'hippie-expand-try-functions-list)
1757 (cons 'python-try-complete hippie-expand-try-functions-list))) 1760 (cons 'python-try-complete hippie-expand-try-functions-list)))
1758 (unless font-lock-mode (font-lock-mode 1))
1759 (when python-guess-indent (python-guess-indent)) 1761 (when python-guess-indent (python-guess-indent))
1760 (set (make-local-variable 'python-command) python-python-command) 1762 (set (make-local-variable 'python-command) python-python-command)
1761 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode 1763 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode
1762 (let ((python-mode-running t)) 1764 (let ((python-mode-running t))
1763 (python-maybe-jython)))) 1765 (python-maybe-jython))))