]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/python.el
(compilation-disable-input): Default to nil.
[gnu-emacs] / lisp / progmodes / python.el
index eae6ef755704802a4c6418bc72f8e2e056868efb..f54314319029dcca090a3df152bd3e152a898206 100644 (file)
@@ -1,6 +1,6 @@
 ;;; python.el --- silly walks for Python
 
-;; Copyright (C) 2003, 2004  Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
 
 ;; Author: Dave Love <fx@gnu.org>
 ;; Maintainer: FSF
@@ -21,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -70,9 +70,9 @@
 (autoload 'compilation-start "compile")
 
 (defgroup python nil
-  "Silly walks in the Python language"
+  "Silly walks in the Python language."
   :group 'languages
-  :version "21.4"
+  :version "22.1"
   :link '(emacs-commentary-link "python"))
 \f
 ;;;###autoload
@@ -336,14 +336,14 @@ keyword `raise', `break', `continue' or `pass'."
     (unless bos (python-beginning-of-statement))
     (back-to-indentation)
     (looking-at (rx (and (or "return" "raise" "break" "continue" "pass")
-                        word-end)))))
+                        symbol-end)))))
 
 (defun python-outdent-p ()
   "Return non-nil if current line should outdent a level."
   (save-excursion
     (back-to-indentation)
-    (and (looking-at (rx (and (or (and (or "else" "finally") word-end)
-                                 (and (or "except" "elif") word-end
+    (and (looking-at (rx (and (or (and (or "else" "finally") symbol-end)
+                                 (and (or "except" "elif") symbol-end
                                       (1+ (not (any ?:)))))
                              (optional space) ":" (optional space)
                              (or (syntax comment-start) line-end))))
@@ -355,8 +355,8 @@ keyword `raise', `break', `continue' or `pass'."
         ;; Fixme: check this
         (not (looking-at (rx (and (or (and (or "if" "elif" "except"
                                                "for" "while")
-                                           word-end (1+ (not (any ?:))))
-                                      (and "try" word-end))
+                                           symbol-end (1+ (not (any ?:))))
+                                      (and "try" symbol-end))
                                   (optional space) ":" (optional space)
                                   (or (syntax comment-start) line-end)))))
         (progn (end-of-line)
@@ -949,6 +949,7 @@ See `python-check-command' for the default."
                                    (if name
                                        (file-name-nondirectory name))))))))
   (setq python-saved-check-command command)
+  (require 'compile)                    ;To define compilation-* variables.
   (save-some-buffers (not compilation-ask-about-save) nil)
   (let ((compilation-error-regexp-alist
         (cons '("(\\([^,]+\\), line \\([0-9]+\\))" 1 2)
@@ -1066,7 +1067,7 @@ For running multiple processes in multiple buffers, see `python-buffer'.
   ;; Still required by `comint-redirect-send-command', for instance
   ;; (and we need to match things like `>>> ... >>> '):
   (set (make-local-variable 'comint-prompt-regexp)
-       (rx (and line-start (1+ (and (repeat 3 (any ">.")) ?\ )))))
+       (rx (and line-start (1+ (and (repeat 3 (any ">.")) ?\s)))))
   (set (make-local-variable 'compilation-error-regexp-alist)
        python-compilation-regexp-alist)
   (compilation-shell-minor-mode 1))
@@ -1098,28 +1099,40 @@ Don't save anything for STR matching `inferior-python-filter-regexp'."
 (defvar python-preoutput-continuation nil
   "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.")
 
+(defvar python-preoutput-leftover nil)
+
 ;; Using this stops us getting lines in the buffer like
 ;; >>> ... ... >>>
 ;; Also look for (and delete) an `_emacs_ok' string and call
 ;; `python-preoutput-continuation' if we get it.
 (defun python-preoutput-filter (s)
   "`comint-preoutput-filter-functions' function: ignore prompts not at bol."
+  (when python-preoutput-leftover
+    (setq s (concat python-preoutput-leftover s))
+    (setq python-preoutput-leftover nil))
   (cond ((and (string-match (rx (and string-start (repeat 3 (any ".>"))
-                                    " " string-end))
-                           s)
-             (/= (let ((inhibit-field-text-motion t))
-                   (line-beginning-position))
-                 (point)))
-        "")
-       ((string= s "_emacs_ok\n")
-        (when python-preoutput-continuation
-          (funcall python-preoutput-continuation)
-          (setq python-preoutput-continuation nil))
-        "")
-       ((string-match "_emacs_out \\(.*\\)\n" s)
-        (setq python-preoutput-result (match-string 1 s))
+                                     " " string-end))
+                            s)
+              (/= (let ((inhibit-field-text-motion t))
+                    (line-beginning-position))
+                  (point)))
+         "")
+        ((string= s "_emacs_ok\n")
+         (when python-preoutput-continuation
+           (funcall python-preoutput-continuation)
+           (setq python-preoutput-continuation nil))
+         "")
+        ((string-match "_emacs_out \\(.*\\)\n" s)
+         (setq python-preoutput-result (match-string 1 s))
+         "")
+       ((string-match ".*\n" s)
+        s)
+       ((or (eq t (compare-strings s nil nil "_emacs_ok\n" nil (length s)))
+            (let ((end (min (length "_emacs_out ") (length s))))
+              (eq t (compare-strings s nil end "_emacs_out " nil end))))
+        (setq python-preoutput-leftover s)
         "")
