diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 98 |
1 files changed, 56 insertions, 42 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index bfa507b851a..7a7e62d06ee 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | ;; Copyright (C) 2003, 04 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2003, 04 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Dave Love <fx@gnu.org> | 5 | ;; Author: Dave Love <fx@gnu.org> |
| 6 | ;; Maintainer: FSF | ||
| 6 | ;; Created: Nov 2003 | 7 | ;; Created: Nov 2003 |
| 7 | ;; Keywords: languages | 8 | ;; Keywords: languages |
| 8 | 9 | ||
| @@ -66,10 +67,8 @@ | |||
| 66 | (require 'comint) | 67 | (require 'comint) |
| 67 | (eval-when-compile | 68 | (eval-when-compile |
| 68 | (require 'compile) | 69 | (require 'compile) |
| 69 | (autoload 'Info-last "info") | ||
| 70 | (autoload 'Info-exit "info") | ||
| 71 | (autoload 'info-lookup-maybe-add-help "info-look")) | 70 | (autoload 'info-lookup-maybe-add-help "info-look")) |
| 72 | (autoload 'compilation-start "compile") ; spurious compiler warning anyway | 71 | (autoload 'compilation-start "compile") |
| 73 | 72 | ||
| 74 | (defgroup python nil | 73 | (defgroup python nil |
| 75 | "Silly walks in the Python language" | 74 | "Silly walks in the Python language" |
| @@ -829,7 +828,8 @@ move and return nil. Otherwise return t." | |||
| 829 | Makes nested Imenu menus from nested `class' and `def' statements. | 828 | Makes nested Imenu menus from nested `class' and `def' statements. |
| 830 | The nested menus are headed by an item referencing the outer | 829 | The nested menus are headed by an item referencing the outer |
| 831 | definition; it has a space prepended to the name so that it sorts | 830 | definition; it has a space prepended to the name so that it sorts |
| 832 | first with `imenu--sort-by-name'." | 831 | first with `imenu--sort-by-name' (though, unfortunately, sub-menus |
| 832 | precede it)." | ||
| 833 | (unless (boundp 'python-recursing) ; dynamically bound below | 833 | (unless (boundp 'python-recursing) ; dynamically bound below |
| 834 | (goto-char (point-min))) ; normal call from Imenu | 834 | (goto-char (point-min))) ; normal call from Imenu |
| 835 | (let (index-alist ; accumulated value to return | 835 | (let (index-alist ; accumulated value to return |
| @@ -937,32 +937,37 @@ Additional arguments are added when the command is used by `run-python' | |||
| 937 | et al.") | 937 | et al.") |
| 938 | 938 | ||
| 939 | (defvar python-buffer nil | 939 | (defvar python-buffer nil |
| 940 | "*The current python process buffer. | 940 | "The current python process buffer." |
| 941 | To run multiple Python processes, start the first with \\[run-python]. | 941 | ;; Fixme: a single process is currently assumed, so that this doc |
| 942 | It will be in a buffer named *Python*. Rename that with | 942 | ;; is misleading. |
| 943 | \\[rename-buffer]. Now start a new process with \\[run-python]. It | 943 | |
| 944 | will be in a new buffer, named *Python*. Switch between the different | 944 | ;; "*The current python process buffer. |
| 945 | process buffers with \\[switch-to-buffer]. | 945 | ;; To run multiple Python processes, start the first with \\[run-python]. |
| 946 | 946 | ;; It will be in a buffer named *Python*. Rename that with | |
| 947 | Commands that send text from source buffers to Python processes have | 947 | ;; \\[rename-buffer]. Now start a new process with \\[run-python]. It |
| 948 | to choose a process to send to. This is determined by global variable | 948 | ;; will be in a new buffer, named *Python*. Switch between the different |
| 949 | `python-buffer'. Suppose you have three inferior Pythons running: | 949 | ;; process buffers with \\[switch-to-buffer]. |
| 950 | Buffer Process | 950 | |
| 951 | foo python | 951 | ;; Commands that send text from source buffers to Python processes have |
| 952 | bar python<2> | 952 | ;; to choose a process to send to. This is determined by global variable |
| 953 | *Python* python<3> | 953 | ;; `python-buffer'. Suppose you have three inferior Pythons running: |
| 954 | If you do a \\[python-send-region-and-go] command on some Python source | 954 | ;; Buffer Process |
| 955 | code, what process does it go to? | 955 | ;; foo python |
| 956 | 956 | ;; bar python<2> | |
| 957 | - In a process buffer (foo, bar, or *Python*), send it to that process. | 957 | ;; *Python* python<3> |
| 958 | - In some other buffer (e.g. a source file), send it to the process | 958 | ;; If you do a \\[python-send-region-and-go] command on some Python source |
| 959 | attached to `python-buffer'. | 959 | ;; code, what process does it go to? |
| 960 | Process selection is done by function `python-proc'. | 960 | |
| 961 | 961 | ;; - In a process buffer (foo, bar, or *Python*), send it to that process. | |
| 962 | Whenever \\[run-python] starts a new process, it resets `python-buffer' | 962 | ;; - In some other buffer (e.g. a source file), send it to the process |
| 963 | to be the new process's buffer. If you only run one process, this will | 963 | ;; attached to `python-buffer'. |
| 964 | do the right thing. If you run multiple processes, you can change | 964 | ;; Process selection is done by function `python-proc'. |
| 965 | `python-buffer' to another process buffer with \\[set-variable].") | 965 | |
| 966 | ;; Whenever \\[run-python] starts a new process, it resets `python-buffer' | ||
| 967 | ;; to be the new process's buffer. If you only run one process, this will | ||
| 968 | ;; do the right thing. If you run multiple processes, you can change | ||
| 969 | ;; `python-buffer' to another process buffer with \\[set-variable]." | ||
| 970 | ) | ||
| 966 | 971 | ||
| 967 | (defconst python-compilation-regexp-alist | 972 | (defconst python-compilation-regexp-alist |
| 968 | `((,(rx (and line-start (1+ (any " \t")) "File \"" | 973 | `((,(rx (and line-start (1+ (any " \t")) "File \"" |
| @@ -971,6 +976,9 @@ do the right thing. If you run multiple processes, you can change | |||
| 971 | 1 python-compilation-line-number)) | 976 | 1 python-compilation-line-number)) |
| 972 | "`compilation-error-regexp-alist' for inferior Python.") | 977 | "`compilation-error-regexp-alist' for inferior Python.") |
| 973 | 978 | ||
| 979 | ;; Fixme: This should inherit some stuff from python-mode, but I'm not | ||
| 980 | ;; sure how much: at least some keybindings, like C-c C-f; syntax?; | ||
| 981 | ;; font-locking, e.g. for triple-quoted strings? | ||
| 974 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" | 982 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" |
| 975 | "Major mode for interacting with an inferior Python process. | 983 | "Major mode for interacting with an inferior Python process. |
| 976 | A Python process can be started with \\[run-python]. | 984 | A Python process can be started with \\[run-python]. |
| @@ -997,7 +1005,8 @@ For running multiple processes in multiple buffers, see `python-buffer'. | |||
| 997 | (add-hook 'comint-input-filter-functions 'python-input-filter nil t) | 1005 | (add-hook 'comint-input-filter-functions 'python-input-filter nil t) |
| 998 | (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter | 1006 | (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter |
| 999 | nil t) | 1007 | nil t) |
| 1000 | ;; Still required by `comint-redirect-send-command', for instance: | 1008 | ;; Still required by `comint-redirect-send-command', for instance |
| 1009 | ;; (and we need to match things like `>>> ... >>> '): | ||
| 1001 | (set (make-local-variable 'comint-prompt-regexp) "^\\([>.]\\{3\\} \\)+") | 1010 | (set (make-local-variable 'comint-prompt-regexp) "^\\([>.]\\{3\\} \\)+") |
| 1002 | (set (make-local-variable 'compilation-error-regexp-alist) | 1011 | (set (make-local-variable 'compilation-error-regexp-alist) |
| 1003 | python-compilation-regexp-alist) | 1012 | python-compilation-regexp-alist) |
| @@ -1037,11 +1046,15 @@ Used as line-number hook function in `python-compilation-regexp-alist'." | |||
| 1037 | (cons (point-marker) | 1046 | (cons (point-marker) |
| 1038 | (if (and (markerp python-orig-start) | 1047 | (if (and (markerp python-orig-start) |
| 1039 | (marker-buffer python-orig-start)) | 1048 | (marker-buffer python-orig-start)) |
| 1040 | (with-current-buffer (marker-buffer python-orig-start) | 1049 | (let ((start python-orig-start)) |
| 1041 | (goto-char python-orig-start) | 1050 | (with-current-buffer (marker-buffer python-orig-start) |
| 1042 | (forward-line (1- line))) | 1051 | (goto-char start) |
| 1043 | (list (if (stringp python-orig-start) python-orig-start file) | 1052 | (forward-line (1- line)) |
| 1044 | line nil))))) | 1053 | (point-marker))) |
| 1054 | (list (if (stringp python-orig-start) | ||
| 1055 | (list python-orig-start default-directory) | ||
| 1056 | file) | ||
| 1057 | line col))))) | ||
| 1045 | 1058 | ||
| 1046 | (defvar python-preoutput-result nil | 1059 | (defvar python-preoutput-result nil |
| 1047 | "Data from output line last `_emacs_out' line seen by the preoutput filter.") | 1060 | "Data from output line last `_emacs_out' line seen by the preoutput filter.") |
| @@ -1234,17 +1247,17 @@ module-qualified names." | |||
| 1234 | ;; (set (make-local-variable 'compilation-old-error-list) nil) | 1247 | ;; (set (make-local-variable 'compilation-old-error-list) nil) |
| 1235 | (let ((comint-input-filter-functions | 1248 | (let ((comint-input-filter-functions |
| 1236 | (delete 'python-input-filter comint-input-filter-functions))) | 1249 | (delete 'python-input-filter comint-input-filter-functions))) |
| 1250 | (set (make-local-variable 'python-orig-start) nil) | ||
| 1251 | ;; Fixme: I'm not convinced by this logic from python-mode.el. | ||
| 1237 | (python-send-string | 1252 | (python-send-string |
| 1238 | (if (string-match "\\.py\\'" file-name) | 1253 | (if (string-match "\\.py\\'" file-name) |
| 1239 | ;; Fixme: make sure the directory is in the path list | 1254 | ;; Fixme: make sure the directory is in the path list |
| 1240 | (let ((module (file-name-sans-extension | 1255 | (let ((module (file-name-sans-extension |
| 1241 | (file-name-nondirectory file-name)))) | 1256 | (file-name-nondirectory file-name)))) |
| 1242 | (set (make-local-variable 'python-orig-start) nil) | ||
| 1243 | (format "\ | 1257 | (format "\ |
| 1244 | if globals().has_key(%S): reload(%s) | 1258 | if globals().has_key(%S): reload(%s) |
| 1245 | else: import %s | 1259 | else: import %s |
| 1246 | " module module module)) | 1260 | " module module module)) |
| 1247 | (set (make-local-variable 'python-orig-start) file-name) | ||
| 1248 | (format "execfile('%s')" file-name)))) | 1261 | (format "execfile('%s')" file-name)))) |
| 1249 | (set-marker compilation-parsing-end end) | 1262 | (set-marker compilation-parsing-end end) |
| 1250 | (setq compilation-last-buffer (current-buffer)))))) | 1263 | (setq compilation-last-buffer (current-buffer)))))) |
| @@ -1329,13 +1342,14 @@ Used with `eval-after-load'." | |||
| 1329 | (string-match "^Python \\([0-9]+\\.[0-9]+\\>\\)" s) | 1342 | (string-match "^Python \\([0-9]+\\.[0-9]+\\>\\)" s) |
| 1330 | (match-string 1 s))) | 1343 | (match-string 1 s))) |
| 1331 | ;; Whether info files have a Python version suffix, e.g. in Debian. | 1344 | ;; Whether info files have a Python version suffix, e.g. in Debian. |
| 1332 | (versioned | 1345 | (versioned |
| 1333 | (with-temp-buffer | 1346 | (with-temp-buffer |
| 1334 | (Info-mode) | 1347 | (with-no-warnings (Info-mode)) |
| 1335 | (condition-case () | 1348 | (condition-case () |
| 1336 | ;; Don't use `info' because it would pop-up a *info* buffer. | 1349 | ;; Don't use `info' because it would pop-up a *info* buffer. |
| 1337 | (Info-goto-node (format "(python%s-lib)Miscellaneous Index" | 1350 | (with-no-warnings |
| 1338 | version)) | 1351 | (Info-goto-node (format "(python%s-lib)Miscellaneous Index" |
| 1352 | version))) | ||
| 1339 | (error nil))))) | 1353 | (error nil))))) |
| 1340 | (info-lookup-maybe-add-help | 1354 | (info-lookup-maybe-add-help |
| 1341 | :mode 'python-mode | 1355 | :mode 'python-mode |