diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index a243f6cbe25..317ef2e1282 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -956,10 +956,6 @@ OUTPUT is a string with the contents of the buffer." | |||
| 956 | "Current file from which a region was sent.") | 956 | "Current file from which a region was sent.") |
| 957 | (make-variable-buffer-local 'inferior-python-mode-current-file) | 957 | (make-variable-buffer-local 'inferior-python-mode-current-file) |
| 958 | 958 | ||
| 959 | (defvar inferior-python-mode-current-temp-file nil | ||
| 960 | "Current temp file sent to process.") | ||
| 961 | (make-variable-buffer-local 'inferior-python-mode-current-file) | ||
| 962 | |||
| 963 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" | 959 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" |
| 964 | "Major mode for Python inferior process." | 960 | "Major mode for Python inferior process." |
| 965 | (set-syntax-table python-mode-syntax-table) | 961 | (set-syntax-table python-mode-syntax-table) |
| @@ -1077,10 +1073,7 @@ commands.)" | |||
| 1077 | (message (format "Sent: %s..." | 1073 | (message (format "Sent: %s..." |
| 1078 | (buffer-substring (point-min) | 1074 | (buffer-substring (point-min) |
| 1079 | (line-end-position))))) | 1075 | (line-end-position))))) |
| 1080 | (with-current-buffer (process-buffer process) | 1076 | (python-shell-send-file current-file process temp-file))) |
| 1081 | (setq inferior-python-mode-current-file current-file) | ||
| 1082 | (setq inferior-python-mode-current-temp-file temp-file)) | ||
| 1083 | (python-shell-send-file temp-file process))) | ||
| 1084 | 1077 | ||
| 1085 | (defun python-shell-send-buffer () | 1078 | (defun python-shell-send-buffer () |
| 1086 | "Send the entire buffer to inferior Python process." | 1079 | "Send the entire buffer to inferior Python process." |
| @@ -1103,15 +1096,26 @@ When argument ARG is non-nil sends the innermost defun." | |||
| 1103 | (or (python-end-of-defun-function) | 1096 | (or (python-end-of-defun-function) |
| 1104 | (progn (end-of-line) (point-marker))))))) | 1097 | (progn (end-of-line) (point-marker))))))) |
| 1105 | 1098 | ||
| 1106 | (defun python-shell-send-file (file-name &optional process) | 1099 | (defun python-shell-send-file (file-name &optional process temp-file-name) |
| 1107 | "Send FILE-NAME to inferior Python PROCESS." | 1100 | "Send FILE-NAME to inferior Python PROCESS. |
| 1101 | If TEMP-FILE-NAME is passed then that file is used for processing | ||
| 1102 | instead, while internally the shell will continue to use | ||
| 1103 | FILE-NAME." | ||
| 1108 | (interactive "fFile to send: ") | 1104 | (interactive "fFile to send: ") |
| 1109 | (let ((process (or process (python-shell-get-or-create-process))) | 1105 | (let ((process (or process (python-shell-get-or-create-process))) |
| 1110 | (full-file-name (expand-file-name file-name))) | 1106 | (file-name (convert-standard-filename (expand-file-name file-name))) |
| 1107 | (temp-file-name (when temp-file-name | ||
| 1108 | (convert-standard-filename | ||
| 1109 | (expand-file-name temp-file-name))))) | ||
| 1110 | (find-file-noselect file-name) | ||
| 1111 | (with-current-buffer (process-buffer process) | ||
| 1112 | (setq inferior-python-mode-current-file file-name)) | ||
| 1111 | (python-shell-send-string | 1113 | (python-shell-send-string |
| 1112 | (format | 1114 | (format |
| 1113 | "__pyfile = open('%s'); exec(compile(__pyfile.read(), '%s', 'exec')); __pyfile.close()" | 1115 | (concat "__pyfile = open('''%s''');" |
| 1114 | full-file-name full-file-name) | 1116 | "exec(compile(__pyfile.read(), '''%s''', 'exec'));" |
| 1117 | "__pyfile.close()") | ||
| 1118 | (or temp-file-name file-name) file-name) | ||
| 1115 | process))) | 1119 | process))) |
| 1116 | 1120 | ||
| 1117 | (defun python-shell-clear-latest-output () | 1121 | (defun python-shell-clear-latest-output () |
| @@ -1289,8 +1293,7 @@ Returns a cons with the form: | |||
| 1289 | (or | 1293 | (or |
| 1290 | (assq (current-buffer) python-pdbtrack-tracking-buffers) | 1294 | (assq (current-buffer) python-pdbtrack-tracking-buffers) |
| 1291 | (let* ((file (with-current-buffer (current-buffer) | 1295 | (let* ((file (with-current-buffer (current-buffer) |
| 1292 | (or inferior-python-mode-current-file | 1296 | inferior-python-mode-current-file)) |
| 1293 | inferior-python-mode-current-temp-file))) | ||
| 1294 | (tracking-buffers | 1297 | (tracking-buffers |
| 1295 | `(,(current-buffer) . | 1298 | `(,(current-buffer) . |
| 1296 | ,(or (get-file-buffer file) | 1299 | ,(or (get-file-buffer file) |
| @@ -1316,7 +1319,7 @@ Argument OUTPUT is a string with the output from the comint process." | |||
| 1316 | (string-match | 1319 | (string-match |
| 1317 | (format python-pdbtrack-stacktrace-info-regexp | 1320 | (format python-pdbtrack-stacktrace-info-regexp |
| 1318 | (regexp-quote | 1321 | (regexp-quote |
| 1319 | inferior-python-mode-current-temp-file)) | 1322 | inferior-python-mode-current-file)) |
| 1320 | full-output) | 1323 | full-output) |
| 1321 | (string-to-number (or (match-string-no-properties 1 full-output) "")))) | 1324 | (string-to-number (or (match-string-no-properties 1 full-output) "")))) |
| 1322 | (tracked-buffer-window (get-buffer-window (cdr tracking-buffers))) | 1325 | (tracked-buffer-window (get-buffer-window (cdr tracking-buffers))) |
| @@ -1577,6 +1580,10 @@ It is specially designed to be added to the | |||
| 1577 | (message (format "Eldoc setup code sent."))))) | 1580 | (message (format "Eldoc setup code sent."))))) |
| 1578 | 1581 | ||
| 1579 | (defun python-eldoc--get-doc-at-point (&optional force-input force-process) | 1582 | (defun python-eldoc--get-doc-at-point (&optional force-input force-process) |
| 1583 | "Internal implementation to get documentation at point. | ||
| 1584 | If not FORCE-INPUT is passed then what `current-word' returns | ||
| 1585 | will be used. If not FORCE-PROCESS is passed what | ||
| 1586 | `python-shell-get-process' returns is used." | ||
| 1580 | (let ((process (or force-process (python-shell-get-process)))) | 1587 | (let ((process (or force-process (python-shell-get-process)))) |
| 1581 | (if (not process) | 1588 | (if (not process) |
| 1582 | "Eldoc needs an inferior Python process running." | 1589 | "Eldoc needs an inferior Python process running." |