Subject: bug#18462: Emacs freeze with python mode and M-q

From: Leonardo Nobrega <[email-masked]>
Date: Tue, 30 Sep 2014 16:35:58 -0400

The second loop in python-fill-paren moves the point until the syntax
context changes. If it doesn't find a close-paren before the end of
the buffer, it loops forever.

ChangeLog entry:

    * lisp/progmodes/python.el (python-fill-paren): Break
    end-of-region loop when it reaches point-max.

Patch:

=== modified file 'lisp/progmodes/python.el'
*** lisp/progmodes/python.el    2014-09-29 18:14:08 +0000
--- lisp/progmodes/python.el    2014-09-30 20:14:37 +0000
*************** JUSTIFY should be used (if applicable) a
*** 3300,3306 ****
                            (end-of-line)
                            (when (not (python-syntax-context 'paren))
                              (skip-syntax-backward "^)")))
!                         (while (python-syntax-context 'paren)
                            (goto-char (1+ (point-marker))))
                          (point-marker)))
      (let ((paragraph-start "\f\\|[ \t]*$")
--- 3300,3307 ----
                            (end-of-line)
                            (when (not (python-syntax-context 'paren))
                              (skip-syntax-backward "^)")))
!                         (while (and (python-syntax-context 'paren)
!                                     (< (point) (point-max)))
                            (goto-char (1+ (point-marker))))
                          (point-marker)))
      (let ((paragraph-start "\f\\|[ \t]*$")