From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.devel Subject: fix infinite loop in python.el Date: Sat, 21 Jul 2007 15:49:54 +0300 Message-ID: <200707211549.54650.pogonyshev@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1185021315 24929 80.91.229.12 (21 Jul 2007 12:35:15 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 21 Jul 2007 12:35:15 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 21 14:35:14 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1ICEAy-0007zs-0W for ged-emacs-devel@m.gmane.org; Sat, 21 Jul 2007 14:35:12 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ICEAx-00085v-In for ged-emacs-devel@m.gmane.org; Sat, 21 Jul 2007 08:35:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ICEAu-00085G-1n for emacs-devel@gnu.org; Sat, 21 Jul 2007 08:35:08 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ICEAt-000851-GU for emacs-devel@gnu.org; Sat, 21 Jul 2007 08:35:07 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ICEAt-00084v-AZ for emacs-devel@gnu.org; Sat, 21 Jul 2007 08:35:07 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1ICEAs-00053E-RO for emacs-devel@gnu.org; Sat, 21 Jul 2007 08:35:07 -0400 Original-Received: (qmail invoked by alias); 21 Jul 2007 12:35:04 -0000 Original-Received: from unknown (EHLO [80.94.230.3]) [80.94.230.3] by mail.gmx.net (mp045) with SMTP; 21 Jul 2007 14:35:04 +0200 X-Authenticated: #16844820 X-Provags-ID: V01U2FsdGVkX19I3TIQt31IURAW7193syPXc9ZcybAv+8PaK3idXJ qiM79rlhOj5Epg User-Agent: KMail/1.7.2 Content-Disposition: inline X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:75227 Archived-At: 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 * 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 ".."))