-       (t s)))
+        (t s)))
 
 ;;;###autoload
 (defun run-python (&optional cmd noshow)
@@ -1359,7 +1372,9 @@ The result is what follows `_emacs_out' in the output (or nil)."
   (let ((proc (python-proc)))
     (python-send-string string)
     (setq python-preoutput-result nil)
-    (accept-process-output proc 5)
+    (while (progn
+            (accept-process-output proc 5)
+            python-preoutput-leftover))
     python-preoutput-result))
 
 ;; Fixme: try to make it work with point in the arglist.  Also, is
@@ -1562,7 +1577,8 @@ of current line."
        (beginning-of-defun)
        (if (looking-at (rx (and (0+ space) (or "def" "class") (1+ space)
                                 (group (1+ (or word (syntax symbol))))
-                                word-end)))
+                                ;; Greediness makes this unnecessary?  --Stef
+                                symbol-end)))
            (push (match-string 1) accum)))
       (if accum (mapconcat 'identity accum ".")))))
 
@@ -1665,7 +1681,7 @@ Repeating the command scrolls the completion window."
 ;;;; Modes.
 
 (defvar outline-heading-end-regexp)
-(defvar eldoc-print-current-symbol-info-function)
+(defvar eldoc-documentation-function)
 
 ;;;###autoload
 (define-derived-mode python-mode fundamental-mode "Python"
@@ -1702,9 +1718,9 @@ lines count as headers.
        '(python-font-lock-keywords nil nil ((?_ . "w")) nil
                                   (font-lock-syntactic-keywords
                                    . python-font-lock-syntactic-keywords)
-;;; This probably isn't worth it.
-;;;                               (font-lock-syntactic-face-function
-;;;                                . python-font-lock-syntactic-face-function)
+                                  ;; This probably isn't worth it.
+                                  ;; (font-lock-syntactic-face-function
+                                  ;;  . python-font-lock-syntactic-face-function)
                                   ))
   (set (make-local-variable 'parse-sexp-lookup-properties) t)
   (set (make-local-variable 'comment-start) "# ")
@@ -1712,7 +1728,7 @@ lines count as headers.
   (set (make-local-variable 'indent-line-function) #'python-indent-line)
   (set (make-local-variable 'paragraph-start) "\\s-*$")
   (set (make-local-variable 'fill-paragraph-function) 'python-fill-paragraph)
-  (set (make-local-variable 'require-final-newline) t)
+  (set (make-local-variable 'require-final-newline) mode-require-final-newline)
   (set (make-local-variable 'add-log-current-defun-function)
        #'python-current-defun)
   ;; Fixme: Generalize to do all blocks?
@@ -1725,7 +1741,7 @@ lines count as headers.
        'python-beginning-of-defun)
   (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
   (setq imenu-create-index-function #'python-imenu-create-index)
-  (set (make-local-variable 'eldoc-print-current-symbol-info-function)
+  (set (make-local-variable 'eldoc-documentation-function)
        #'python-eldoc-function)
   (add-hook 'eldoc-mode-hook
            '(lambda () (run-python 0 t)) nil t) ; need it running