Commit affc0ca0 authored by Barry Warsaw's avatar Barry Warsaw

Changes in preparation for integrating into the Python CVS tree.

Introductory comment updates.

(python-font-lock-keywords): Added "assert"

(py-block-closing-keywords-re): New variable.

(py-no-outdent-re): Rewrite to use py-block-closing-keywords-re.

(py-shell): py-process-filter should no longer be necessary.  Comint
should do all the work.  Note that more fixes to the py-shell process
mechanism need to be done.

(py-execute-region): Check for empty region.  Some questionable
changes to set-buffer after shell-command-on-region.  Again, this all
needs to be closely examined for X/Emacs 19/20 compatibility.

(py-goto-beyond-final-line): py-parse-partial-sexp-works-p should no
longer be necessary.

(py-statement-closes-block-p): Use py-block-closing-keywords-re.
parent 6345ac6d
...@@ -25,56 +25,43 @@ ...@@ -25,56 +25,43 @@
;; subsequently left the net; in 1995, Barry Warsaw inherited the ;; subsequently left the net; in 1995, Barry Warsaw inherited the
;; mode and is the current maintainer. ;; mode and is the current maintainer.
;; At some point this mode will undergo a rewrite to bring it more in ;; Note: this version of python-mode.el is no longer compatible with
;; line with GNU Emacs Lisp coding standards, and to wax all the Emacs ;; Emacs 18. For a gabazillion reasons, I highly recommend upgrading
;; 18 support. But all in all, the mode works exceedingly well, and ;; to X/Emacs 19 or X/Emacs 20. For older versions of the 19 series,
;; I've simply been tweaking it as I go along. Ain't it wonderful ;; you may need to acquire the Custom library.
;; that Python has a much more sane syntax than C? (or <shudder> C++?!
;; :-). I can say that; I maintain CC Mode! ;; python-mode.el is currently distributed with XEmacs 19 and XEmacs
;; 20. Since this file is not GPL'd it is not distributed with Emacs,
;; The following statements, placed in your .emacs file or ;; but it is compatible with the EOL 19 series and current 20 series
;; site-init.el, will cause this file to be autoloaded, and ;; Emacsen. By default, in XEmacs when you visit a .py file, it is
;; python-mode invoked, when visiting .py files (assuming this file is ;; put in Python mode. In Emacs, you need to add the following to
;; in your load-path): ;; your .emacs file (you don't need this for XEmacs):
;; ;;
;; (autoload 'python-mode "python-mode" "Python editing mode." t) ;; (autoload 'python-mode "python-mode" "Python editing mode." t)
;; (setq auto-mode-alist ;; (setq auto-mode-alist
;; (cons '("\\.py$" . python-mode) auto-mode-alist)) ;; (cons '("\\.py$" . python-mode) auto-mode-alist))
;; (setq interpreter-mode-alist
;; (cons '("python" . python-mode) interpreter-mode-alist))
;; ;;
;; Assuming python-mode.el is on your load-path, it will be invoked
;; when you visit a .py file, or a file with a first line that looks
;; like:
;;
;; #! /usr/bin/env python
;; If you want font-lock support for Python source code (a.k.a. syntax ;; If you want font-lock support for Python source code (a.k.a. syntax
;; coloring, highlighting), add this to your .emacs file: ;; coloring, highlighting), add this to your .emacs file:
;; ;;
;; (add-hook 'python-mode-hook 'turn-on-font-lock) ;; (add-hook 'python-mode-hook 'turn-on-font-lock)
;; ;;
;; But you better be sure you're version of Emacs supports ;; Again, this should not be necessary for XEmacs, since it Just Works.
;; font-lock-mode! As of this writing, the latest Emacs and XEmacs
;; 19's do.
;; Here's a brief list of recent additions/improvements/changes: ;; To submit bug reports, use C-c C-b. Please include a complete, but
;; ;; concise code sample and a recipe for reproducing the bug. Send
;; - Wrapping and indentation within triple quote strings now works. ;; suggestions and other comments to python-mode@python.org.
;; - `Standard' bug reporting mechanism (use C-c C-b)
;; - py-mark-block was moved to C-c C-m ;; When in a Python mode buffer, do a C-h m for more help. It's
;; - C-c C-v shows you the python-mode version ;; doubtful that a texinfo manual would be very useful.
;; - a basic python-font-lock-keywords has been added for (X)Emacs 19
;; - proper interaction with pending-del and del-sel modes.
;; - Better support for outdenting: py-electric-colon (:) and
;; py-indent-line (TAB) improvements; one level of outdentation
;; added after a return, raise, break, pass, or continue statement.
;; Defeated by prefixing command with C-u.
;; - New py-electric-colon (:) command for improved outdenting Also
;; py-indent-line (TAB) should handle outdented lines better
;; - improved (I think) C-c > and C-c <
;; - py-(forward|backward)-into-nomenclature, not bound, but useful on
;; M-f and M-b respectively.
;; - integration with imenu by Perry A. Stoll <stoll@atr-sw.atr.co.jp>
;; - py-indent-offset now defaults to 4
;; - new variable py-honor-comment-indentation
;; - comment-region bound to C-c #
;; - py-delete-char obeys numeric arguments
;; - Small modification to rule for "indenting comment lines", such
;; lines must now also be indented less than or equal to the
;; indentation of the previous statement.
;; Here's a brief to do list: ;; Here's a brief to do list:
;; ;;
...@@ -89,14 +76,6 @@ ...@@ -89,14 +76,6 @@
;; - Add a py-goto-error or some such that would scan an exception in ;; - Add a py-goto-error or some such that would scan an exception in
;; the py-shell buffer, and pop you to that line in the file. ;; the py-shell buffer, and pop you to that line in the file.
;; If you can think of more things you'd like to see, drop me a line.
;; If you want to report bugs, use py-submit-bug-report (C-c C-b).
;;
;; Note that I only test things on XEmacs 19 and to some degree on
;; Emacs 19. If you port stuff to FSF Emacs 19, or Emacs 18, please
;; send me your patches. Byte compiler complaints can probably be
;; safely ignored.
;;; Code: ;;; Code:
(require 'custom) (require 'custom)
...@@ -157,7 +136,8 @@ indentation hints, unless the comment character is in column zero." ...@@ -157,7 +136,8 @@ indentation hints, unless the comment character is in column zero."
:type '(choice :type '(choice
(const :tag "Skip all comment lines (fast)" nil) (const :tag "Skip all comment lines (fast)" nil)
(const :tag "Single # `sets' indentation for next line" t) (const :tag "Single # `sets' indentation for next line" t)
(const :tag "Single # `sets' indentation except at column zero" other) (const :tag "Single # `sets' indentation except at column zero"
other)
) )
:group 'python) :group 'python)
...@@ -253,7 +233,7 @@ supported list, along with the values for this variable: ...@@ -253,7 +233,7 @@ supported list, along with the values for this variable:
") ")
(defvar python-font-lock-keywords (defvar python-font-lock-keywords
(let* ((keywords '("and" "break" "class" (let* ((keywords '("and" "assert" "break" "class"
"continue" "def" "del" "elif" "continue" "def" "del" "elif"
"else:" "except" "except:" "exec" "else:" "except" "except:" "exec"
"finally:" "for" "from" "global" "finally:" "for" "from" "global"
...@@ -330,16 +310,22 @@ Currently-active file is at the head of the list.") ...@@ -330,16 +310,22 @@ Currently-active file is at the head of the list.")
"\\)")) "\\)"))
;; Regexp matching keywords which typically close a block
(defconst py-block-closing-keywords-re
"\\(return\\|raise\\|break\\|continue\\|pass\\)")
;; Regexp matching lines to not outdent after. ;; Regexp matching lines to not outdent after.
(defconst py-no-outdent-re (defconst py-no-outdent-re
(concat "\\(" (mapconcat 'identity (concat
'("try:" "\\("
(mapconcat 'identity
(list "try:"
"except\\(\\s +.*\\)?:" "except\\(\\s +.*\\)?:"
"while\\s +.*:" "while\\s +.*:"
"for\\s +.*:" "for\\s +.*:"
"if\\s +.*:" "if\\s +.*:"
"elif\\s +.*:" "elif\\s +.*:"
"\\(return\\|break\\|raise\\|continue\\)[ \t\n]" (concat py-block-closing-keywords-re "[ \t\n]")
) )
"\\|") "\\|")
"\\)")) "\\)"))
...@@ -903,7 +889,7 @@ filter." ...@@ -903,7 +889,7 @@ filter."
(switch-to-buffer-other-window (make-comint "Python" py-python-command)) (switch-to-buffer-other-window (make-comint "Python" py-python-command))
(make-local-variable 'comint-prompt-regexp) (make-local-variable 'comint-prompt-regexp)
(setq comint-prompt-regexp "^>>> \\|^[.][.][.] ") (setq comint-prompt-regexp "^>>> \\|^[.][.][.] ")
(set-process-filter (get-buffer-process (current-buffer)) 'py-process-filter) (set-process-filter (get-buffer-process (current-buffer)) nil)
(set-syntax-table py-mode-syntax-table) (set-syntax-table py-mode-syntax-table)
(local-set-key [tab] 'self-insert-command)) (local-set-key [tab] 'self-insert-command))
...@@ -940,11 +926,17 @@ practice, unless you're trying to be a jerk <grin>. ...@@ -940,11 +926,17 @@ practice, unless you're trying to be a jerk <grin>.
See the `\\[py-shell]' docs for additional warnings." See the `\\[py-shell]' docs for additional warnings."
(interactive "r") (interactive "r")
(or (< start end) (error "Region is empty")) (or (< start end)
(error "Region is empty"))
(let ((pyproc (get-process "Python")) (let ((pyproc (get-process "Python"))
fname) fname)
(if (null pyproc) (if (null pyproc)
(shell-command-on-region start end py-python-command) (let ((outbuf "*Python Output*"))
(shell-command-on-region start end py-python-command outbuf)
(save-excursion
(set-buffer outbuf)
;; TBD: ???
(goto-char (point-max))))
;; else feed it thru a temp file ;; else feed it thru a temp file
(setq fname (py-make-temp-name)) (setq fname (py-make-temp-name))
(write-region start end fname nil 'no-msg) (write-region start end fname nil 'no-msg)
...@@ -2248,10 +2240,7 @@ local bindings to py-newline-and-indent.")) ...@@ -2248,10 +2240,7 @@ local bindings to py-newline-and-indent."))
(if (and (not (zerop (car state))) (if (and (not (zerop (car state)))
(not (eobp))) (not (eobp)))
(progn (progn
(parse-partial-sexp (point) (point-max) (parse-partial-sexp (point) (point-max) 0 nil state)
(if py-parse-partial-sexp-works-p
0 (- 0 (car state)))
nil state)
(forward-line 1)))))) (forward-line 1))))))
;; t iff statement opens a block == iff it ends with a colon that's ;; t iff statement opens a block == iff it ends with a colon that's
...@@ -2290,7 +2279,7 @@ local bindings to py-newline-and-indent.")) ...@@ -2290,7 +2279,7 @@ local bindings to py-newline-and-indent."))
(let ((here (point))) (let ((here (point)))
(back-to-indentation) (back-to-indentation)
(prog1 (prog1
(looking-at "\\(return\\|raise\\|break\\|continue\\|pass\\)\\>") (looking-at (concat py-block-closing-keywords-re "\\>"))
(goto-char here)))) (goto-char here))))
;; go to point right beyond final line of block begun by the current ;; go to point right beyond final line of block begun by the current
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment