aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:03:09 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:09 -0300
commite2d8d4790fa69c61976341e89e61eec558a4bcc7 (patch)
tree6ea67196272c525e1560d46cdb79143041d94a77 /lisp/progmodes/python.el
parentc0428ba0bd8f0d9e4e05bc12aa7fce2df4e2dc11 (diff)
downloademacs-e2d8d4790fa69c61976341e89e61eec558a4bcc7.tar.gz
emacs-e2d8d4790fa69c61976341e89e61eec558a4bcc7.zip
Documentation enhancements
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el191
1 files changed, 90 insertions, 101 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 92a19309dc1..0a09ec55ef7 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1,6 +1,6 @@
1;;; python.el -- Python's flying circus support for Emacs 1;;; python.el -- Python's flying circus support for Emacs
2 2
3;; Copyright (C) 2010 Free Software Foundation, Inc. 3;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
4 4
5;; Author: Fabián E. Gallina <fabian@anue.biz> 5;; Author: Fabián E. Gallina <fabian@anue.biz>
6;; Maintainer: FSF 6;; Maintainer: FSF
@@ -34,7 +34,7 @@
34 34
35;; Implements Syntax highlighting, Indentation, Movement, Shell 35;; Implements Syntax highlighting, Indentation, Movement, Shell
36;; interaction, Shell completion, Pdb tracking, Symbol completion, 36;; interaction, Shell completion, Pdb tracking, Symbol completion,
37;; Eldoc. 37;; Skeletons, FFAP, Code Check, Eldoc.
38 38
39;; Syntax highlighting: Fontification of code is provided and supports 39;; Syntax highlighting: Fontification of code is provided and supports
40;; python's triple quoted strings properly. 40;; python's triple quoted strings properly.
@@ -255,7 +255,8 @@
255 "=" "%" "**" "//" "<<" ">>" "<=" "!=" 255 "=" "%" "**" "//" "<<" ">>" "<=" "!="
256 "==" ">=" "is" "not"))) 256 "==" ">=" "is" "not")))
257 `(assignment-operator . ,(rx (or "=" "+=" "-=" "*=" "/=" "//=" "%=" "**=" 257 `(assignment-operator . ,(rx (or "=" "+=" "-=" "*=" "/=" "//=" "%=" "**="
258 ">>=" "<<=" "&=" "^=" "|=")))))) 258 ">>=" "<<=" "&=" "^=" "|="))))
259 "Additional Python specific sexps for `python-rx'"))
259 260
260(defmacro python-rx (&rest regexps) 261(defmacro python-rx (&rest regexps)
261 "Python mode especialized rx macro which supports common python named REGEXPS." 262 "Python mode especialized rx macro which supports common python named REGEXPS."
@@ -498,23 +499,18 @@ These make `python-indent-calculate-indentation' subtract the value of
498 (when (> indent-offset 0) 499 (when (> indent-offset 0)
499 (setq python-indent-offset indent-offset)))))))) 500 (setq python-indent-offset indent-offset))))))))
500 501
501(defun python-indent-context (&optional stop) 502(defun python-indent-context ()
502 "Return information on indentation context. 503 "Get information on indentation context.
503Optional argument STOP serves to stop recursive calls. 504Context information is returned with a cons with the form:
504 505 \(STATUS . START)
505Returns a cons with the form:
506
507\(STATUS . START)
508 506
509Where status can be any of the following symbols: 507Where status can be any of the following symbols:
510
511 * inside-paren: If point in between (), {} or [] 508 * inside-paren: If point in between (), {} or []
512 * inside-string: If point is inside a string 509 * inside-string: If point is inside a string
513 * after-backslash: Previous line ends in a backslash 510 * after-backslash: Previous line ends in a backslash
514 * after-beginning-of-block: Point is after beginning of block 511 * after-beginning-of-block: Point is after beginning of block
515 * after-line: Point is after normal line 512 * after-line: Point is after normal line
516 * no-indent: Point is at beginning of buffer or other special case 513 * no-indent: Point is at beginning of buffer or other special case
517
518START is the buffer position where the sexp starts." 514START is the buffer position where the sexp starts."
519 (save-restriction 515 (save-restriction
520 (widen) 516 (widen)
@@ -704,27 +700,23 @@ START is the buffer position where the sexp starts."
704 700
705(defun python-indent-line (&optional force-toggle) 701(defun python-indent-line (&optional force-toggle)
706 "Internal implementation of `python-indent-line-function'. 702 "Internal implementation of `python-indent-line-function'.
707
708Uses the offset calculated in 703Uses the offset calculated in
709`python-indent-calculate-indentation' and available levels 704`python-indent-calculate-indentation' and available levels
710indicated by the variable `python-indent-levels'. 705indicated by the variable `python-indent-levels' to set the
706current indentation.
711 707
712When the variable `last-command' is equal to 708When the variable `last-command' is equal to
713`indent-for-tab-command' or FORCE-TOGGLE is non-nil: 709`indent-for-tab-command' or FORCE-TOGGLE is non-nil it cycles
714 710levels indicated in the variable `python-indent-levels' by
715* Cycles levels indicated in the variable `python-indent-levels' 711setting the current level in the variable
716 by setting the current level in the variable 712`python-indent-current-level'.
717 `python-indent-current-level'.
718 713
719When the variable `last-command' is not equal to 714When the variable `last-command' is not equal to
720`indent-for-tab-command' and FORCE-TOGGLE is nil: 715`indent-for-tab-command' and FORCE-TOGGLE is nil it calculates
721 716possible indentation levels and saves it in the variable
722* calculates possible indentation levels and saves it in the 717`python-indent-levels'. Afterwards it sets the variable
723 variable `python-indent-levels'. 718`python-indent-current-level' correctly so offset is equal
724 719to (`nth' `python-indent-current-level' `python-indent-levels')"
725* sets the variable `python-indent-current-level' correctly so
726 offset is equal to (`nth' `python-indent-current-level'
727 `python-indent-levels')"
728 (if (or (and (eq this-command 'indent-for-tab-command) 720 (if (or (and (eq this-command 'indent-for-tab-command)
729 (eq last-command this-command)) 721 (eq last-command this-command))
730 force-toggle) 722 force-toggle)
@@ -745,11 +737,11 @@ When the variable `last-command' is not equal to
745 737
746(defun python-indent-line-function () 738(defun python-indent-line-function ()
747 "`indent-line-function' for Python mode. 739 "`indent-line-function' for Python mode.
748Internally just calls `python-indent-line'." 740See `python-indent-line' for details."
749 (python-indent-line)) 741 (python-indent-line))
750 742
751(defun python-indent-dedent-line () 743(defun python-indent-dedent-line ()
752 "Dedent current line." 744 "De-indent current line."
753 (interactive "*") 745 (interactive "*")
754 (when (and (not (or (python-info-ppss-context 'string) 746 (when (and (not (or (python-info-ppss-context 'string)
755 (python-info-ppss-context 'comment))) 747 (python-info-ppss-context 'comment)))
@@ -761,9 +753,9 @@ Internally just calls `python-indent-line'."
761 t)) 753 t))
762 754
763(defun python-indent-dedent-line-backspace (arg) 755(defun python-indent-dedent-line-backspace (arg)
764 "Dedent current line. 756 "De-indent current line.
765Argument ARG is passed to `backward-delete-char-untabify' when 757Argument ARG is passed to `backward-delete-char-untabify' when
766point is not in between the indentation." 758point is not in between the indentation."
767 (interactive "*p") 759 (interactive "*p")
768 (when (not (python-indent-dedent-line)) 760 (when (not (python-indent-dedent-line))
769 (backward-delete-char-untabify arg))) 761 (backward-delete-char-untabify arg)))
@@ -795,15 +787,10 @@ Called from a program, START and END specify the region to indent."
795 787
796(defun python-indent-shift-left (start end &optional count) 788(defun python-indent-shift-left (start end &optional count)
797 "Shift lines contained in region START END by COUNT columns to the left. 789 "Shift lines contained in region START END by COUNT columns to the left.
798 790COUNT defaults to `python-indent-offset'. If region isn't
799COUNT defaults to `python-indent-offset'. 791active, the current line is shifted. The shifted region includes
800 792the lines in which START and END lie. An error is signaled if
801If region isn't active, the current line is shifted. 793any lines in the region are indented less than COUNT columns."
802
803The shifted region includes the lines in which START and END lie.
804
805An error is signaled if any lines in the region are indented less
806than COUNT columns."
807 (interactive 794 (interactive
808 (if mark-active 795 (if mark-active
809 (list (region-beginning) (region-end) current-prefix-arg) 796 (list (region-beginning) (region-end) current-prefix-arg)
@@ -826,13 +813,9 @@ than COUNT columns."
826 813
827(defun python-indent-shift-right (start end &optional count) 814(defun python-indent-shift-right (start end &optional count)
828 "Shift lines contained in region START END by COUNT columns to the left. 815 "Shift lines contained in region START END by COUNT columns to the left.
829 816COUNT defaults to `python-indent-offset'. If region isn't
830COUNT defaults to `python-indent-offset'. 817active, the current line is shifted. The shifted region includes
831 818the lines in which START and END lie."
832If region isn't active, the current line is shifted.
833
834The shifted region includes the lines in which START and END
835lie."
836 (interactive 819 (interactive
837 (if mark-active 820 (if mark-active
838 (list (region-beginning) (region-end) current-prefix-arg) 821 (list (region-beginning) (region-end) current-prefix-arg)
@@ -844,9 +827,9 @@ lie."
844 (indent-rigidly start end count))) 827 (indent-rigidly start end count)))
845 828
846(defun python-indent-electric-colon (arg) 829(defun python-indent-electric-colon (arg)
847 "Insert a colon and maybe outdent the line if it is a statement like `else'. 830 "Insert a colon and maybe de-indent the current line.
848With numeric ARG, just insert that many colons. With \\[universal-argument], 831With numeric ARG, just insert that many colons. With
849just insert a single colon." 832\\[universal-argument], just insert a single colon."
850 (interactive "*P") 833 (interactive "*P")
851 (self-insert-command (if (not (integerp arg)) 1 arg)) 834 (self-insert-command (if (not (integerp arg)) 1 arg))
852 (when (and (not arg) 835 (when (and (not arg)
@@ -974,29 +957,29 @@ Returns nil if point is not in a def or class."
974 :safe 'stringp) 957 :safe 'stringp)
975 958
976(defcustom python-shell-prompt-regexp ">>> " 959(defcustom python-shell-prompt-regexp ">>> "
977 "Regex matching top\-level input prompt of python shell. 960 "Regular Expression matching top\-level input prompt of python shell.
978The regex should not contain a caret (^) at the beginning." 961It should not contain a caret (^) at the beginning."
979 :type 'string 962 :type 'string
980 :group 'python 963 :group 'python
981 :safe 'stringp) 964 :safe 'stringp)
982 965
983(defcustom python-shell-prompt-block-regexp "[.][.][.] " 966(defcustom python-shell-prompt-block-regexp "[.][.][.] "
984 "Regex matching block input prompt of python shell. 967 "Regular Expression matching block input prompt of python shell.
985The regex should not contain a caret (^) at the beginning." 968It should not contain a caret (^) at the beginning."
986 :type 'string 969 :type 'string
987 :group 'python 970 :group 'python
988 :safe 'stringp) 971 :safe 'stringp)
989 972
990(defcustom python-shell-prompt-output-regexp nil 973(defcustom python-shell-prompt-output-regexp nil
991 "Regex matching output prompt of python shell. 974 "Regular Expression matching output prompt of python shell.
992The regex should not contain a caret (^) at the beginning." 975It should not contain a caret (^) at the beginning."
993 :type 'string 976 :type 'string
994 :group 'python 977 :group 'python
995 :safe 'stringp) 978 :safe 'stringp)
996 979
997(defcustom python-shell-prompt-pdb-regexp "[(<]*[Ii]?[Pp]db[>)]+ " 980(defcustom python-shell-prompt-pdb-regexp "[(<]*[Ii]?[Pp]db[>)]+ "
998 "Regex matching pdb input prompt of python shell. 981 "Regular Expression matching pdb input prompt of python shell.
999The regex should not contain a caret (^) at the beginning." 982It should not contain a caret (^) at the beginning."
1000 :type 'string 983 :type 'string
1001 :group 'python 984 :group 'python
1002 :safe 'stringp) 985 :safe 'stringp)
@@ -1005,7 +988,7 @@ The regex should not contain a caret (^) at the beginning."
1005 python-ffap-setup-code 988 python-ffap-setup-code
1006 python-eldoc-setup-code) 989 python-eldoc-setup-code)
1007 "List of code run by `python-shell-send-setup-codes'. 990 "List of code run by `python-shell-send-setup-codes'.
1008Each variable can be either a simple string with the code to 991Each variable can contain either a simple string with the code to
1009execute or a cons with the form (CODE . DESCRIPTION), where CODE 992execute or a cons with the form (CODE . DESCRIPTION), where CODE
1010is a string with the code to execute and DESCRIPTION is the 993is a string with the code to execute and DESCRIPTION is the
1011description of it." 994description of it."
@@ -1030,14 +1013,12 @@ description of it."
1030 1013
1031(defun python-shell-get-process-name (dedicated) 1014(defun python-shell-get-process-name (dedicated)
1032 "Calculate the appropiate process name for inferior Python process. 1015 "Calculate the appropiate process name for inferior Python process.
1033
1034If DEDICATED is t and the variable `buffer-file-name' is non-nil 1016If DEDICATED is t and the variable `buffer-file-name' is non-nil
1035returns a string with the form 1017returns a string with the form
1036`python-shell-buffer-name'[variable `buffer-file-name'] else 1018`python-shell-buffer-name'[variable `buffer-file-name'] else
1037returns the value of `python-shell-buffer-name'. 1019returns the value of `python-shell-buffer-name'. After
1038 1020calculating the process name adds the buffer name for the process
1039After calculating the process name add the buffer name for the 1021in the `same-window-buffer-names' list."
1040process in the `same-window-buffer-names' list"
1041 (let ((process-name 1022 (let ((process-name
1042 (if (and dedicated 1023 (if (and dedicated
1043 buffer-file-name) 1024 buffer-file-name)
@@ -1048,7 +1029,7 @@ process in the `same-window-buffer-names' list"
1048 process-name)) 1029 process-name))
1049 1030
1050(defun python-shell-parse-command () 1031(defun python-shell-parse-command ()
1051 "Calculates the string used to execute the inferior Python process." 1032 "Calculate the string used to execute the inferior Python process."
1052 (format "%s %s" python-shell-interpreter python-shell-interpreter-args)) 1033 (format "%s %s" python-shell-interpreter python-shell-interpreter-args))
1053 1034
1054(defun python-comint-output-filter-function (output) 1035(defun python-comint-output-filter-function (output)
@@ -1062,10 +1043,24 @@ OUTPUT is a string with the contents of the buffer."
1062 1043
1063(define-derived-mode inferior-python-mode comint-mode "Inferior Python" 1044(define-derived-mode inferior-python-mode comint-mode "Inferior Python"
1064 "Major mode for Python inferior process. 1045 "Major mode for Python inferior process.
1065Adds `python-shell-completion-complete-at-point' to the 1046Runs a Python interpreter as a subprocess of Emacs, with Python
1066`comint-dynamic-complete-functions' list. Also binds <tab> to 1047I/O through an Emacs buffer. Variables
1067`python-shell-complete-or-indent' in the 1048`python-shell-interpreter' and `python-shell-interpreter-args'
1068`inferior-python-mode-map'." 1049controls which Python interpreter is run. Variables
1050`python-shell-prompt-regexp',
1051`python-shell-prompt-output-regexp',
1052`python-shell-prompt-block-regexp',
1053`python-shell-completion-setup-code',
1054`python-shell-completion-string-code', `python-eldoc-setup-code',
1055`python-eldoc-string-code', `python-ffap-setup-code' and
1056`python-ffap-string-code' can customize this mode for different
1057Python interpreters.
1058
1059You can also add additional setup code to be run at
1060initialization of the interpreter via `python-shell-setup-codes'
1061variable.
1062
1063\(Type \\[describe-mode] in the process buffer for a list of commands.)"
1069 (set-syntax-table python-mode-syntax-table) 1064 (set-syntax-table python-mode-syntax-table)
1070 (setq mode-line-process '(":%s")) 1065 (setq mode-line-process '(":%s"))
1071 (setq comint-prompt-regexp (format "^\\(?:%s\\|%s\\|%s\\)" 1066 (setq comint-prompt-regexp (format "^\\(?:%s\\|%s\\|%s\\)"
@@ -1091,26 +1086,17 @@ Adds `python-shell-completion-complete-at-point' to the
1091 1086
1092(defun run-python (dedicated cmd) 1087(defun run-python (dedicated cmd)
1093 "Run an inferior Python process. 1088 "Run an inferior Python process.
1094 1089Input and output via buffer named after
1095Input and output via buffer *\\[python-shell-buffer-name]*. 1090`python-shell-buffer-name'. If there is a process already
1096 1091running in that buffer, just switch to it.
1097If there is a process already running in 1092With argument, allows you to define DEDICATED, so a dedicated
1098*\\[python-shell-buffer-name]*, switch to that buffer. 1093process for the current buffer is open, and define CMD so you can
1099 1094edit the command used to call the interpreter (default is value
1100With argument, allows you to: 1095of `python-shell-interpreter' and arguments defined in
1101 1096`python-shell-interpreter-args'). Runs the hook
1102 * Define DEDICATED so a dedicated process for the current buffer 1097`inferior-python-mode-hook' (after the `comint-mode-hook' is
1103 is open. 1098run).
1104 1099\(Type \\[describe-mode] in the process buffer for a list of commands.)"
1105 * Define CMD so you can edit the command used to call the
1106interpreter (default is value of `python-shell-interpreter' and
1107arguments defined in `python-shell-interpreter-args').
1108
1109Runs the hook `inferior-python-mode-hook' (after the
1110`comint-mode-hook' is run).
1111
1112\(Type \\[describe-mode] in the process buffer for a list of
1113commands.)"
1114 (interactive 1100 (interactive
1115 (if current-prefix-arg 1101 (if current-prefix-arg
1116 (list 1102 (list
@@ -1182,8 +1168,8 @@ When MSG is non-nil messages the first line of STRING."
1182 1168
1183(defun python-shell-send-string-no-output (string &optional process msg) 1169(defun python-shell-send-string-no-output (string &optional process msg)
1184 "Send STRING to PROCESS and inhibit output. 1170 "Send STRING to PROCESS and inhibit output.
1185When MSG is non-nil messages the first line of STRING. 1171When MSG is non-nil messages the first line of STRING. Return
1186Return the output." 1172the output."
1187 (let* ((output-buffer) 1173 (let* ((output-buffer)
1188 (process (or process (python-shell-get-or-create-process))) 1174 (process (or process (python-shell-get-or-create-process)))
1189 (comint-preoutput-filter-functions 1175 (comint-preoutput-filter-functions
@@ -1360,8 +1346,8 @@ else:
1360 1346
1361(defun python-shell-completion-complete-or-indent () 1347(defun python-shell-completion-complete-or-indent ()
1362 "Complete or indent depending on the context. 1348 "Complete or indent depending on the context.
1363If content before pointer is all whitespace indent. If not try to 1349If content before pointer is all whitespace indent. If not try
1364complete." 1350to complete."
1365 (interactive) 1351 (interactive)
1366 (if (string-match "^[[:space:]]*$" 1352 (if (string-match "^[[:space:]]*$"
1367 (buffer-substring (comint-line-beginning-position) 1353 (buffer-substring (comint-line-beginning-position)
@@ -1374,12 +1360,11 @@ complete."
1374 1360
1375(defvar python-pdbtrack-stacktrace-info-regexp 1361(defvar python-pdbtrack-stacktrace-info-regexp
1376 "> %s(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" 1362 "> %s(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()"
1377 "Regexp matching stacktrace information. 1363 "Regular Expression matching stacktrace information.
1378It is used to extract the current line and module beign 1364Used to extract the current line and module beign inspected. The
1379inspected. 1365regexp should not start with a caret (^) and can contain a string
1380The regexp should not start with a caret (^) and can contain a 1366placeholder (\%s) which is replaced with the filename beign
1381string placeholder (\%s) which is replaced with the filename 1367inspected (so other files in the debugging process are not
1382beign inspected (so other files in the debugging process are not
1383opened)") 1368opened)")
1384 1369
1385(defvar python-pdbtrack-tracking-buffers '() 1370(defvar python-pdbtrack-tracking-buffers '()
@@ -1879,7 +1864,7 @@ not inside a defun."
1879 (mapconcat (lambda (string) string) names ".")))) 1864 (mapconcat (lambda (string) string) names "."))))
1880 1865
1881(defun python-info-closing-block () 1866(defun python-info-closing-block ()
1882 "Return the point of the block that the current line closes." 1867 "Return the point of the block the current line closes."
1883 (let ((closing-word (save-excursion 1868 (let ((closing-word (save-excursion
1884 (back-to-indentation) 1869 (back-to-indentation)
1885 (current-word))) 1870 (current-word)))
@@ -1981,7 +1966,11 @@ character address of the specified TYPE."
1981 1966
1982;;;###autoload 1967;;;###autoload
1983(define-derived-mode python-mode fundamental-mode "Python" 1968(define-derived-mode python-mode fundamental-mode "Python"
1984 "A major mode for editing Python files." 1969 "Major mode for editing Python files.
1970
1971\\{python-mode-map}
1972Entry to this mode calls the value of `python-mode-hook'
1973if that value is non-nil."
1985 (set (make-local-variable 'tab-width) 8) 1974 (set (make-local-variable 'tab-width) 8)
1986 (set (make-local-variable 'indent-tabs-mode) nil) 1975 (set (make-local-variable 'indent-tabs-mode) nil)
1987 1976