unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* bug/patch: python.el python-beginning-of-statement
@ 2004-06-27  9:34 Karl Chen
  2004-06-28  2:23 ` Richard Stallman
  0 siblings, 1 reply; 3+ messages in thread
From: Karl Chen @ 2004-06-27  9:34 UTC (permalink / raw)



BUG:
emacs -q /tmp/a.py
) RET TAB

If you have invalid syntax (such as unmatched ")") and try to
indent, python-mode will go into an infinite loop until you C-g.
The bug is in python-beginning-of-statement.


Index: python.el
===================================================================
--- python.el	(revision 6526)
+++ python.el	(working copy)
@@ -710,16 +710,17 @@
 expressions."
   (beginning-of-line)
   (python-beginning-of-string)
-  (while (python-continuation-line-p)
-    (beginning-of-line)
-    (if (python-backslash-continuation-line-p)
-	(while (python-backslash-continuation-line-p)
-	  (forward-line -1))
-      (python-beginning-of-string)
-      ;; Skip forward out of nested brackets.
-      (condition-case ()		; beware invalid syntax
-	  (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t)
-	(error (end-of-line)))))
+  (block nil
+    (while (python-continuation-line-p)
+      (beginning-of-line)
+      (if (python-backslash-continuation-line-p)
+          (while (python-backslash-continuation-line-p)
+            (forward-line -1))
+        (python-beginning-of-string)
+        ;; Skip forward out of nested brackets.
+        (condition-case ()		; beware invalid syntax
+            (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t)
+          (error (return))))))
   (back-to-indentation))
 
 (defun python-end-of-statement ()

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

* Re: bug/patch: python.el python-beginning-of-statement
  2004-06-27  9:34 bug/patch: python.el python-beginning-of-statement Karl Chen
@ 2004-06-28  2:23 ` Richard Stallman
  2004-06-28  8:33   ` Karl Chen
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Stallman @ 2004-06-28  2:23 UTC (permalink / raw)
  Cc: emacs-devel

Does this version of the function work right?

(defun python-beginning-of-statement ()
  "Go to start of current statement.
Accounts for continuation lines, multi-line strings, and multi-line bracketed
expressions."
  (beginning-of-line)
  (python-beginning-of-string)
  (catch 'foo
    (while (python-continuation-line-p)
      (beginning-of-line)
      (if (python-backslash-continuation-line-p)
	  (while (python-backslash-continuation-line-p)
	    (forward-line -1))
	(python-beginning-of-string)
	;; Skip forward out of nested brackets.
	(condition-case ()		; beware invalid syntax
	    (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t)
	  (error (throw 'foo))))))
  (back-to-indentation))

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

* Re: bug/patch: python.el python-beginning-of-statement
  2004-06-28  2:23 ` Richard Stallman
@ 2004-06-28  8:33   ` Karl Chen
  0 siblings, 0 replies; 3+ messages in thread
From: Karl Chen @ 2004-06-28  8:33 UTC (permalink / raw)
  Cc: emacs-devel

>>>>> "rms" == Richard Stallman <rms@gnu.org> writes:
    rms> 
    rms> Does this version of the function work right?  (Defun
    rms> python-beginning-of-statement ()

No, but if you change (throw 'foo) to (throw 'foo nil) it works.


(defun python-beginning-of-statement ()
  "Go to start of current statement.
Accounts for continuation lines, multi-line strings, and multi-line bracketed
expressions."
  (beginning-of-line)
  (python-beginning-of-string)
  (catch 'foo
    (while (python-continuation-line-p)
      (beginning-of-line)
      (if (python-backslash-continuation-line-p)
	  (while (python-backslash-continuation-line-p)
	    (forward-line -1))
	(python-beginning-of-string)
	;; Skip forward out of nested brackets.
	(condition-case ()		; beware invalid syntax
	    (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t)
	  (error (throw 'foo nil))))))
  (back-to-indentation))

Is there a rule against using block/return?  It seems better to
use lexically-scoped blocks than dynamically-scoped blocks.

-- 
Karl 2004-06-28 01:30

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

end of thread, other threads:[~2004-06-28  8:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-27  9:34 bug/patch: python.el python-beginning-of-statement Karl Chen
2004-06-28  2:23 ` Richard Stallman
2004-06-28  8:33   ` Karl Chen

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