unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* fix infinite loop in python.el
@ 2007-07-21 12:49 Paul Pogonyshev
  2007-07-22  1:49 ` Richard Stallman
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Pogonyshev @ 2007-07-21 12:49 UTC (permalink / raw)
  To: emacs-devel

Hi,

This patch fixes possible infinite loop (apparently happening only
with invalid syntax) in `python.el'.  I accidentally discovered it
when Emacs would hang with new `python-which-func'.


2007-07-21  Paul Pogonyshev  <pogonyshev@gmx.net>

	* progmodes/python.el (python-current-defun): Adjust to never fall
	into infinite loop.


*** python.el	12 Jul 2007 22:55:32 +0300	1.63
--- python.el	21 Jul 2007 15:46:18 +0300	
***************
*** 1828,1848 ****
    (save-excursion
      ;; Move up the tree of nested `class' and `def' blocks until we
      ;; get to zero indentation, accumulating the defined names.
!     (let ((start t)
! 	  (accum)
  	  (length -1))
!       (while (and (or start (> (current-indentation) 0))
! 		  (or (null length-limit)
! 		      (null (cdr accum))
! 		      (< length length-limit)))
! 	(setq start nil)
! 	(python-beginning-of-block)
! 	(end-of-line)
! 	(beginning-of-defun)
! 	(when (looking-at (rx (0+ space) (or "def" "class") (1+ space)
! 			      (group (1+ (or word (syntax symbol))))))
! 	  (push (match-string 1) accum)
! 	  (setq length (+ length 1 (length (car accum))))))
        (when accum
  	(when (and length-limit (> length length-limit))
  	  (setcar accum ".."))
--- 1828,1852 ----
    (save-excursion
      ;; Move up the tree of nested `class' and `def' blocks until we
      ;; get to zero indentation, accumulating the defined names.
!     (let ((accum)
  	  (length -1))
!       (catch 'done
! 	(while (or (null length-limit)
! 		   (null (cdr accum))
! 		   (< length length-limit))
! 	  (setq start nil)
! 	  (let ((started-from (point)))
! 	    (python-beginning-of-block)
! 	    (end-of-line)
! 	    (beginning-of-defun)
! 	    (when (= (point) started-from)
! 	      (throw 'done nil)))
! 	  (when (looking-at (rx (0+ space) (or "def" "class") (1+ space)
! 				(group (1+ (or word (syntax symbol))))))
! 	    (push (match-string 1) accum)
! 	    (setq length (+ length 1 (length (car accum)))))
! 	  (when (= (current-indentation) 0)
! 	    (throw 'done nil))))
        (when accum
  	(when (and length-limit (> length length-limit))
  	  (setcar accum ".."))

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-01  0:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-21 12:49 fix infinite loop in python.el Paul Pogonyshev
2007-07-22  1:49 ` Richard Stallman
2007-07-22 16:45   ` Paul Pogonyshev
2007-07-23  4:28     ` Richard Stallman
2007-07-31 13:56       ` Paul Pogonyshev
2007-08-01  0:49         ` Vinicius Jose Latorre

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).