Mercurial > emacs
comparison lisp/progmodes/python.el @ 90133:4da4a09e8b1b
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-31
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 206-222)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 45-52)
- Update from CVS
- Update from CVS: texi Makefile.in CVS keyw cruft
- Update from CVS: ChangeLog tweaks
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 31 Mar 2005 09:58:14 +0000 |
parents | 3ebd9bdb4fe5 bf4917ef8f38 |
children | 08185296b491 |
comparison
equal
deleted
inserted
replaced
90132:4080fe8b4f0f | 90133:4da4a09e8b1b |
---|---|
1 ;;; python.el --- silly walks for Python | 1 ;;; python.el --- silly walks for Python |
2 | 2 |
3 ;; Copyright (C) 2003, 2004 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2003, 2004, 2005 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 |
7 ;; Created: Nov 2003 | 7 ;; Created: Nov 2003 |
8 ;; Keywords: languages | 8 ;; Keywords: languages |
334 keyword `raise', `break', `continue' or `pass'." | 334 keyword `raise', `break', `continue' or `pass'." |
335 (save-excursion | 335 (save-excursion |
336 (unless bos (python-beginning-of-statement)) | 336 (unless bos (python-beginning-of-statement)) |
337 (back-to-indentation) | 337 (back-to-indentation) |
338 (looking-at (rx (and (or "return" "raise" "break" "continue" "pass") | 338 (looking-at (rx (and (or "return" "raise" "break" "continue" "pass") |
339 word-end))))) | 339 symbol-end))))) |
340 | 340 |
341 (defun python-outdent-p () | 341 (defun python-outdent-p () |
342 "Return non-nil if current line should outdent a level." | 342 "Return non-nil if current line should outdent a level." |
343 (save-excursion | 343 (save-excursion |
344 (back-to-indentation) | 344 (back-to-indentation) |
345 (and (looking-at (rx (and (or (and (or "else" "finally") word-end) | 345 (and (looking-at (rx (and (or (and (or "else" "finally") symbol-end) |
346 (and (or "except" "elif") word-end | 346 (and (or "except" "elif") symbol-end |
347 (1+ (not (any ?:))))) | 347 (1+ (not (any ?:))))) |
348 (optional space) ":" (optional space) | 348 (optional space) ":" (optional space) |
349 (or (syntax comment-start) line-end)))) | 349 (or (syntax comment-start) line-end)))) |
350 (progn (end-of-line) | 350 (progn (end-of-line) |
351 (not (python-in-string/comment))) | 351 (not (python-in-string/comment))) |
353 (zerop (python-previous-statement)) | 353 (zerop (python-previous-statement)) |
354 (not (python-close-block-statement-p t)) | 354 (not (python-close-block-statement-p t)) |
355 ;; Fixme: check this | 355 ;; Fixme: check this |
356 (not (looking-at (rx (and (or (and (or "if" "elif" "except" | 356 (not (looking-at (rx (and (or (and (or "if" "elif" "except" |
357 "for" "while") | 357 "for" "while") |
358 word-end (1+ (not (any ?:)))) | 358 symbol-end (1+ (not (any ?:)))) |
359 (and "try" word-end)) | 359 (and "try" symbol-end)) |
360 (optional space) ":" (optional space) | 360 (optional space) ":" (optional space) |
361 (or (syntax comment-start) line-end))))) | 361 (or (syntax comment-start) line-end))))) |
362 (progn (end-of-line) | 362 (progn (end-of-line) |
363 (not (python-in-string/comment)))))) | 363 (not (python-in-string/comment)))))) |
364 | 364 |
1096 "Data from last `_emacs_out' line seen by the preoutput filter.") | 1096 "Data from last `_emacs_out' line seen by the preoutput filter.") |
1097 | 1097 |
1098 (defvar python-preoutput-continuation nil | 1098 (defvar python-preoutput-continuation nil |
1099 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") | 1099 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") |
1100 | 1100 |
1101 (defvar python-preoutput-leftover nil) | |
1102 | |
1101 ;; Using this stops us getting lines in the buffer like | 1103 ;; Using this stops us getting lines in the buffer like |
1102 ;; >>> ... ... >>> | 1104 ;; >>> ... ... >>> |
1103 ;; Also look for (and delete) an `_emacs_ok' string and call | 1105 ;; Also look for (and delete) an `_emacs_ok' string and call |
1104 ;; `python-preoutput-continuation' if we get it. | 1106 ;; `python-preoutput-continuation' if we get it. |
1105 (defun python-preoutput-filter (s) | 1107 (defun python-preoutput-filter (s) |
1106 "`comint-preoutput-filter-functions' function: ignore prompts not at bol." | 1108 "`comint-preoutput-filter-functions' function: ignore prompts not at bol." |
1109 (when python-preoutput-leftover | |
1110 (setq s (concat python-preoutput-leftover s)) | |
1111 (setq python-preoutput-leftover nil)) | |
1107 (cond ((and (string-match (rx (and string-start (repeat 3 (any ".>")) | 1112 (cond ((and (string-match (rx (and string-start (repeat 3 (any ".>")) |
1108 " " string-end)) | 1113 " " string-end)) |
1109 s) | 1114 s) |
1110 (/= (let ((inhibit-field-text-motion t)) | 1115 (/= (let ((inhibit-field-text-motion t)) |
1111 (line-beginning-position)) | 1116 (line-beginning-position)) |
1112 (point))) | 1117 (point))) |
1118 "") | |
1119 ((string= s "_emacs_ok\n") | |
1120 (when python-preoutput-continuation | |
1121 (funcall python-preoutput-continuation) | |
1122 (setq python-preoutput-continuation nil)) | |
1123 "") | |
1124 ((string-match "_emacs_out \\(.*\\)\n" s) | |
1125 (setq python-preoutput-result (match-string 1 s)) | |
1126 "") | |
1127 ((string-match ".*\n" s) | |
1128 s) | |
1129 ((or (eq t (compare-strings s nil nil "_emacs_ok\n" nil (length s))) | |
1130 (let ((end (min (length "_emacs_out ") (length s)))) | |
1131 (eq t (compare-strings s nil end "_emacs_out " nil end)))) | |
1132 (setq python-preoutput-leftover s) | |
1113 "") | 1133 "") |
1114 ((string= s "_emacs_ok\n") | 1134 (t s))) |
1115 (when python-preoutput-continuation | |
1116 (funcall python-preoutput-continuation) | |
1117 (setq python-preoutput-continuation nil)) | |
1118 "") | |
1119 ((string-match "_emacs_out \\(.*\\)\n" s) | |
1120 (setq python-preoutput-result (match-string 1 s)) | |
1121 "") | |
1122 (t s))) | |
1123 | 1135 |
1124 ;;;###autoload | 1136 ;;;###autoload |
1125 (defun run-python (&optional cmd noshow) | 1137 (defun run-python (&optional cmd noshow) |
1126 "Run an inferior Python process, input and output via buffer *Python*. | 1138 "Run an inferior Python process, input and output via buffer *Python*. |
1127 CMD is the Python command to run. NOSHOW non-nil means don't show the | 1139 CMD is the Python command to run. NOSHOW non-nil means don't show the |
1357 "Send STRING to inferior Python (if any) and return result. | 1369 "Send STRING to inferior Python (if any) and return result. |
1358 The result is what follows `_emacs_out' in the output (or nil)." | 1370 The result is what follows `_emacs_out' in the output (or nil)." |
1359 (let ((proc (python-proc))) | 1371 (let ((proc (python-proc))) |
1360 (python-send-string string) | 1372 (python-send-string string) |
1361 (setq python-preoutput-result nil) | 1373 (setq python-preoutput-result nil) |
1362 (accept-process-output proc 5) | 1374 (while (progn |
1375 (accept-process-output proc 5) | |
1376 python-preoutput-leftover)) | |
1363 python-preoutput-result)) | 1377 python-preoutput-result)) |
1364 | 1378 |
1365 ;; Fixme: try to make it work with point in the arglist. Also, is | 1379 ;; Fixme: try to make it work with point in the arglist. Also, is |
1366 ;; there anything reasonable we can do with random methods? | 1380 ;; there anything reasonable we can do with random methods? |
1367 ;; (Currently only works with functions.) | 1381 ;; (Currently only works with functions.) |
1560 (python-beginning-of-block) | 1574 (python-beginning-of-block) |
1561 (end-of-line) | 1575 (end-of-line) |
1562 (beginning-of-defun) | 1576 (beginning-of-defun) |
1563 (if (looking-at (rx (and (0+ space) (or "def" "class") (1+ space) | 1577 (if (looking-at (rx (and (0+ space) (or "def" "class") (1+ space) |
1564 (group (1+ (or word (syntax symbol)))) | 1578 (group (1+ (or word (syntax symbol)))) |
1565 word-end))) | 1579 ;; Greediness makes this unnecessary? --Stef |
1580 symbol-end))) | |
1566 (push (match-string 1) accum))) | 1581 (push (match-string 1) accum))) |
1567 (if accum (mapconcat 'identity accum "."))))) | 1582 (if accum (mapconcat 'identity accum "."))))) |
1568 | 1583 |
1569 (defun python-mark-block () | 1584 (defun python-mark-block () |
1570 "Mark the block around point. | 1585 "Mark the block around point. |
1700 :group 'python | 1715 :group 'python |
1701 (set (make-local-variable 'font-lock-defaults) | 1716 (set (make-local-variable 'font-lock-defaults) |
1702 '(python-font-lock-keywords nil nil ((?_ . "w")) nil | 1717 '(python-font-lock-keywords nil nil ((?_ . "w")) nil |
1703 (font-lock-syntactic-keywords | 1718 (font-lock-syntactic-keywords |
1704 . python-font-lock-syntactic-keywords) | 1719 . python-font-lock-syntactic-keywords) |
1705 ;;; This probably isn't worth it. | 1720 ;; This probably isn't worth it. |
1706 ;;; (font-lock-syntactic-face-function | 1721 ;; (font-lock-syntactic-face-function |
1707 ;;; . python-font-lock-syntactic-face-function) | 1722 ;; . python-font-lock-syntactic-face-function) |
1708 )) | 1723 )) |
1709 (set (make-local-variable 'parse-sexp-lookup-properties) t) | 1724 (set (make-local-variable 'parse-sexp-lookup-properties) t) |
1710 (set (make-local-variable 'comment-start) "# ") | 1725 (set (make-local-variable 'comment-start) "# ") |
1711 (set (make-local-variable 'comment-indent-function) #'python-comment-indent) | 1726 (set (make-local-variable 'comment-indent-function) #'python-comment-indent) |
1712 (set (make-local-variable 'indent-line-function) #'python-indent-line) | 1727 (set (make-local-variable 'indent-line-function) #'python-indent-line) |