• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/progmodes/

Lines Matching defs:python

0 ;;; python.el --- silly walks for Python
31 ;; There is another Python mode, python-mode.el, used by XEmacs and
39 ;; This doesn't implement all the facilities of python-mode.el. Some
54 ;; `python-send-region' & al via `compilation-shell-minor-mode'.)
60 ;; with python-mode.el in some respects. For instance, various key
75 (defgroup python nil
79 :link '(emacs-commentary-link "python"))
85 (add-to-list 'interpreter-mode-alist '("python" . python-mode))
87 (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
92 (defvar python-font-lock-keywords
116 (defconst python-font-lock-syntactic-keywords
126 (1 (python-quote-syntax 1))
127 (2 (python-quote-syntax 2))
128 (3 (python-quote-syntax 3)))
133 (defun python-quote-syntax (n)
177 ;; (defun python-font-lock-syntactic-face-function (state)
198 (defvar python-mode-map
200 ;; Mostly taken from python-mode.el.
201 (define-key map ":" 'python-electric-colon)
202 (define-key map "\177" 'python-backspace)
203 (define-key map "\C-c<" 'python-shift-left)
204 (define-key map "\C-c>" 'python-shift-right)
205 (define-key map "\C-c\C-k" 'python-mark-block)
206 (define-key map "\C-c\C-n" 'python-next-statement)
207 (define-key map "\C-c\C-p" 'python-previous-statement)
208 (define-key map "\C-c\C-u" 'python-beginning-of-block)
209 (define-key map "\C-c\C-f" 'python-describe-symbol)
210 (define-key map "\C-c\C-w" 'python-check)
211 (define-key map "\C-c\C-v" 'python-check) ; a la sgml-mode
212 (define-key map "\C-c\C-s" 'python-send-string)
213 (define-key map [?\C-\M-x] 'python-send-defun)
214 (define-key map "\C-c\C-r" 'python-send-region)
215 (define-key map "\C-c\M-r" 'python-send-region-and-go)
216 (define-key map "\C-c\C-c" 'python-send-buffer)
217 (define-key map "\C-c\C-z" 'python-switch-to-python)
218 (define-key map "\C-c\C-m" 'python-load-file)
219 (define-key map "\C-c\C-l" 'python-load-file) ; a la cmuscheme
220 (substitute-key-definition 'complete-symbol 'python-complete-symbol
222 (define-key map "\C-c\C-i" 'python-find-imports)
223 (define-key map "\C-c\C-t" 'python-expand-template)
224 (easy-menu-define python-menu map "Python Mode menu"
227 ["Shift region left" python-shift-left :active mark-active
229 ["Shift region right" python-shift-right :active mark-active
232 ["Mark block" python-mark-block
237 ["Start of block" python-beginning-of-block
239 ["End of block" python-end-of-block
251 python-skeletons))) ; defined later
253 ["Start interpreter" run-python
255 ["Import/reload file" python-load-file
257 ["Eval buffer" python-send-buffer
259 ["Eval region" python-send-region :active mark-active
261 ["Eval def/class" python-send-defun
263 ["Switch to interpreter" python-switch-to-python
265 ["Set default process" python-set-proc
267 :active (buffer-live-p python-buffer)]
268 ["Check file" python-check :help "Run pychecker"]
271 ["Help on symbol" python-describe-symbol
273 ["Complete symbol" python-complete-symbol
275 ["Update imports" python-find-imports
283 (defvar python-mode-syntax-table
305 (defsubst python-in-string/comment ()
310 (defconst python-space-backslash-table
311 (let ((table (copy-syntax-table python-mode-syntax-table)))
314 "`python-mode-syntax-table' with backslash given whitespace syntax.")
316 (defun python-skip-comments/blanks (&optional backward)
331 (with-syntax-table python-space-backslash-table
334 (defun python-backslash-continuation-line-p ()
339 (defun python-continuation-line-p ()
343 (or (python-backslash-continuation-line-p)
354 (defun python-comment-line-p ()
362 (defun python-blank-line-p ()
368 (defun python-beginning-of-string ()
375 (defun python-open-block-statement-p (&optional bos)
379 (unless bos (python-beginning-of-statement))
384 (defun python-close-block-statement-p (&optional bos)
390 (unless bos (python-beginning-of-statement))
395 (defun python-outdent-p ()
401 (not (python-in-string/comment))
403 (zerop (python-previous-statement))
404 (not (python-close-block-statement-p t))
406 (not (python-open-block-statement-p)))))
411 (defcustom python-indent 4
413 See also `\\[python-guess-indent]'"
414 :group 'python
416 (put 'python-indent 'safe-local-variable 'integerp)
418 (defcustom python-guess-indent t
419 "Non-nil means Python mode guesses `python-indent' for the buffer."
421 :group 'python)
423 (defcustom python-indent-string-contents t
432 :group 'python)
434 (defcustom python-honour-comment-indentation nil
440 :group 'python)
442 (defcustom python-continuation-offset 4
446 :group 'python
449 (defun python-guess-indent ()
451 Set `python-indent' locally to the value guessed."
463 (python-open-block-statement-p))
465 (python-beginning-of-statement)
467 (if (zerop (python-next-statement))
472 (when (/= indent (default-value 'python-indent))
473 (set (make-local-variable 'python-indent) indent)
474 (unless (= tab-width python-indent)
480 (defvar python-indent-list nil
483 (defvar python-indent-list-length nil
486 (defvar python-indent-index nil
489 (defun python-calculate-indentation ()
491 (setq python-indent-list nil
492 python-indent-list-length 1)
499 (if (not python-indent-string-contents)
501 ;; Only respect `python-indent-string-contents' in doc
504 (python-beginning-of-statement)
514 ((python-continuation-line-p) ; after backslash, or bracketed
517 (backslash (python-backslash-continuation-line-p))
525 (if (with-syntax-table python-space-backslash-table
535 (+ python-indent (current-column))
540 (python-beginning-of-statement)
541 (+ (current-indentation) (* (car syntax) python-indent))))
544 (if (python-continuation-line-p)
550 (python-beginning-of-statement)
551 (+ (current-indentation) python-continuation-offset
552 (if (python-open-block-statement-p t)
553 python-indent
556 ;; Fixme: Like python-mode.el; not convinced by this.
560 (t (if python-honour-comment-indentation
567 (python-beginning-of-statement)
571 (python-beginning-of-statement)
573 ;; indentable comment like python-mode.el
578 (python-indentation-levels)
584 (when (and (> python-indent-list-length 1)
585 (python-comment-line-p))
587 (unless (python-comment-line-p)
588 (let ((elt (assq (current-indentation) python-indent-list)))
589 (setq python-indent-list
590 (nconc (delete elt python-indent-list)
592 (caar (last python-indent-list)))))))
599 (defun python-initial-text ()
610 (defconst python-block-pairs
619 (defun python-first-word ()
625 (defun python-indentation-levels ()
638 ((save-excursion (and (python-previous-statement)
639 (python-open-block-statement-p t)
643 (if (progn (python-end-of-statement)
644 (python-skip-comments/blanks t)
646 (setq indent (+ python-indent indent)))))
651 (when (python-comment-line-p)
653 (if (python-comment-line-p)
658 (let ((start (car (assoc (python-first-word) python-block-pairs))))
659 (python-previous-statement)
666 (not (member (python-first-word)
668 python-block-pairs)))))
671 (python-close-block-statement-p))
672 (push (cons (current-indentation) (python-initial-text))
674 (while (python-beginning-of-block)
676 (member (python-first-word)
677 (cdr (assoc start python-block-pairs))))
678 (push (cons (current-indentation) (python-initial-text))
681 (setq python-indent-list levels
682 python-indent-list-length (length python-indent-list))))))
684 ;; This is basically what `python-indent-line' would be if we didn't
686 (defun python-indent-line-1 (&optional leave)
687 "Subroutine of `python-indent-line'.
690 `python-calculate-indentation'."
691 (let ((target (python-calculate-indentation))
695 (and leave python-indent-list
696 (assq (current-indentation) python-indent-list)))
705 (defun python-indent-line ()
714 (if (= 1 python-indent-list-length)
716 (progn (setq python-indent-index
717 (% (1+ python-indent-index) python-indent-list-length))
720 (indent-to (car (nth python-indent-index python-indent-list)))
721 (if (python-block-end-p)
722 (let ((text (cdr (nth python-indent-index
723 python-indent-list))))
726 (python-indent-line-1)
727 (setq python-indent-index (1- python-indent-list-length))))
729 (defun python-indent-region (start end)
740 (python-indent-line-1 t))
744 (defun python-block-end-p ()
747 (and (not (python-comment-line-p))
748 (or (python-close-block-statement-p t)
751 (python-previous-statement)
760 (defun python-beginning-of-defun ()
769 (if (python-comment-line-p)
789 (not (python-in-string/comment)))
792 (defun python-end-of-defun ()
800 (when (python-comment-line-p)
803 (if (not (python-open-block-statement-p))
804 (python-beginning-of-block))
806 (unless (python-open-block-statement-p)
808 (python-in-string/comment))) ; just loop
813 (python-beginning-of-defun))
819 (python-in-string/comment)))) ; just loop
822 (python-end-of-block)
838 (defun python-beginning-of-statement ()
843 (python-beginning-of-string)
844 (while (python-continuation-line-p)
846 (if (python-backslash-continuation-line-p)
849 (while (python-backslash-continuation-line-p)
851 (python-beginning-of-string)
852 (python-skip-out)))
855 (defun python-skip-out (&optional forward syntax)
877 (defun python-end-of-statement ()
896 ((python-skip-out t s))))
903 (defun python-previous-statement (&optional count)
910 (python-next-statement (- count))
911 (python-beginning-of-statement)
913 (python-skip-comments/blanks t)
914 (python-beginning-of-statement)
918 (defun python-next-statement (&optional count)
925 (python-previous-statement (- count))
928 (python-end-of-statement)
929 (python-skip-comments/blanks)
934 (defun python-beginning-of-block (&optional arg)
937 `python-end-of-block' instead.
945 ((< arg 0) (python-end-of-block (- arg)))
948 (if (or (python-comment-line-p)
949 (python-blank-line-p))
950 (python-skip-comments/blanks t))
951 (python-beginning-of-statement)
958 ;;; (while (zerop (python-previous-statement))
960 ;;; (python-open-block-statement-p t))
965 (not (python-comment-line-p))
968 (progn (python-beginning-of-statement) t)
969 (python-open-block-statement-p t))
973 (python-beginning-of-block (1- arg)))))))))
975 (defun python-end-of-block (&optional arg)
978 call `python-beginning-of-block' instead.
984 (python-beginning-of-block (- arg))
987 (_ (if (python-comment-line-p)
988 (python-skip-comments/blanks t)))
990 (open (python-open-block-statement-p))
996 (while (and (zerop (python-next-statement))
1001 (python-skip-comments/blanks t)
1010 (defvar python-recursing)
1011 (defun python-imenu-create-index ()
1019 (unless (boundp 'python-recursing) ; dynamically bound below
1037 (unless (python-in-string/comment)
1044 (let* ((python-recursing t)
1045 (sublist (python-imenu-create-index)))
1050 (unless (boundp 'python-recursing)
1057 (unless (python-in-string/comment)
1070 (defun python-electric-colon (arg)
1078 (python-outdent-p)
1079 (not (python-in-string/comment))
1080 (> (current-indentation) (python-calculate-indentation))
1081 (python-indent-line))) ; OK, do it
1082 (put 'python-electric-colon 'delete-selection t)
1084 (defun python-backspace (arg)
1092 (python-continuation-line-p))
1098 (indents (python-indentation-levels))
1108 (put 'python-backspace 'delete-selection 'supersede)
1113 (defcustom python-check-command "pychecker --stdlib"
1116 :group 'python)
1118 (defvar python-saved-check-command nil
1122 (defun python-check (command)
1125 See `python-check-command' for the default."
1128 (or python-saved-check-command
1129 (concat python-check-command " "
1133 (setq python-saved-check-command command)
1146 (defcustom python-python-command "python"
1151 :group 'python
1154 (defcustom python-jython-command "jython"
1157 :group 'python
1160 (defvar python-command python-python-command
1162 May be `python-python-command' or `python-jython-command', possibly
1164 is used by `run-python' et al.")
1166 (defvar python-buffer nil
1171 value of `python-buffer'. If its value in the current buffer,
1172 i.e. both any local value and the default one, is nil, `run-python'
1175 Whenever \\[run-python] starts a new process, it resets the default
1176 value of `python-buffer' to be the new process's buffer and sets the
1181 Use \\[python-set-proc] to set the default value from a buffer with a
1183 (make-variable-buffer-local 'python-buffer)
1185 (defconst python-compilation-regexp-alist
1198 (defvar inferior-python-mode-map
1201 (define-key map "\C-c\C-l" 'python-load-file)
1202 (define-key map "\C-c\C-v" 'python-check)
1206 ;; python-send-region. Fixme: uncomment these if we address that.
1208 ;; (define-key map [(meta ?\t)] 'python-complete-symbol)
1209 ;; (define-key map "\C-c\C-f" 'python-describe-symbol)
1212 (defvar inferior-python-mode-syntax-table
1213 (let ((st (make-syntax-table python-mode-syntax-table)))
1221 ;; Fixme: This should inherit some stuff from `python-mode', but I'm
1224 (define-derived-mode inferior-python-mode comint-mode "Inferior Python"
1226 A Python process can be started with \\[run-python].
1228 Hooks `comint-mode-hook' and `inferior-python-mode-hook' are run in
1233 * \\[python-switch-to-python] switches the current buffer to the Python
1235 * \\[python-send-region] sends the current region to the Python process.
1236 * \\[python-send-region-and-go] switches to the Python process buffer
1238 For running multiple processes in multiple buffers, see `run-python' and
1239 `python-buffer'.
1241 \\{inferior-python-mode-map}"
1242 :group 'python
1244 (set (make-local-variable 'comint-input-filter) 'python-input-filter)
1245 (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter
1252 python-compilation-regexp-alist)
1255 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'"
1259 :group 'python)
1261 (defun python-input-filter (str)
1263 Don't save anything for STR matching `inferior-python-filter-regexp'."
1264 (not (string-match inferior-python-filter-regexp str)))
1267 (defun python-args-to-list (string)
1272 (python-args-to-list (substring string (+ 1 where)))))
1274 (if pos (python-args-to-list (substring string pos))))))))
1276 (defvar python-preoutput-result nil
1279 (defvar python-preoutput-leftover nil)
1280 (defvar python-preoutput-skip-next-prompt nil)
1284 (defun python-preoutput-filter (s)
1286 (when python-preoutput-leftover
1287 (setq s (concat python-preoutput-leftover s))
1288 (setq python-preoutput-leftover nil))
1295 (when (and python-preoutput-skip-next-prompt
1297 (setq python-preoutput-skip-next-prompt nil)
1301 (local-variable-p 'python-preoutput-result))
1303 (setq python-preoutput-result (match-string 1 line))
1304 (set (make-local-variable 'python-preoutput-skip-next-prompt) t))
1310 (or python-preoutput-skip-next-prompt
1320 (setq python-preoutput-skip-next-prompt nil)
1327 (set (make-local-variable 'python-preoutput-leftover) s)
1334 (defun run-python (&optional cmd noshow new)
1339 Normally, if there is a process already running in `python-buffer',
1341 the initial command line (default is `python-command'); `-i' etc. args
1343 one isn't running attached to `python-buffer', or interactively the
1344 default `python-command', or argument NEW is non-nil. See also the
1345 documentation for `python-buffer'.
1347 Runs the hook `inferior-python-mode-hook' \(after the
1351 (list (read-string "Run Python: " python-command) nil t)
1352 (list python-command)))
1353 (unless cmd (setq cmd python-python-command))
1354 (setq python-command cmd)
1355 ;; Fixme: Consider making `python-buffer' buffer-local as a buffer
1356 ;; (not a name) in Python buffers from which `run-python' &c is
1358 (when (or new (not (comint-check-proc python-buffer)))
1361 (append (python-args-to-list cmd)
1371 (setq-default python-buffer (current-buffer))
1372 (setq python-buffer (current-buffer))
1373 (accept-process-output (get-buffer-process python-buffer) 5)
1374 (inferior-python-mode)
1382 (python-send-receive "import emacs; print '_emacs_out ()'")))
1383 (if (derived-mode-p 'python-mode)
1384 (setq python-buffer (default-value 'python-buffer))) ; buffer-local
1385 ;; Without this, help output goes into the inferior python buffer if
1388 (unless noshow (pop-to-buffer python-buffer t)))
1397 (defun python-send-command (command)
1398 "Like `python-send-string' but resets `compilation-shell-minor-mode'.
1401 ;; (let ((end (marker-position (process-mark (python-proc)))))
1402 (with-current-buffer (process-buffer (python-proc))
1405 (python-send-string command)
1408 ;; compilation-fake-loc in python-send-region. -- Stef
1410 ;; (python-send-receive "print '_emacs_out ()'")
1411 ;; (with-current-buffer python-buffer
1415 (defun python-send-region (start end)
1444 (python-send-command command)
1445 (with-current-buffer (process-buffer (python-proc))
1448 ;; `python-send-command''s call to `compilation-forget-errors'.
1451 (defun python-send-string (string)
1454 (comint-send-string (python-proc) string)
1457 (comint-send-string (python-proc) "\n"))
1461 (comint-send-string (python-proc) "\n")))
1463 (defun python-send-buffer ()
1466 (python-send-region (point-min) (point-max)))
1470 (defun python-send-defun ()
1473 (save-excursion (python-send-region (progn (beginning-of-defun) (point))
1476 (defun python-switch-to-python (eob-p)
1480 (pop-to-buffer (process-buffer (python-proc)) t) ;Runs python if needed.
1485 (defun python-send-region-and-go (start end)
1489 (python-send-region start end)
1490 (python-switch-to-python t))
1492 (defcustom python-source-modes '(python-mode jython-mode)
1495 it is considered Python source by `python-load-file', which uses the
1498 :group 'python)
1500 (defvar python-prev-dir/file nil
1501 "Caches (directory . file) pair used in the last `python-load-file' command.
1506 (defun python-load-file (file-name)
1512 (interactive (comint-get-source "Load Python file: " python-prev-dir/file
1513 python-source-modes
1516 (setq python-prev-dir/file (cons (file-name-directory file-name)
1518 (with-current-buffer (process-buffer (python-proc)) ;Runs python if needed.
1519 ;; Fixme: I'm not convinced by this logic from python-mode.el.
1520 (python-send-command
1529 (defun python-proc ()
1531 See variable `python-buffer'. Starts a new process if necessary."
1533 ;; isn't one for `python-buffer'.
1534 (unless (comint-check-proc python-buffer)
1535 (run-python nil t))
1536 (get-buffer-process (if (derived-mode-p 'inferior-python-mode)
1538 python-buffer)))
1540 (defun python-set-proc ()
1541 "Set the default value of `python-buffer' to correspond to this buffer.
1542 If the current buffer has a local value of `python-buffer', set the
1544 the one that gets input from \\[python-send-region] et al when used
1545 in a buffer that doesn't have a local value of `python-buffer'."
1547 (if (local-variable-p 'python-buffer)
1548 (setq-default python-buffer python-buffer)
1549 (error "No local value of `python-buffer'")))
1554 (defconst python-dotty-syntax-table
1556 (set-char-table-parent table python-mode-syntax-table)
1560 Otherwise inherits from `python-mode-syntax-table'.")
1565 (defvar python-imports) ; forward declaration
1570 (defun python-describe-symbol (symbol)
1584 (let ((symbol (with-syntax-table python-dotty-syntax-table
1603 (help-setup-xref (list 'python-describe-symbol symbol) (interactive-p))
1607 symbol python-imports)
1608 "*Help*" (python-proc) nil nil))
1612 (defun python-send-receive (string)
1615 (python-send-string string)
1616 (let ((proc (python-proc)))
1618 (set (make-local-variable 'python-preoutput-result) nil)
1621 (null python-preoutput-result)))
1622 (prog1 python-preoutput-result
1623 (kill-local-variable 'python-preoutput-result)))))
1627 (defun python-eldoc-function ()
1631 (let ((symbol (with-syntax-table python-dotty-syntax-table
1637 (python-send-receive (format "emacs.eargs(%S, %s)"
1638 symbol python-imports)))
1649 (python-send-receive
1652 python-imports))))))))))))
1657 (defun python-after-info-look ()
1660 (let* ((version (let ((s (shell-command-to-string (concat python-command
1671 (Info-goto-node (format "(python%s-lib)Miscellaneous Index"
1676 :mode 'python-mode
1685 `((,(concat "(python" version "-ref)Miscellaneous Index") nil "")
1686 (,(concat "(python" version "-ref)Module Index" nil ""))
1687 (,(concat "(python" version "-ref)Function-Method-Variable Index"
1689 (,(concat "(python" version "-ref)Class-Exception-Object Index"
1691 (,(concat "(python" version "-lib)Module Index" nil ""))
1692 (,(concat "(python" version "-lib)Class-Exception-Object Index"
1694 (,(concat "(python" version "-lib)Function-Method-Variable Index"
1696 (,(concat "(python" version "-lib)Miscellaneous Index" nil "")))
1697 '(("(python-ref)Miscellaneous Index" nil "")
1698 ("(python-ref)Module Index" nil "")
1699 ("(python-ref)Function-Method-Variable Index" nil "")
1700 ("(python-ref)Class-Exception-Object Index" nil "")
1701 ("(python-lib)Module Index" nil "")
1702 ("(python-lib)Class-Exception-Object Index" nil "")
1703 ("(python-lib)Function-Method-Variable Index" nil "")
1704 ("(python-lib)Miscellaneous Index" nil ""))))))
1705 (eval-after-load "info-look" '(python-after-info-look))
1710 (defcustom python-jython-packages '("java" "javax" "org" "com")
1712 If these are imported near the beginning of the buffer, `python-mode'
1715 :group 'python)
1717 ;; Called from `python-mode', this causes a recursive call of the
1719 (defun python-maybe-jython ()
1723 `python-jython-packages'."
1724 ;; The logic is taken from python-mode.el.
1742 (if (member (match-string 1) python-jython-packages)
1746 (defun python-fill-paragraph (&optional justify)
1789 (defun python-shift-left (start end &optional count)
1791 COUNT defaults to `python-indent'. If region isn't active, just shift
1800 (setq count python-indent))
1813 (defun python-shift-right (start end &optional count)
1815 COUNT defaults to `python-indent'. If region isn't active, just shift
1823 (setq count python-indent))
1826 (defun python-outline-level ()
1828 The level is the number of `python-indent' steps of indentation
1830 (1+ (/ (current-indentation) python-indent)))
1833 (defun python-current-defun ()
1842 (python-beginning-of-block)
1850 (defun python-mark-block ()
1852 Uses `python-beginning-of-block', `python-end-of-block'."
1855 (python-beginning-of-block)
1857 (python-end-of-block)
1867 (defvar python-imports nil
1868 "String of top-level import statements updated by `python-find-imports'.")
1869 (make-variable-buffer-local 'python-imports)
1877 (defun python-find-imports ()
1878 "Find top-level imports, updating `python-imports'."
1888 (setq python-imports
1903 (set-text-properties 0 (length python-imports) nil python-imports)
1906 (setq python-imports
1908 (format "%S" python-imports) t t))))))
1912 (defun python-symbol-completions (symbol)
1915 Uses `python-imports' to load modules against which to complete."
1920 (python-send-receive
1921 (format "emacs.complete(%S,%s)" symbol python-imports))))
1928 (defun python-partial-symbol ()
1939 (defun python-complete-symbol ()
1955 (symbol (python-partial-symbol))
1956 (completions (python-symbol-completions symbol))
1973 (defun python-try-complete (old)
1975 (when (derived-mode-p 'python-mode) ; though we only add it locally
1977 (let ((symbol (python-partial-symbol)))
1982 (and symbol (python-symbol-completions symbol)))))
1996 (defun python-module-path (module)
1998 (python-send-receive (format "emacs.modpath (%S)" module)))
2001 '(push '(python-mode . python-module-path) ffap-alist))
2006 (defcustom python-use-skeletons nil
2011 :group 'python)
2013 (defvar python-skeletons nil
2017 (defvar python-mode-abbrev-table nil
2019 The default contents correspond to the elements of `python-skeletons'.")
2020 (define-abbrev-table 'python-mode-abbrev-table ())
2023 ;; Define a user-level skeleton and add it to `python-skeletons' and
2025 (defmacro def-python-skeleton (name &rest elements)
2027 (function (intern (concat "python-insert-" name))))
2029 (add-to-list 'python-skeletons ',(cons name function))
2030 (if python-use-skeletons
2031 (define-abbrev python-mode-abbrev-table ,name "" ',function nil t))
2035 (put 'def-python-skeleton 'lisp-indent-function 2)
2043 (def-python-skeleton if
2051 (python-else) | ^)
2053 (define-skeleton python-else
2061 (def-python-skeleton while
2065 (python-else) | ^)
2067 (def-python-skeleton for
2071 (python-else) | ^)
2073 (def-python-skeleton try/except
2078 < "except " str (python-target) ":" \n
2082 (python-else) | ^)
2084 (define-skeleton python-target
2088 (def-python-skeleton try/finally
2095 (def-python-skeleton def
2102 (def-python-skeleton class
2112 (defvar python-default-template "if"
2113 "Default template to expand by `python-expand-template'.
2116 (defun python-expand-template (name)
2121 python-default-template)
2122 python-skeletons nil t)))
2124 (setq name python-default-template)
2125 (setq python-default-template name))
2126 (let ((func (cdr (assoc name python-skeletons))))
2141 (defun python-setup-brm ()
2152 (features (cons 'python-mode features))) ; and requires this
2154 (remove-hook 'python-mode-hook ; undo this from `brm-init'
2157 python-brm-menu python-mode-map
2190 (defun python-abbrev-pc-hook ()
2192 (remove-hook 'post-command-hook 'python-abbrev-pc-hook t)
2193 (set-syntax-table python-mode-syntax-table))
2195 (defvar python-abbrev-syntax-table
2196 (copy-syntax-table python-mode-syntax-table)
2199 (defun python-pea-hook ()
2201 (set-syntax-table python-abbrev-syntax-table)
2202 (add-hook 'post-command-hook 'python-abbrev-pc-hook nil t))
2203 (modify-syntax-entry ?/ "w" python-abbrev-syntax-table)
2205 (defvar python-mode-running) ;Dynamically scoped var.
2208 (define-derived-mode python-mode fundamental-mode "Python"
2212 contain Jython code. See also `run-python' and associated Python mode
2220 \\<python-mode-map>
2222 an else statement. \\[python-backspace] at the beginning of an indented statement
2241 \\{python-mode-map}"
2242 :group 'python
2244 '(python-font-lock-keywords nil nil nil nil
2246 . python-font-lock-syntactic-keywords)
2249 ;; . python-font-lock-syntactic-face-function)
2254 (set (make-local-variable 'indent-line-function) #'python-indent-line)
2255 (set (make-local-variable 'indent-region-function) #'python-indent-region)
2257 (set (make-local-variable 'fill-paragraph-function) 'python-fill-paragraph)
2260 #'python-current-defun)
2266 (set (make-local-variable 'outline-level) #'python-outline-level)
2268 (make-local-variable 'python-saved-check-command)
2270 'python-beginning-of-defun)
2271 (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
2272 (setq imenu-create-index-function #'python-imenu-create-index)
2274 #'python-eldoc-function)
2276 (lambda () (run-python nil t)) ; need it running
2282 `(python-mode "^\\s-*def\\>" nil "#"
2284 (python-end-of-defun)
2288 '((< '(backward-delete-char-untabify (min python-indent
2291 (add-hook 'pre-abbrev-expand-hook 'python-pea-hook nil t)
2294 (cons 'python-try-complete hippie-expand-try-functions-list)))
2297 (when python-guess-indent (python-guess-indent))
2299 (unless (= tab-width python-indent)
2301 (set (make-local-variable 'python-command) python-python-command)
2302 (python-find-imports)
2303 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode
2304 (let ((python-mode-running t))
2305 (python-maybe-jython))))
2307 (custom-add-option 'python-mode-hook 'imenu-add-menubar-index)
2308 (custom-add-option 'python-mode-hook
2312 (custom-add-option 'python-mode-hook 'turn-on-eldoc-mode)
2313 (custom-add-option 'python-mode-hook 'abbrev-mode)
2314 (custom-add-option 'python-mode-hook 'python-setup-brm)
2317 (define-derived-mode jython-mode python-mode "Jython"
2319 Like `python-mode', but sets up parameters for Jython subprocesses.
2320 Runs `jython-mode-hook' after `python-mode-hook'."
2321 :group 'python
2322 (set (make-local-variable 'python-command) python-jython-command))
2324 (provide 'python)
2325 (provide 'python-21)
2327 ;;; python.el ends here