Mercurial > emacs
comparison lisp/progmodes/python.el @ 55300:2db456741f80
(python-compilation-line-number): Remove.
(python-compilation-regexp-alist): Don't use it any more.
(python-orig-start, python-input-filter): Remove.
(inferior-python-mode): Don't set up comint-input-filter-functions.
(python-send-region): Use compilation-fake-loc.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Sat, 01 May 2004 21:16:07 +0000 |
| parents | 780b94f913fe |
| children | a828ab1b3079 |
comparison
equal
deleted
inserted
replaced
| 55299:19ff0d2ea8e8 | 55300:2db456741f80 |
|---|---|
| 968 ;; do the right thing. If you run multiple processes, you can change | 968 ;; do the right thing. If you run multiple processes, you can change |
| 969 ;; `python-buffer' to another process buffer with \\[set-variable]." | 969 ;; `python-buffer' to another process buffer with \\[set-variable]." |
| 970 ) | 970 ) |
| 971 | 971 |
| 972 (defconst python-compilation-regexp-alist | 972 (defconst python-compilation-regexp-alist |
| 973 ;; FIXME: maybe this should be moved to compilation-error-regexp-alist-alist. | |
| 973 `((,(rx (and line-start (1+ (any " \t")) "File \"" | 974 `((,(rx (and line-start (1+ (any " \t")) "File \"" |
| 974 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c | 975 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c |
| 975 "\", line " (group (1+ digit)))) | 976 "\", line " (group (1+ digit)))) |
| 976 1 python-compilation-line-number)) | 977 1 2)) |
| 977 "`compilation-error-regexp-alist' for inferior Python.") | 978 "`compilation-error-regexp-alist' for inferior Python.") |
| 978 | 979 |
| 979 ;; Fixme: This should inherit some stuff from python-mode, but I'm not | 980 ;; 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 ;; sure how much: at least some keybindings, like C-c C-f; syntax?; |
| 981 ;; font-locking, e.g. for triple-quoted strings? | 982 ;; font-locking, e.g. for triple-quoted strings? |
| 1000 (set-syntax-table python-mode-syntax-table) | 1001 (set-syntax-table python-mode-syntax-table) |
| 1001 (setq mode-line-process '(":%s")) | 1002 (setq mode-line-process '(":%s")) |
| 1002 ;; Fixme: Maybe install some python-mode bindings too. | 1003 ;; Fixme: Maybe install some python-mode bindings too. |
| 1003 (define-key inferior-python-mode-map "\C-c\C-l" 'python-load-file) | 1004 (define-key inferior-python-mode-map "\C-c\C-l" 'python-load-file) |
| 1004 (define-key inferior-python-mode-map "\C-c\C-z" 'python-switch-to-python) | 1005 (define-key inferior-python-mode-map "\C-c\C-z" 'python-switch-to-python) |
| 1005 (add-hook 'comint-input-filter-functions 'python-input-filter nil t) | |
| 1006 (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter | 1006 (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter |
| 1007 nil t) | 1007 nil t) |
| 1008 ;; 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 `>>> ... >>> '): | 1009 ;; (and we need to match things like `>>> ... >>> '): |
| 1010 (set (make-local-variable 'comint-prompt-regexp) "^\\([>.]\\{3\\} \\)+") | 1010 (set (make-local-variable 'comint-prompt-regexp) "^\\([>.]\\{3\\} \\)+") |
| 1015 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'" | 1015 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'" |
| 1016 "*Input matching this regexp is not saved on the history list. | 1016 "*Input matching this regexp is not saved on the history list. |
| 1017 Default ignores all inputs of 0, 1, or 2 non-blank characters." | 1017 Default ignores all inputs of 0, 1, or 2 non-blank characters." |
| 1018 :type 'regexp | 1018 :type 'regexp |
| 1019 :group 'python) | 1019 :group 'python) |
| 1020 | |
| 1021 (defvar python-orig-start nil | |
| 1022 "Marker to the start of the region passed to the inferior Python. | |
| 1023 It can also be a filename.") | |
| 1024 | |
| 1025 (defun python-input-filter (str) | |
| 1026 "`comint-input-filter' function for inferior Python. | |
| 1027 Don't save anything for STR matching `inferior-python-filter-regexp'. | |
| 1028 Also resets variables for adjusting error messages." | |
| 1029 (setq python-orig-start nil) | |
| 1030 (not (string-match inferior-python-filter-regexp str))) | |
| 1031 | 1020 |
| 1032 ;; Fixme: Loses with quoted whitespace. | 1021 ;; Fixme: Loses with quoted whitespace. |
| 1033 (defun python-args-to-list (string) | 1022 (defun python-args-to-list (string) |
| 1034 (let ((where (string-match "[ \t]" string))) | 1023 (let ((where (string-match "[ \t]" string))) |
| 1035 (cond ((null where) (list string)) | 1024 (cond ((null where) (list string)) |
| 1036 ((not (= where 0)) | 1025 ((not (= where 0)) |
| 1037 (cons (substring string 0 where) | 1026 (cons (substring string 0 where) |
| 1038 (python-args-to-list (substring string (+ 1 where))))) | 1027 (python-args-to-list (substring string (+ 1 where))))) |
| 1039 (t (let ((pos (string-match "[^ \t]" string))) | 1028 (t (let ((pos (string-match "[^ \t]" string))) |
| 1040 (if pos (python-args-to-list (substring string pos)))))))) | 1029 (if pos (python-args-to-list (substring string pos)))))))) |
| 1041 | |
| 1042 (defun python-compilation-line-number (file col) | |
| 1043 "Return error descriptor of error found for FILE, column COL. | |
| 1044 Used as line-number hook function in `python-compilation-regexp-alist'." | |
| 1045 (let ((line (string-to-number (match-string 2)))) | |
| 1046 (cons (point-marker) | |
| 1047 (if (and (markerp python-orig-start) | |
| 1048 (marker-buffer python-orig-start)) | |
| 1049 (let ((start python-orig-start)) | |
| 1050 (with-current-buffer (marker-buffer python-orig-start) | |
| 1051 (goto-char start) | |
| 1052 (forward-line (1- line)) | |
| 1053 (point-marker))) | |
| 1054 (list (if (stringp python-orig-start) | |
| 1055 (list python-orig-start default-directory) | |
| 1056 file) | |
| 1057 line col))))) | |
| 1058 | 1030 |
| 1059 (defvar python-preoutput-result nil | 1031 (defvar python-preoutput-result nil |
| 1060 "Data from output line last `_emacs_out' line seen by the preoutput filter.") | 1032 "Data from output line last `_emacs_out' line seen by the preoutput filter.") |
| 1061 | 1033 |
| 1062 (defvar python-preoutput-continuation nil | 1034 (defvar python-preoutput-continuation nil |
| 1176 (/= 0 (current-indentation))) ; need dummy block | 1148 (/= 0 (current-indentation))) ; need dummy block |
| 1177 (write-region "if True:\n" nil f nil 'nomsg)) | 1149 (write-region "if True:\n" nil f nil 'nomsg)) |
| 1178 (write-region start end f t 'nomsg) | 1150 (write-region start end f t 'nomsg) |
| 1179 (when python-buffer | 1151 (when python-buffer |
| 1180 (with-current-buffer python-buffer | 1152 (with-current-buffer python-buffer |
| 1181 (set (make-local-variable 'python-orig-start) orig-start) | 1153 (python-send-command command) |
| 1182 (let ((comint-input-filter-functions | 1154 ;; Tell compile.el to redirect error locations in file `f' to |
| 1183 ;; Don't reset python-orig-start. | 1155 ;; positions past marker `orig-start'. It has to be done *after* |
| 1184 (remq 'python-input-filter comint-input-filter-functions))) | 1156 ;; python-send-command's call to compilation-forget-errors. |
| 1185 (python-send-command command)))))) | 1157 (compilation-fake-loc orig-start f))))) |
| 1186 | 1158 |
| 1187 (defun python-send-string (string) | 1159 (defun python-send-string (string) |
| 1188 "Evaluate STRING in inferior Python process." | 1160 "Evaluate STRING in inferior Python process." |
| 1189 (interactive "sPython command: ") | 1161 (interactive "sPython command: ") |
| 1190 (comint-send-string (python-proc) string) | 1162 (comint-send-string (python-proc) string) |
