Mercurial > hg > xemacs-beta
comparison lisp/modes/python-mode.el @ 22:8fc7fe29b841 r19-15b94
Import from CVS: tag r19-15b94
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:50:29 +0200 |
parents | b82b59fe008d |
children | 441bb1e64a06 |
comparison
equal
deleted
inserted
replaced
21:b88636d63495 | 22:8fc7fe29b841 |
---|---|
1 ;;; python-mode.el --- Major mode for editing Python programs | 1 ;;; python-mode.el --- Major mode for editing Python programs |
2 | 2 |
3 ;; Copyright (C) 1992,1993,1994 Tim Peters | 3 ;; Copyright (C) 1992,1993,1994 Tim Peters |
4 | 4 |
5 ;; Author: 1995-1996 Barry A. Warsaw | 5 ;; Author: 1995-1997 Barry A. Warsaw |
6 ;; 1992-1994 Tim Peters | 6 ;; 1992-1994 Tim Peters |
7 ;; Maintainer: python-mode@python.org | 7 ;; Maintainer: python-mode@python.org |
8 ;; Created: Feb 1992 | 8 ;; Created: Feb 1992 |
9 ;; Version: 2.83 | 9 ;; Version: 2.89 |
10 ;; Last Modified: 1996/10/23 20:44:59 | 10 ;; Last Modified: 1997/01/30 20:16:18 |
11 ;; Keywords: python languages oop | 11 ;; Keywords: python languages oop |
12 | 12 |
13 ;; This software is provided as-is, without express or implied | 13 ;; This software is provided as-is, without express or implied |
14 ;; warranty. Permission to use, copy, modify, distribute or sell this | 14 ;; warranty. Permission to use, copy, modify, distribute or sell this |
15 ;; software, without fee, for any purpose and by any individual or | 15 ;; software, without fee, for any purpose and by any individual or |
272 | 272 |
273 ;; in previous version of python-mode.el, the hook was incorrectly | 273 ;; in previous version of python-mode.el, the hook was incorrectly |
274 ;; called py-mode-hook, and was not defvar'd. deprecate its use. | 274 ;; called py-mode-hook, and was not defvar'd. deprecate its use. |
275 (and (fboundp 'make-obsolete-variable) | 275 (and (fboundp 'make-obsolete-variable) |
276 (make-obsolete-variable 'py-mode-hook 'python-mode-hook)) | 276 (make-obsolete-variable 'py-mode-hook 'python-mode-hook)) |
277 | |
278 (defvar py-delete-function 'backward-delete-char-untabify | |
279 "*Function called by `py-delete-char' when deleting characters.") | |
277 | 280 |
278 (defvar py-mode-map () | 281 (defvar py-mode-map () |
279 "Keymap used in `python-mode' buffers.") | 282 "Keymap used in `python-mode' buffers.") |
280 | 283 |
281 (if py-mode-map | 284 (if py-mode-map |
405 "Regexp for finding a class name. | 408 "Regexp for finding a class name. |
406 | 409 |
407 If you change this, you probably have to change `py-current-defun' as well. | 410 If you change this, you probably have to change `py-current-defun' as well. |
408 This is only used by `py-current-defun' to find the name for add-log.el.") | 411 This is only used by `py-current-defun' to find the name for add-log.el.") |
409 | 412 |
413 ;; As of 30-Jan-1997, Emacs 19.34 works but XEmacs 19.15b90 and | |
414 ;; previous does not. It is suspected that Emacsen before 19.34 are | |
415 ;; also broken. | |
416 (defvar py-parse-partial-sexp-works-p | |
417 (let ((buf (get-buffer-create " ---*---pps---*---")) | |
418 state status) | |
419 (save-excursion | |
420 (set-buffer buf) | |
421 (erase-buffer) | |
422 (insert "(line1\n line2)\nline3") | |
423 (lisp-mode) | |
424 (goto-char (point-min)) | |
425 (setq state (parse-partial-sexp (point) (save-excursion | |
426 (forward-line 1) | |
427 (point)))) | |
428 (parse-partial-sexp (point) (point-max) 0 nil state) | |
429 (setq status (not (= (point) (point-max)))) | |
430 (kill-buffer buf) | |
431 status)) | |
432 "Does `parse-partial-sexp' work in this Emacs?") | |
410 | 433 |
411 | 434 |
412 ;; Menu definitions, only relevent if you have the easymenu.el package | 435 ;; Menu definitions, only relevent if you have the easymenu.el package |
413 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions). | 436 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions). |
414 (defvar py-menu nil | 437 (defvar py-menu nil |
422 (require 'easymenu) | 445 (require 'easymenu) |
423 (error nil)) | 446 (error nil)) |
424 (easy-menu-define | 447 (easy-menu-define |
425 py-menu py-mode-map "Python Mode menu" | 448 py-menu py-mode-map "Python Mode menu" |
426 '("Python" | 449 '("Python" |
427 ["Comment Out Region" comment-region (mark)] | 450 ["Comment Out Region" py-comment-region (mark)] |
428 ["Uncomment Region" (comment-region (point) (mark) '(4)) (mark)] | 451 ["Uncomment Region" (py-comment-region (point) (mark) '(4)) (mark)] |
429 "-" | 452 "-" |
430 ["Mark current block" py-mark-block t] | 453 ["Mark current block" py-mark-block t] |
431 ["Mark current def" mark-python-def-or-class t] | 454 ["Mark current def" mark-python-def-or-class t] |
432 ["Mark current class" (mark-python-def-or-class t) t] | 455 ["Mark current class" (mark-python-def-or-class t) t] |
433 "-" | 456 "-" |
680 (make-local-variable 'font-lock-defaults) | 703 (make-local-variable 'font-lock-defaults) |
681 (make-local-variable 'paragraph-separate) | 704 (make-local-variable 'paragraph-separate) |
682 (make-local-variable 'paragraph-start) | 705 (make-local-variable 'paragraph-start) |
683 (make-local-variable 'require-final-newline) | 706 (make-local-variable 'require-final-newline) |
684 (make-local-variable 'comment-start) | 707 (make-local-variable 'comment-start) |
708 (make-local-variable 'comment-end) | |
685 (make-local-variable 'comment-start-skip) | 709 (make-local-variable 'comment-start-skip) |
686 (make-local-variable 'comment-column) | 710 (make-local-variable 'comment-column) |
687 (make-local-variable 'indent-region-function) | 711 (make-local-variable 'indent-region-function) |
688 (make-local-variable 'indent-line-function) | 712 (make-local-variable 'indent-line-function) |
689 (make-local-variable 'add-log-current-defun-function) | 713 (make-local-variable 'add-log-current-defun-function) |
695 font-lock-defaults '(python-font-lock-keywords) | 719 font-lock-defaults '(python-font-lock-keywords) |
696 paragraph-separate "^[ \t]*$" | 720 paragraph-separate "^[ \t]*$" |
697 paragraph-start "^[ \t]*$" | 721 paragraph-start "^[ \t]*$" |
698 require-final-newline t | 722 require-final-newline t |
699 comment-start "# " | 723 comment-start "# " |
724 comment-end "" | |
700 comment-start-skip "# *" | 725 comment-start-skip "# *" |
701 comment-column 40 | 726 comment-column 40 |
702 indent-region-function 'py-indent-region | 727 indent-region-function 'py-indent-region |
703 indent-line-function 'py-indent-line | 728 indent-line-function 'py-indent-line |
704 ;; tell add-log.el how to find the current function/method/variable | 729 ;; tell add-log.el how to find the current function/method/variable |
988 | 1013 |
989 | 1014 |
990 ;; Functions for Python style indentation | 1015 ;; Functions for Python style indentation |
991 (defun py-delete-char (count) | 1016 (defun py-delete-char (count) |
992 "Reduce indentation or delete character. | 1017 "Reduce indentation or delete character. |
1018 | |
993 If point is at the leftmost column, deletes the preceding newline. | 1019 If point is at the leftmost column, deletes the preceding newline. |
1020 Deletion is performed by calling the function in `py-delete-function' | |
1021 with a single argument (the number of characters to delete). | |
994 | 1022 |
995 Else if point is at the leftmost non-blank character of a line that is | 1023 Else if point is at the leftmost non-blank character of a line that is |
996 neither a continuation line nor a non-indenting comment line, or if | 1024 neither a continuation line nor a non-indenting comment line, or if |
997 point is at the end of a blank line, reduces the indentation to match | 1025 point is at the end of a blank line, reduces the indentation to match |
998 that of the line that opened the current block of code. The line that | 1026 that of the line that opened the current block of code. The line that |
1007 (if (or (/= (current-indentation) (current-column)) | 1035 (if (or (/= (current-indentation) (current-column)) |
1008 (bolp) | 1036 (bolp) |
1009 (py-continuation-line-p) | 1037 (py-continuation-line-p) |
1010 (not py-honor-comment-indentation) | 1038 (not py-honor-comment-indentation) |
1011 (looking-at "#[^ \t\n]")) ; non-indenting # | 1039 (looking-at "#[^ \t\n]")) ; non-indenting # |
1012 (backward-delete-char-untabify count) | 1040 (funcall py-delete-function count) |
1013 ;; else indent the same as the colon line that opened the block | 1041 ;; else indent the same as the colon line that opened the block |
1014 | 1042 |
1015 ;; force non-blank so py-goto-block-up doesn't ignore it | 1043 ;; force non-blank so py-goto-block-up doesn't ignore it |
1016 (insert-char ?* 1) | 1044 (insert-char ?* 1) |
1017 (backward-char) | 1045 (backward-char) |
2193 ;; if in nest, zip to the end of the nest | 2221 ;; if in nest, zip to the end of the nest |
2194 (setq state (py-parse-state)) | 2222 (setq state (py-parse-state)) |
2195 (if (and (not (zerop (car state))) | 2223 (if (and (not (zerop (car state))) |
2196 (not (eobp))) | 2224 (not (eobp))) |
2197 (progn | 2225 (progn |
2198 ;; BUG ALERT: I could swear, from reading the docs, that | 2226 (parse-partial-sexp (point) (point-max) |
2199 ;; the 3rd argument should be plain 0 | 2227 (if py-parse-partial-sexp-works-p |
2200 (parse-partial-sexp (point) (point-max) (- 0 (car state)) | 2228 0 (- 0 (car state))) |
2201 nil state) | 2229 nil state) |
2202 (forward-line 1)))))) | 2230 (forward-line 1)))))) |
2203 | 2231 |
2204 ;; t iff statement opens a block == iff it ends with a colon that's | 2232 ;; t iff statement opens a block == iff it ends with a colon that's |
2205 ;; not in a comment. point should be at the start of a statement | 2233 ;; not in a comment. point should be at the start of a statement |
2359 py-this-is-lucid-emacs-p)) | 2387 py-this-is-lucid-emacs-p)) |
2360 (move-marker last-input-end (point))) ; muck w/ shell-mode | 2388 (move-marker last-input-end (point))) ; muck w/ shell-mode |
2361 (set-buffer cbuf)) | 2389 (set-buffer cbuf)) |
2362 (sit-for 0)) | 2390 (sit-for 0)) |
2363 | 2391 |
2392 ;; older Emacsen don't have this function | |
2393 (if (not (fboundp 'match-string)) | |
2394 (defun match-string (n) | |
2395 (let ((beg (match-beginning n)) | |
2396 (end (match-end n))) | |
2397 (if (and beg end) | |
2398 (buffer-substring beg end) | |
2399 nil)))) | |
2400 | |
2364 (defun py-current-defun () | 2401 (defun py-current-defun () |
2365 ;; tell add-log.el how to find the current function/method/variable | 2402 ;; tell add-log.el how to find the current function/method/variable |
2366 (save-excursion | 2403 (save-excursion |
2367 (if (re-search-backward py-defun-start-re nil t) | 2404 (if (re-search-backward py-defun-start-re nil t) |
2368 (or (match-string 3) | 2405 (or (match-string 3) |
2372 (concat (match-string 1) "." method) | 2409 (concat (match-string 1) "." method) |
2373 method))) | 2410 method))) |
2374 nil))) | 2411 nil))) |
2375 | 2412 |
2376 | 2413 |
2377 (defconst py-version "2.83" | 2414 (defconst py-version "2.89" |
2378 "`python-mode' version number.") | 2415 "`python-mode' version number.") |
2379 (defconst py-help-address "python-mode@python.org" | 2416 (defconst py-help-address "python-mode@python.org" |
2380 "Address accepting submission of bug reports.") | 2417 "Address accepting submission of bug reports.") |
2381 | 2418 |
2382 (defun py-version () | 2419 (defun py-version () |