emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fix infinite loop in python.el


From: Paul Pogonyshev
Subject: fix infinite loop in python.el
Date: Sat, 21 Jul 2007 15:49:54 +0300
User-agent: KMail/1.7.2

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  <address@hidden>

        * 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 ".."))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]