diff options
| author | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-03-25 16:37:21 -0400 |
| commit | 699c782b7668c44d0fa4446331b0590a6d5dac82 (patch) | |
| tree | 5dcce364741d0761920a3d274b0fc8aba4103d45 /lisp/progmodes/python.el | |
| parent | 98fb480ee31bf74cf554044f60f21df16566dd7f (diff) | |
| parent | e99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff) | |
| download | emacs-699c782b7668c44d0fa4446331b0590a6d5dac82.tar.gz emacs-699c782b7668c44d0fa4446331b0590a6d5dac82.zip | |
Merge from trunkpending
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 59 |
1 files changed, 21 insertions, 38 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 4d2f15c69d8..3ef872d26eb 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; python.el --- silly walks for Python -*- coding: iso-8859-1 -*- | 1 | ;;; python.el --- silly walks for Python -*- coding: iso-8859-1 -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2003-2011 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Dave Love <fx@gnu.org> | 5 | ;; Author: Dave Love <fx@gnu.org> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -67,6 +67,7 @@ | |||
| 67 | ;;; Code: | 67 | ;;; Code: |
| 68 | 68 | ||
| 69 | (require 'comint) | 69 | (require 'comint) |
| 70 | (require 'ansi-color) | ||
| 70 | 71 | ||
| 71 | (eval-when-compile | 72 | (eval-when-compile |
| 72 | (require 'compile) | 73 | (require 'compile) |
| @@ -86,7 +87,6 @@ | |||
| 86 | (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode)) | 87 | (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode)) |
| 87 | ;;;###autoload | 88 | ;;;###autoload |
| 88 | (add-to-list 'auto-mode-alist (cons (purecopy "\\.py\\'") 'python-mode)) | 89 | (add-to-list 'auto-mode-alist (cons (purecopy "\\.py\\'") 'python-mode)) |
| 89 | (add-to-list 'same-window-buffer-names (purecopy "*Python*")) | ||
| 90 | 90 | ||
| 91 | ;;;; Font lock | 91 | ;;;; Font lock |
| 92 | 92 | ||
| @@ -120,7 +120,7 @@ | |||
| 120 | (1 font-lock-type-face)) | 120 | (1 font-lock-type-face)) |
| 121 | ;; Built-ins. (The next three blocks are from | 121 | ;; Built-ins. (The next three blocks are from |
| 122 | ;; `__builtin__.__dict__.keys()' in Python 2.7) These patterns | 122 | ;; `__builtin__.__dict__.keys()' in Python 2.7) These patterns |
| 123 | ;; are debateable, but they at least help to spot possible | 123 | ;; are debatable, but they at least help to spot possible |
| 124 | ;; shadowing of builtins. | 124 | ;; shadowing of builtins. |
| 125 | (,(rx symbol-start (or | 125 | (,(rx symbol-start (or |
| 126 | ;; exceptions | 126 | ;; exceptions |
| @@ -296,7 +296,7 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)." | |||
| 296 | :filter (lambda (&rest junk) | 296 | :filter (lambda (&rest junk) |
| 297 | (abbrev-table-menu python-mode-abbrev-table))) | 297 | (abbrev-table-menu python-mode-abbrev-table))) |
| 298 | "-" | 298 | "-" |
| 299 | ["Start interpreter" python-shell | 299 | ["Start interpreter" run-python |
| 300 | :help "Run `inferior' Python in separate buffer"] | 300 | :help "Run `inferior' Python in separate buffer"] |
| 301 | ["Import/reload file" python-load-file | 301 | ["Import/reload file" python-load-file |
| 302 | :help "Load into inferior Python session"] | 302 | :help "Load into inferior Python session"] |
| @@ -328,14 +328,6 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)." | |||
| 328 | ;; eric has items including: (un)indent, (un)comment, restart script, | 328 | ;; eric has items including: (un)indent, (un)comment, restart script, |
| 329 | ;; run script, debug script; also things for profiling, unit testing. | 329 | ;; run script, debug script; also things for profiling, unit testing. |
| 330 | 330 | ||
| 331 | (defvar python-shell-map | ||
| 332 | (let ((map (copy-keymap comint-mode-map))) | ||
| 333 | (define-key map [tab] 'tab-to-tab-stop) | ||
| 334 | (define-key map "\C-c-" 'py-up-exception) | ||
| 335 | (define-key map "\C-c=" 'py-down-exception) | ||
| 336 | map) | ||
| 337 | "Keymap used in *Python* shell buffers.") | ||
| 338 | |||
| 339 | (defvar python-mode-syntax-table | 331 | (defvar python-mode-syntax-table |
| 340 | (let ((table (make-syntax-table))) | 332 | (let ((table (make-syntax-table))) |
| 341 | ;; Give punctuation syntax to ASCII that normally has symbol | 333 | ;; Give punctuation syntax to ASCII that normally has symbol |
| @@ -559,7 +551,7 @@ element matches `python-python-command'." | |||
| 559 | "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" | 551 | "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" |
| 560 | "Regular expression pdbtrack uses to find a stack trace entry.") | 552 | "Regular expression pdbtrack uses to find a stack trace entry.") |
| 561 | 553 | ||
| 562 | (defconst python-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ " | 554 | (defconst python-pdbtrack-input-prompt "\n[(<]*[Ii]?[Pp]db[>)]+ " |
| 563 | "Regular expression pdbtrack uses to recognize a pdb prompt.") | 555 | "Regular expression pdbtrack uses to recognize a pdb prompt.") |
| 564 | 556 | ||
| 565 | (defconst python-pdbtrack-track-range 10000 | 557 | (defconst python-pdbtrack-track-range 10000 |
| @@ -957,22 +949,12 @@ Finds end of innermost nested class or method definition." | |||
| 957 | "Go to start of current statement. | 949 | "Go to start of current statement. |
| 958 | Accounts for continuation lines, multi-line strings, and | 950 | Accounts for continuation lines, multi-line strings, and |
| 959 | multi-line bracketed expressions." | 951 | multi-line bracketed expressions." |
| 960 | (beginning-of-line) | 952 | (while |
| 961 | (python-beginning-of-string) | ||
| 962 | (let (point) | ||
| 963 | (while (and (python-continuation-line-p) | ||
| 964 | (if point | ||
| 965 | (< (point) point) | ||
| 966 | t)) | ||
| 967 | (beginning-of-line) | ||
| 968 | (if (python-backslash-continuation-line-p) | 953 | (if (python-backslash-continuation-line-p) |
| 969 | (progn | 954 | (progn (forward-line -1) t) |
| 970 | (forward-line -1) | 955 | (beginning-of-line) |
| 971 | (while (python-backslash-continuation-line-p) | 956 | (or (python-beginning-of-string) |
| 972 | (forward-line -1))) | 957 | (python-skip-out)))) |
| 973 | (python-beginning-of-string) | ||
| 974 | (python-skip-out)) | ||
| 975 | (setq point (point)))) | ||
| 976 | (back-to-indentation)) | 958 | (back-to-indentation)) |
| 977 | 959 | ||
| 978 | (defun python-skip-out (&optional forward syntax) | 960 | (defun python-skip-out (&optional forward syntax) |
| @@ -980,6 +962,7 @@ multi-line bracketed expressions." | |||
| 980 | Skip forward if FORWARD is non-nil, else backward. | 962 | Skip forward if FORWARD is non-nil, else backward. |
| 981 | If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point. | 963 | If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point. |
| 982 | Return non-nil if and only if skipping was done." | 964 | Return non-nil if and only if skipping was done." |
| 965 | ;; FIXME: Use syntax-ppss-toplevel-pos. | ||
| 983 | (let ((depth (syntax-ppss-depth (or syntax (syntax-ppss)))) | 966 | (let ((depth (syntax-ppss-depth (or syntax (syntax-ppss)))) |
| 984 | (forward (if forward -1 1))) | 967 | (forward (if forward -1 1))) |
| 985 | (unless (zerop depth) | 968 | (unless (zerop depth) |
| @@ -1021,9 +1004,10 @@ On a comment line, go to end of line." | |||
| 1021 | (error (goto-char pos) (end-of-line))))) | 1004 | (error (goto-char pos) (end-of-line))))) |
| 1022 | ((python-skip-out t s)))) | 1005 | ((python-skip-out t s)))) |
| 1023 | (end-of-line)) | 1006 | (end-of-line)) |
| 1024 | (unless comment | 1007 | (and (not comment) |
| 1025 | (eq ?\\ (char-before)))) ; Line continued? | 1008 | (not (eobp)) |
| 1026 | (end-of-line 2)) ; Try next line. | 1009 | (eq ?\\ (char-before)))) ; Line continued? |
| 1010 | (end-of-line 2)) ; Try next line. | ||
| 1027 | (point)) | 1011 | (point)) |
| 1028 | 1012 | ||
| 1029 | (defun python-previous-statement (&optional count) | 1013 | (defun python-previous-statement (&optional count) |
| @@ -1140,7 +1124,7 @@ don't move and return nil. Otherwise return t." | |||
| 1140 | 1124 | ||
| 1141 | ;;;; Imenu. | 1125 | ;;;; Imenu. |
| 1142 | 1126 | ||
| 1143 | ;; For possibily speeding this up, here's the top of the ELP profile | 1127 | ;; For possibly speeding this up, here's the top of the ELP profile |
| 1144 | ;; for rescanning pydoc.py (2.2k lines, 90kb): | 1128 | ;; for rescanning pydoc.py (2.2k lines, 90kb): |
| 1145 | ;; Function Name Call Count Elapsed Time Average Time | 1129 | ;; Function Name Call Count Elapsed Time Average Time |
| 1146 | ;; ==================================== ========== ============= ============ | 1130 | ;; ==================================== ========== ============= ============ |
| @@ -1345,7 +1329,7 @@ local value.") | |||
| 1345 | (define-key map "\C-c\C-l" 'python-load-file) | 1329 | (define-key map "\C-c\C-l" 'python-load-file) |
| 1346 | (define-key map "\C-c\C-v" 'python-check) | 1330 | (define-key map "\C-c\C-v" 'python-check) |
| 1347 | ;; Note that we _can_ still use these commands which send to the | 1331 | ;; Note that we _can_ still use these commands which send to the |
| 1348 | ;; Python process even at the prompt iff we have a normal prompt, | 1332 | ;; Python process even at the prompt if we have a normal prompt, |
| 1349 | ;; i.e. '>>> ' and not '... '. See the comment before | 1333 | ;; i.e. '>>> ' and not '... '. See the comment before |
| 1350 | ;; python-send-region. Fixme: uncomment these if we address that. | 1334 | ;; python-send-region. Fixme: uncomment these if we address that. |
| 1351 | 1335 | ||
| @@ -1404,7 +1388,6 @@ For running multiple processes in multiple buffers, see `run-python' and | |||
| 1404 | 1388 | ||
| 1405 | \\{inferior-python-mode-map}" | 1389 | \\{inferior-python-mode-map}" |
| 1406 | :group 'python | 1390 | :group 'python |
| 1407 | (require 'ansi-color) ; for ipython | ||
| 1408 | (setq mode-line-process '(":%s")) | 1391 | (setq mode-line-process '(":%s")) |
| 1409 | (set (make-local-variable 'comint-input-filter) 'python-input-filter) | 1392 | (set (make-local-variable 'comint-input-filter) 'python-input-filter) |
| 1410 | (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter | 1393 | (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter |
| @@ -1548,7 +1531,6 @@ behavior, change `python-remove-cwd-from-path' to nil." | |||
| 1548 | (interactive (if current-prefix-arg | 1531 | (interactive (if current-prefix-arg |
| 1549 | (list (read-string "Run Python: " python-command) nil t) | 1532 | (list (read-string "Run Python: " python-command) nil t) |
| 1550 | (list python-command))) | 1533 | (list python-command))) |
| 1551 | (require 'ansi-color) ; for ipython | ||
| 1552 | (unless cmd (setq cmd python-command)) | 1534 | (unless cmd (setq cmd python-command)) |
| 1553 | (python-check-version cmd) | 1535 | (python-check-version cmd) |
| 1554 | (setq python-command cmd) | 1536 | (setq python-command cmd) |
| @@ -1567,7 +1549,7 @@ behavior, change `python-remove-cwd-from-path' to nil." | |||
| 1567 | (if path (concat path path-separator)) | 1549 | (if path (concat path path-separator)) |
| 1568 | data-directory) | 1550 | data-directory) |
| 1569 | process-environment)) | 1551 | process-environment)) |
| 1570 | ;; If we use a pipe, unicode characters are not printed | 1552 | ;; If we use a pipe, Unicode characters are not printed |
| 1571 | ;; correctly (Bug#5794) and IPython does not work at | 1553 | ;; correctly (Bug#5794) and IPython does not work at |
| 1572 | ;; all (Bug#5390). | 1554 | ;; all (Bug#5390). |
| 1573 | (process-connection-type t)) | 1555 | (process-connection-type t)) |
| @@ -2361,7 +2343,7 @@ Interactively, prompt for the name with completion." | |||
| 2361 | ;;;; Bicycle Repair Man support | 2343 | ;;;; Bicycle Repair Man support |
| 2362 | 2344 | ||
| 2363 | (autoload 'pymacs-load "pymacs" nil t) | 2345 | (autoload 'pymacs-load "pymacs" nil t) |
| 2364 | (autoload 'brm-init "bikemacs") | 2346 | (autoload 'brm-init "bikeemacs") |
| 2365 | (defvar brm-menu) | 2347 | (defvar brm-menu) |
| 2366 | 2348 | ||
| 2367 | ;; I'm not sure how useful BRM really is, and it's certainly dangerous | 2349 | ;; I'm not sure how useful BRM really is, and it's certainly dangerous |
| @@ -2571,7 +2553,7 @@ If the traceback target file path is invalid, we look for the | |||
| 2571 | most recently visited python-mode buffer which either has the | 2553 | most recently visited python-mode buffer which either has the |
| 2572 | name of the current function or class, or which defines the | 2554 | name of the current function or class, or which defines the |
| 2573 | function or class. This is to provide for scripts not in the | 2555 | function or class. This is to provide for scripts not in the |
| 2574 | local filesytem (e.g., Zope's 'Script \(Python)', but it's not | 2556 | local file system (e.g., Zope's 'Script \(Python)', but it's not |
| 2575 | Zope specific). If you put a copy of the script in a buffer | 2557 | Zope specific). If you put a copy of the script in a buffer |
| 2576 | named for the script and activate python-mode, then pdbtrack will | 2558 | named for the script and activate python-mode, then pdbtrack will |
| 2577 | find it." | 2559 | find it." |
| @@ -2601,6 +2583,7 @@ find it." | |||
| 2601 | (if (not (string-match (concat python-pdbtrack-input-prompt "$") block)) | 2583 | (if (not (string-match (concat python-pdbtrack-input-prompt "$") block)) |
| 2602 | (python-pdbtrack-overlay-arrow nil) | 2584 | (python-pdbtrack-overlay-arrow nil) |
| 2603 | 2585 | ||
| 2586 | (setq block (ansi-color-filter-apply block)) | ||
| 2604 | (setq target (python-pdbtrack-get-source-buffer block)) | 2587 | (setq target (python-pdbtrack-get-source-buffer block)) |
| 2605 | 2588 | ||
| 2606 | (if (stringp target) | 2589 | (if (stringp target) |