Mercurial > hg > xemacs-beta
comparison lisp/modes/python-mode.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | ac2d302a0011 |
children | 8fc7fe29b841 |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
4 | 4 |
5 ;; Author: 1995-1996 Barry A. Warsaw | 5 ;; Author: 1995-1996 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.67 | 9 ;; Version: 2.83 |
10 ;; Last Modified: 1996/08/01 20:11:51 | 10 ;; Last Modified: 1996/10/23 20:44:59 |
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 |
16 ;; organization, is hereby granted, provided that the above copyright | 16 ;; organization, is hereby granted, provided that the above copyright |
17 ;; notice and this paragraph appear in all copies. | 17 ;; notice and this paragraph appear in all copies. |
18 | 18 |
19 ;;; Commentary: | 19 ;;; Commentary: |
20 ;; | |
21 | 20 |
22 ;; This is a major mode for editing Python programs. It was developed | 21 ;; This is a major mode for editing Python programs. It was developed |
23 ;; by Tim Peters after an original idea by Michael A. Guravage. Tim | 22 ;; by Tim Peters after an original idea by Michael A. Guravage. Tim |
24 ;; left the net for a while and in the interim, Barry Warsaw has | 23 ;; subsequently left the net; in 1995, Barry Warsaw inherited the |
25 ;; undertaken maintenance of the mode. | 24 ;; mode and is the current maintainer. |
26 | 25 |
27 ;; At some point this mode will undergo a rewrite to bring it more in | 26 ;; At some point this mode will undergo a rewrite to bring it more in |
28 ;; line with GNU Emacs Lisp coding standards, and to wax all the Emacs | 27 ;; line with GNU Emacs Lisp coding standards, and to wax all the Emacs |
29 ;; 18 support. But all in all, the mode works exceedingly well, and | 28 ;; 18 support. But all in all, the mode works exceedingly well, and |
30 ;; I've simply been tweaking it as I go along. Ain't it wonderful | 29 ;; I've simply been tweaking it as I go along. Ain't it wonderful |
57 ;; - C-c C-v shows you the python-mode version | 56 ;; - C-c C-v shows you the python-mode version |
58 ;; - a basic python-font-lock-keywords has been added for (X)Emacs 19 | 57 ;; - a basic python-font-lock-keywords has been added for (X)Emacs 19 |
59 ;; - proper interaction with pending-del and del-sel modes. | 58 ;; - proper interaction with pending-del and del-sel modes. |
60 ;; - Better support for outdenting: py-electric-colon (:) and | 59 ;; - Better support for outdenting: py-electric-colon (:) and |
61 ;; py-indent-line (TAB) improvements; one level of outdentation | 60 ;; py-indent-line (TAB) improvements; one level of outdentation |
62 ;; added after a return, raise, break, or continue statement | 61 ;; added after a return, raise, break, pass, or continue statement. |
62 ;; Defeated by prefixing command with C-u. | |
63 ;; - New py-electric-colon (:) command for improved outdenting Also | 63 ;; - New py-electric-colon (:) command for improved outdenting Also |
64 ;; py-indent-line (TAB) should handle outdented lines better | 64 ;; py-indent-line (TAB) should handle outdented lines better |
65 ;; - improved (I think) C-c > and C-c < | 65 ;; - improved (I think) C-c > and C-c < |
66 ;; - py-(forward|backward)-into-nomenclature, not bound, but useful on | 66 ;; - py-(forward|backward)-into-nomenclature, not bound, but useful on |
67 ;; M-f and M-b respectively. | 67 ;; M-f and M-b respectively. |
82 ;; write-file-hooks that runs untabify on the whole buffer (to work | 82 ;; write-file-hooks that runs untabify on the whole buffer (to work |
83 ;; around potential tab/space mismatch problems). In practice this | 83 ;; around potential tab/space mismatch problems). In practice this |
84 ;; hasn't been a problem... yet. | 84 ;; hasn't been a problem... yet. |
85 ;; - have py-execute-region on indented code act as if the region is | 85 ;; - have py-execute-region on indented code act as if the region is |
86 ;; left justified. Avoids syntax errors. | 86 ;; left justified. Avoids syntax errors. |
87 ;; - Add a py-goto-error or some such that would scan an exception in | |
88 ;; the py-shell buffer, and pop you to that line in the file. | |
87 | 89 |
88 ;; If you can think of more things you'd like to see, drop me a line. | 90 ;; If you can think of more things you'd like to see, drop me a line. |
89 ;; If you want to report bugs, use py-submit-bug-report (C-c C-b). | 91 ;; If you want to report bugs, use py-submit-bug-report (C-c C-b). |
90 ;; | 92 ;; |
91 ;; Note that I only test things on XEmacs 19 and to some degree on | 93 ;; Note that I only test things on XEmacs 19 and to some degree on |
205 equal <number>, `tab-width' is set to <number>, a message saying so is | 207 equal <number>, `tab-width' is set to <number>, a message saying so is |
206 displayed in the echo area, and if `py-beep-if-tab-change' is non-nil | 208 displayed in the echo area, and if `py-beep-if-tab-change' is non-nil |
207 the Emacs bell is also rung as a warning.") | 209 the Emacs bell is also rung as a warning.") |
208 | 210 |
209 (defconst python-font-lock-keywords | 211 (defconst python-font-lock-keywords |
210 (let* ((keywords '("access" "and" "break" "class" | 212 (let* ((keywords '("and" "break" "class" |
211 "continue" "def" "del" "elif" | 213 "continue" "def" "del" "elif" |
212 "else:" "except" "except:" "exec" | 214 "else:" "except" "except:" "exec" |
213 "finally:" "for" "from" "global" | 215 "finally:" "for" "from" "global" |
214 "if" "import" "in" "is" | 216 "if" "import" "in" "is" |
215 "lambda" "not" "or" "pass" | 217 "lambda" "not" "or" "pass" |
383 '("try:" | 385 '("try:" |
384 "except\\(\\s +.*\\)?:" | 386 "except\\(\\s +.*\\)?:" |
385 "while\\s +.*:" | 387 "while\\s +.*:" |
386 "for\\s +.*:" | 388 "for\\s +.*:" |
387 "if\\s +.*:" | 389 "if\\s +.*:" |
388 "elif\\s +.*:") | 390 "elif\\s +.*:" |
391 "\\(return\\|break\\|raise\\|continue\\)[ \t\n]" | |
392 ) | |
389 "\\|") | 393 "\\|") |
390 "\\)") | 394 "\\)") |
391 "Regexp matching lines to not outdent after.") | 395 "Regexp matching lines to not outdent after.") |
392 | 396 |
397 (defvar py-defun-start-re | |
398 "^\\([ \t]*\\)def[ \t]+\\([a-zA-Z_0-9]+\\)\\|\\(^[a-zA-Z_0-9]+\\)[ \t]*=" | |
399 "Regexp matching a function, method or variable assignment. | |
400 | |
401 If you change this, you probably have to change `py-current-defun' as well. | |
402 This is only used by `py-current-defun' to find the name for add-log.el.") | |
403 | |
404 (defvar py-class-start-re "^class[ \t]*\\([a-zA-Z_0-9]+\\)" | |
405 "Regexp for finding a class name. | |
406 | |
407 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.") | |
409 | |
410 | |
393 | 411 |
394 ;; Menu definitions, only relevent if you have the easymenu.el package | 412 ;; Menu definitions, only relevent if you have the easymenu.el package |
395 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions). | 413 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions). |
414 (defvar py-menu nil | |
415 "Menu for Python Mode. | |
416 | |
417 This menu will get created automatically if you have the easymenu | |
418 package. Note that the latest XEmacs 19 and Emacs 19 versions contain | |
419 this package.") | |
420 | |
396 (if (condition-case nil | 421 (if (condition-case nil |
397 (require 'easymenu) | 422 (require 'easymenu) |
398 (error nil)) | 423 (error nil)) |
399 (easy-menu-define | 424 (easy-menu-define |
400 py-menu py-mode-map "Python Mode menu" | 425 py-menu py-mode-map "Python Mode menu" |
487 better alternative for finding the index.") | 512 better alternative for finding the index.") |
488 | 513 |
489 ;; These next two variables are used when searching for the python | 514 ;; These next two variables are used when searching for the python |
490 ;; class/definitions. Just saving some time in accessing the | 515 ;; class/definitions. Just saving some time in accessing the |
491 ;; generic-python-expression, really. | 516 ;; generic-python-expression, really. |
492 (defvar imenu-example--python-generic-regexp) | 517 (defvar imenu-example--python-generic-regexp nil) |
493 (defvar imenu-example--python-generic-parens) | 518 (defvar imenu-example--python-generic-parens nil) |
494 | 519 |
495 | 520 |
496 ;;;###autoload | 521 ;;;###autoload |
497 (eval-when-compile | 522 (eval-when-compile |
498 ;; Imenu isn't used in XEmacs, so just ignore load errors | 523 ;; Imenu isn't used in XEmacs, so just ignore load errors |
648 py-python-command\t\tshell command to invoke Python interpreter | 673 py-python-command\t\tshell command to invoke Python interpreter |
649 py-scroll-process-buffer\t\talways scroll Python process buffer | 674 py-scroll-process-buffer\t\talways scroll Python process buffer |
650 py-temp-directory\t\tdirectory used for temp files (if needed) | 675 py-temp-directory\t\tdirectory used for temp files (if needed) |
651 py-beep-if-tab-change\t\tring the bell if tab-width is changed" | 676 py-beep-if-tab-change\t\tring the bell if tab-width is changed" |
652 (interactive) | 677 (interactive) |
678 ;; set up local variables | |
653 (kill-all-local-variables) | 679 (kill-all-local-variables) |
680 (make-local-variable 'font-lock-defaults) | |
681 (make-local-variable 'paragraph-separate) | |
682 (make-local-variable 'paragraph-start) | |
683 (make-local-variable 'require-final-newline) | |
684 (make-local-variable 'comment-start) | |
685 (make-local-variable 'comment-start-skip) | |
686 (make-local-variable 'comment-column) | |
687 (make-local-variable 'indent-region-function) | |
688 (make-local-variable 'indent-line-function) | |
689 (make-local-variable 'add-log-current-defun-function) | |
690 ;; | |
654 (set-syntax-table py-mode-syntax-table) | 691 (set-syntax-table py-mode-syntax-table) |
655 (setq major-mode 'python-mode | 692 (setq major-mode 'python-mode |
656 mode-name "Python" | 693 mode-name "Python" |
657 local-abbrev-table python-mode-abbrev-table) | 694 local-abbrev-table python-mode-abbrev-table |
695 font-lock-defaults '(python-font-lock-keywords) | |
696 paragraph-separate "^[ \t]*$" | |
697 paragraph-start "^[ \t]*$" | |
698 require-final-newline t | |
699 comment-start "# " | |
700 comment-start-skip "# *" | |
701 comment-column 40 | |
702 indent-region-function 'py-indent-region | |
703 indent-line-function 'py-indent-line | |
704 ;; tell add-log.el how to find the current function/method/variable | |
705 add-log-current-defun-function 'py-current-defun | |
706 ) | |
658 (use-local-map py-mode-map) | 707 (use-local-map py-mode-map) |
659 ;; add the menu | 708 ;; add the menu |
660 (if py-menu | 709 (if py-menu |
661 (easy-menu-add py-menu)) | 710 (easy-menu-add py-menu)) |
662 ;; Emacs 19 requires this | 711 ;; Emacs 19 requires this |
663 (if (or py-this-is-lucid-emacs-p py-this-is-emacs-19-p) | 712 (if (or py-this-is-lucid-emacs-p py-this-is-emacs-19-p) |
664 (setq comment-multi-line nil)) | 713 (setq comment-multi-line nil)) |
665 ;; BAW -- style... | |
666 (mapcar (function (lambda (x) | |
667 (make-local-variable (car x)) | |
668 (set (car x) (cdr x)))) | |
669 '((paragraph-separate . "^[ \t]*$") | |
670 (paragraph-start . "^[ \t]*$") | |
671 (require-final-newline . t) | |
672 (comment-start . "# ") | |
673 (comment-start-skip . "# *") | |
674 (comment-column . 40) | |
675 (indent-region-function . py-indent-region) | |
676 (indent-line-function . py-indent-line))) | |
677 ;; hack to allow overriding the tabsize in the file (see tokenizer.c) | 714 ;; hack to allow overriding the tabsize in the file (see tokenizer.c) |
678 ;; | 715 ;; |
679 ;; not sure where the magic comment has to be; to save time | 716 ;; not sure where the magic comment has to be; to save time |
680 ;; searching for a rarity, we give up if it's not found prior to the | 717 ;; searching for a rarity, we give up if it's not found prior to the |
681 ;; first executable statement. | 718 ;; first executable statement. |
750 (point)))) | 787 (point)))) |
751 (not (or (nth 3 pps) (nth 4 pps))))) | 788 (not (or (nth 3 pps) (nth 4 pps))))) |
752 (save-excursion | 789 (save-excursion |
753 (let ((here (point)) | 790 (let ((here (point)) |
754 (outdent 0) | 791 (outdent 0) |
755 (indent (py-compute-indentation))) | 792 (indent (py-compute-indentation t))) |
756 (if (and (not arg) | 793 (if (and (not arg) |
757 (py-outdent-p) | 794 (py-outdent-p) |
758 (= indent (save-excursion | 795 (= indent (save-excursion |
759 (forward-line -1) | 796 (py-next-statement -1) |
760 (py-compute-indentation))) | 797 (py-compute-indentation t))) |
761 ) | 798 ) |
762 (setq outdent py-indent-offset)) | 799 (setq outdent py-indent-offset)) |
763 ;; Don't indent, only outdent. This assumes that any lines that | 800 ;; Don't indent, only outdent. This assumes that any lines that |
764 ;; are already outdented relative to py-compute-indentation were | 801 ;; are already outdented relative to py-compute-indentation were |
765 ;; put there on purpose. Its highly annoying to have `:' indent | 802 ;; put there on purpose. Its highly annoying to have `:' indent |
772 (indent-to (- indent outdent)) | 809 (indent-to (- indent outdent)) |
773 ))))) | 810 ))))) |
774 | 811 |
775 | 812 |
776 ;;; Functions that execute Python commands in a subprocess | 813 ;;; Functions that execute Python commands in a subprocess |
814 ;;;###autoload | |
777 (defun py-shell () | 815 (defun py-shell () |
778 "Start an interactive Python interpreter in another window. | 816 "Start an interactive Python interpreter in another window. |
779 This is like Shell mode, except that Python is running in the window | 817 This is like Shell mode, except that Python is running in the window |
780 instead of a shell. See the `Interactive Shell' and `Shell Mode' | 818 instead of a shell. See the `Interactive Shell' and `Shell Mode' |
781 sections of the Emacs manual for details, especially for the key | 819 sections of the Emacs manual for details, especially for the key |
893 ;; seems to make the Emacs command loop reluctant to update the | 931 ;; seems to make the Emacs command loop reluctant to update the |
894 ;; display. Perhaps the default process filter in process.c's | 932 ;; display. Perhaps the default process filter in process.c's |
895 ;; read_process_output has update_mode_lines++ for a similar | 933 ;; read_process_output has update_mode_lines++ for a similar |
896 ;; reason? beats me ... | 934 ;; reason? beats me ... |
897 | 935 |
898 ;; BAW - we want to check to see if this still applies | 936 (unwind-protect |
899 (if (eq curbuf pbuf) ; mysterious ugly hack | 937 ;; make sure current buffer is restored |
900 (set-buffer (get-buffer-create "*scratch*"))) | 938 ;; BAW - we want to check to see if this still applies |
901 | 939 (progn |
902 (set-buffer pbuf) | 940 ;; mysterious ugly hack |
903 (let* ((start (point)) | 941 (if (eq curbuf pbuf) |
904 (goback (< start pmark)) | 942 (set-buffer (get-buffer-create "*scratch*"))) |
905 (goend (and (not goback) (= start (point-max)))) | 943 |
906 (buffer-read-only nil)) | 944 (set-buffer pbuf) |
907 (goto-char pmark) | 945 (let* ((start (point)) |
908 (insert string) | 946 (goback (< start pmark)) |
909 (move-marker pmark (point)) | 947 (goend (and (not goback) (= start (point-max)))) |
910 (setq file-finished | 948 (buffer-read-only nil)) |
911 (and py-file-queue | 949 (goto-char pmark) |
912 (equal ">>> " | 950 (insert string) |
913 (buffer-substring | 951 (move-marker pmark (point)) |
914 (prog2 (beginning-of-line) (point) | 952 (setq file-finished |
915 (goto-char pmark)) | 953 (and py-file-queue |
916 (point))))) | 954 (equal ">>> " |
917 (if goback (goto-char start) | 955 (buffer-substring |
918 ;; else | 956 (prog2 (beginning-of-line) (point) |
919 (if py-scroll-process-buffer | 957 (goto-char pmark)) |
920 (let* ((pop-up-windows t) | 958 (point))))) |
921 (pwin (display-buffer pbuf))) | 959 (if goback (goto-char start) |
922 (set-window-point pwin (point))))) | 960 ;; else |
923 (set-buffer curbuf) | 961 (if py-scroll-process-buffer |
924 (if file-finished | 962 (let* ((pop-up-windows t) |
925 (progn | 963 (pwin (display-buffer pbuf))) |
926 (py-delete-file-silently (car py-file-queue)) | 964 (set-window-point pwin (point))))) |
927 (setq py-file-queue (cdr py-file-queue)) | 965 (set-buffer curbuf) |
928 (if py-file-queue | 966 (if file-finished |
929 (py-execute-file pyproc (car py-file-queue))))) | 967 (progn |
930 (and goend | 968 (py-delete-file-silently (car py-file-queue)) |
931 (progn (set-buffer pbuf) | 969 (setq py-file-queue (cdr py-file-queue)) |
932 (goto-char (point-max)))) | 970 (if py-file-queue |
933 ))) | 971 (py-execute-file pyproc (car py-file-queue))))) |
972 (and goend | |
973 (progn (set-buffer pbuf) | |
974 (goto-char (point-max)))) | |
975 )) | |
976 (set-buffer curbuf)))) | |
934 | 977 |
935 (defun py-execute-buffer () | 978 (defun py-execute-buffer () |
936 "Send the contents of the buffer to a Python interpreter. | 979 "Send the contents of the buffer to a Python interpreter. |
937 If there is a *Python* process buffer it is used. If a clipping | 980 If there is a *Python* process buffer it is used. If a clipping |
938 restriction is in effect, only the accessible portion of the buffer is | 981 restriction is in effect, only the accessible portion of the buffer is |
993 | 1036 |
994 ;; required for pending-del and delsel modes | 1037 ;; required for pending-del and delsel modes |
995 (put 'py-delete-char 'delete-selection 'supersede) | 1038 (put 'py-delete-char 'delete-selection 'supersede) |
996 (put 'py-delete-char 'pending-delete 'supersede) | 1039 (put 'py-delete-char 'pending-delete 'supersede) |
997 | 1040 |
998 (defun py-indent-line () | 1041 (defun py-indent-line (&optional arg) |
999 "Fix the indentation of the current line according to Python rules." | 1042 "Fix the indentation of the current line according to Python rules. |
1000 (interactive) | 1043 With \\[universal-argument], ignore outdenting rules for block |
1044 closing statements (e.g. return, raise, break, continue, pass) | |
1045 | |
1046 This function is normally bound to `indent-line-function' so | |
1047 \\[indent-for-tab-command] will call it." | |
1048 (interactive "P") | |
1001 (let* ((ci (current-indentation)) | 1049 (let* ((ci (current-indentation)) |
1002 (move-to-indentation-p (<= (current-column) ci)) | 1050 (move-to-indentation-p (<= (current-column) ci)) |
1003 (need (py-compute-indentation))) | 1051 (need (py-compute-indentation (not arg)))) |
1004 ;; see if we need to outdent | 1052 ;; see if we need to outdent |
1005 (if (py-outdent-p) | 1053 (if (py-outdent-p) |
1006 (setq need (- need py-indent-offset))) | 1054 (setq need (- need py-indent-offset))) |
1007 (if (/= ci need) | 1055 (if (/= ci need) |
1008 (save-excursion | 1056 (save-excursion |
1024 ;; else try to act like newline-and-indent "normally" acts | 1072 ;; else try to act like newline-and-indent "normally" acts |
1025 (beginning-of-line) | 1073 (beginning-of-line) |
1026 (insert-char ?\n 1) | 1074 (insert-char ?\n 1) |
1027 (move-to-column ci)))) | 1075 (move-to-column ci)))) |
1028 | 1076 |
1029 (defun py-compute-indentation () | 1077 (defun py-compute-indentation (honor-block-close-p) |
1078 ;; implements all the rules for indentation computation. when | |
1079 ;; honor-block-close-p is non-nil, statements such as return, raise, | |
1080 ;; break, continue, and pass force one level of outdenting. | |
1030 (save-excursion | 1081 (save-excursion |
1031 (let ((pps (parse-partial-sexp (save-excursion | 1082 (let ((pps (parse-partial-sexp (save-excursion |
1032 (beginning-of-python-def-or-class) | 1083 (beginning-of-python-def-or-class) |
1033 (point)) | 1084 (point)) |
1034 (point)))) | 1085 (point)))) |
1170 ;; strings. | 1221 ;; strings. |
1171 (py-goto-initial-line) | 1222 (py-goto-initial-line) |
1172 (+ (current-indentation) | 1223 (+ (current-indentation) |
1173 (if (py-statement-opens-block-p) | 1224 (if (py-statement-opens-block-p) |
1174 py-indent-offset | 1225 py-indent-offset |
1175 (if (py-statement-closes-block-p) | 1226 (if (and honor-block-close-p (py-statement-closes-block-p)) |
1176 (- py-indent-offset) | 1227 (- py-indent-offset) |
1177 0))) | 1228 0))) |
1178 ))))) | 1229 ))))) |
1179 | 1230 |
1180 (defun py-guess-indent-offset (&optional global) | 1231 (defun py-guess-indent-offset (&optional global) |
1330 (or indent-offset py-indent-offset))) | 1381 (or indent-offset py-indent-offset))) |
1331 (indents '(-1)) ; stack of active indent levels | 1382 (indents '(-1)) ; stack of active indent levels |
1332 (target-column 0) ; column to which to indent | 1383 (target-column 0) ; column to which to indent |
1333 (base-shifted-by 0) ; amount last base line was shifted | 1384 (base-shifted-by 0) ; amount last base line was shifted |
1334 (indent-base (if (looking-at "[ \t\n]") | 1385 (indent-base (if (looking-at "[ \t\n]") |
1335 (py-compute-indentation) | 1386 (py-compute-indentation t) |
1336 0)) | 1387 0)) |
1337 ci) | 1388 ci) |
1338 (while (< (point) end) | 1389 (while (< (point) end) |
1339 (setq ci (current-indentation)) | 1390 (setq ci (current-indentation)) |
1340 ;; figure out appropriate target column | 1391 ;; figure out appropriate target column |
1726 | 1777 |
1727 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores." | 1778 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores." |
1728 (interactive "p") | 1779 (interactive "p") |
1729 (let ((case-fold-search nil)) | 1780 (let ((case-fold-search nil)) |
1730 (if (> arg 0) | 1781 (if (> arg 0) |
1731 (re-search-forward "\\W*\\([A-Z_]*[a-z0-9]*\\)" (point-max) t arg) | 1782 (re-search-forward |
1783 "\\(\\W\\|[_]\\)*\\([A-Z]*[a-z0-9]*\\)" | |
1784 (point-max) t arg) | |
1732 (while (and (< arg 0) | 1785 (while (and (< arg 0) |
1733 (re-search-backward | 1786 (re-search-backward |
1734 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)" | 1787 "\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\(\\W\\|[_]\\)\\w+" |
1735 (point-min) 0)) | 1788 (point-min) 0)) |
1736 (forward-char 1) | 1789 (forward-char 1) |
1737 (setq arg (1+ arg))))) | 1790 (setq arg (1+ arg))))) |
1738 (py-keep-region-active)) | 1791 (py-keep-region-active)) |
1739 | 1792 |
1774 "Key(s): " | 1827 "Key(s): " |
1775 (mapconcat 'key-description | 1828 (mapconcat 'key-description |
1776 (where-is-internal func py-mode-map) | 1829 (where-is-internal func py-mode-map) |
1777 ", ")))) | 1830 ", ")))) |
1778 ((equal funckind "v") ; variable | 1831 ((equal funckind "v") ; variable |
1779 (setq funcdoc (substitute-command-keys | 1832 (setq funcdoc (documentation-property func 'variable-documentation) |
1780 (get func 'variable-documentation)) | |
1781 keys (if (assq func locals) | 1833 keys (if (assq func locals) |
1782 (concat | 1834 (concat |
1783 "Local/Global values: " | 1835 "Local/Global values: " |
1784 (prin1-to-string (symbol-value func)) | 1836 (prin1-to-string (symbol-value func)) |
1785 " / " | 1837 " / " |
2178 (setq searching nil))) | 2230 (setq searching nil))) |
2179 answer))) | 2231 answer))) |
2180 | 2232 |
2181 (defun py-statement-closes-block-p () | 2233 (defun py-statement-closes-block-p () |
2182 ;; true iff the current statement `closes' a block == the line | 2234 ;; true iff the current statement `closes' a block == the line |
2183 ;; starts with `return', `raise', `break' or `continue'. doesn't | 2235 ;; starts with `return', `raise', `break', `continue', and `pass'. |
2184 ;; catch embedded statements | 2236 ;; doesn't catch embedded statements |
2185 (let ((here (point))) | 2237 (let ((here (point))) |
2186 (back-to-indentation) | 2238 (back-to-indentation) |
2187 (prog1 | 2239 (prog1 |
2188 (looking-at "\\(return\\|raise\\|break\\|continue\\)\\>") | 2240 (looking-at "\\(return\\|raise\\|break\\|continue\\|pass\\)\\>") |
2189 (goto-char here)))) | 2241 (goto-char here)))) |
2190 | 2242 |
2191 ;; go to point right beyond final line of block begun by the current | 2243 ;; go to point right beyond final line of block begun by the current |
2192 ;; line. This is the same as where py-goto-beyond-final-line goes | 2244 ;; line. This is the same as where py-goto-beyond-final-line goes |
2193 ;; unless we're on colon line, in which case we go to the end of the | 2245 ;; unless we're on colon line, in which case we go to the end of the |
2307 py-this-is-lucid-emacs-p)) | 2359 py-this-is-lucid-emacs-p)) |
2308 (move-marker last-input-end (point))) ; muck w/ shell-mode | 2360 (move-marker last-input-end (point))) ; muck w/ shell-mode |
2309 (set-buffer cbuf)) | 2361 (set-buffer cbuf)) |
2310 (sit-for 0)) | 2362 (sit-for 0)) |
2311 | 2363 |
2364 (defun py-current-defun () | |
2365 ;; tell add-log.el how to find the current function/method/variable | |
2366 (save-excursion | |
2367 (if (re-search-backward py-defun-start-re nil t) | |
2368 (or (match-string 3) | |
2369 (let ((method (match-string 2))) | |
2370 (if (and (not (zerop (length (match-string 1)))) | |
2371 (re-search-backward py-class-start-re nil t)) | |
2372 (concat (match-string 1) "." method) | |
2373 method))) | |
2374 nil))) | |
2312 | 2375 |
2313 | 2376 |
2314 (defconst py-version "2.67" | 2377 (defconst py-version "2.83" |
2315 "`python-mode' version number.") | 2378 "`python-mode' version number.") |
2316 (defconst py-help-address "python-mode@python.org" | 2379 (defconst py-help-address "python-mode@python.org" |
2317 "Address accepting submission of bug reports.") | 2380 "Address accepting submission of bug reports.") |
2318 | 2381 |
2319 (defun py-version () | 2382 (defun py-version () |