comparison lisp/progmodes/python.el @ 72461:2fee33a062da

Remove * in defcustom docstrings. (run-python, python-proc, python-try-complete): Use derived-mode-p. (python-mode): Set tab-width and indent-tabs-mode.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sun, 20 Aug 2006 18:14:50 +0000
parents 2657308de2f6
children 9d3a9b609c04
comparison
equal deleted inserted replaced
72460:dd4d02e66de4 72461:2fee33a062da
398 (not (python-open-block-statement-p))))) 398 (not (python-open-block-statement-p)))))
399 399
400 ;;;; Indentation. 400 ;;;; Indentation.
401 401
402 (defcustom python-indent 4 402 (defcustom python-indent 4
403 "*Number of columns for a unit of indentation in Python mode. 403 "Number of columns for a unit of indentation in Python mode.
404 See also `\\[python-guess-indent]'" 404 See also `\\[python-guess-indent]'"
405 :group 'python 405 :group 'python
406 :type 'integer) 406 :type 'integer)
407 407
408 (defcustom python-guess-indent t 408 (defcustom python-guess-indent t
409 "*Non-nil means Python mode guesses `python-indent' for the buffer." 409 "Non-nil means Python mode guesses `python-indent' for the buffer."
410 :type 'boolean 410 :type 'boolean
411 :group 'python) 411 :group 'python)
412 412
413 (defcustom python-indent-string-contents t 413 (defcustom python-indent-string-contents t
414 "*Non-nil means indent contents of multi-line strings together. 414 "Non-nil means indent contents of multi-line strings together.
415 This means indent them the same as the preceding non-blank line. 415 This means indent them the same as the preceding non-blank line.
416 Otherwise preserve their indentation. 416 Otherwise preserve their indentation.
417 417
418 This only applies to `doc' strings, i.e. those that form statements; 418 This only applies to `doc' strings, i.e. those that form statements;
419 the indentation is preserved in others." 419 the indentation is preserved in others."
428 are always indented in lines with preceding comments." 428 are always indented in lines with preceding comments."
429 :type 'boolean 429 :type 'boolean
430 :group 'python) 430 :group 'python)
431 431
432 (defcustom python-continuation-offset 4 432 (defcustom python-continuation-offset 4
433 "*Number of columns of additional indentation for continuation lines. 433 "Number of columns of additional indentation for continuation lines.
434 Continuation lines follow a backslash-terminated line starting a 434 Continuation lines follow a backslash-terminated line starting a
435 statement." 435 statement."
436 :group 'python 436 :group 'python
437 :type 'integer) 437 :type 'integer)
438 438
1092 (put 'python-backspace 'delete-selection 'supersede) 1092 (put 'python-backspace 'delete-selection 'supersede)
1093 1093
1094 ;;;; pychecker 1094 ;;;; pychecker
1095 1095
1096 (defcustom python-check-command "pychecker --stdlib" 1096 (defcustom python-check-command "pychecker --stdlib"
1097 "*Command used to check a Python file." 1097 "Command used to check a Python file."
1098 :type 'string 1098 :type 'string
1099 :group 'python) 1099 :group 'python)
1100 1100
1101 (defvar python-saved-check-command nil 1101 (defvar python-saved-check-command nil
1102 "Internal use.") 1102 "Internal use.")
1124 ;;;; Inferior mode stuff (following cmuscheme). 1124 ;;;; Inferior mode stuff (following cmuscheme).
1125 1125
1126 ;; Fixme: Make sure we can work with IPython. 1126 ;; Fixme: Make sure we can work with IPython.
1127 1127
1128 (defcustom python-python-command "python" 1128 (defcustom python-python-command "python"
1129 "*Shell command to run Python interpreter. 1129 "Shell command to run Python interpreter.
1130 Any arguments can't contain whitespace. 1130 Any arguments can't contain whitespace.
1131 Note that IPython may not work properly; it must at least be used 1131 Note that IPython may not work properly; it must at least be used
1132 with the `-cl' flag, i.e. use `ipython -cl'." 1132 with the `-cl' flag, i.e. use `ipython -cl'."
1133 :group 'python 1133 :group 'python
1134 :type 'string) 1134 :type 'string)
1135 1135
1136 (defcustom python-jython-command "jython" 1136 (defcustom python-jython-command "jython"
1137 "*Shell command to run Jython interpreter. 1137 "Shell command to run Jython interpreter.
1138 Any arguments can't contain whitespace." 1138 Any arguments can't contain whitespace."
1139 :group 'python 1139 :group 'python
1140 :type 'string) 1140 :type 'string)
1141 1141
1142 (defvar python-command python-python-command 1142 (defvar python-command python-python-command
1225 (set (make-local-variable 'compilation-error-regexp-alist) 1225 (set (make-local-variable 'compilation-error-regexp-alist)
1226 python-compilation-regexp-alist) 1226 python-compilation-regexp-alist)
1227 (compilation-shell-minor-mode 1)) 1227 (compilation-shell-minor-mode 1))
1228 1228
1229 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'" 1229 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'"
1230 "*Input matching this regexp is not saved on the history list. 1230 "Input matching this regexp is not saved on the history list.
1231 Default ignores all inputs of 0, 1, or 2 non-blank characters." 1231 Default ignores all inputs of 0, 1, or 2 non-blank characters."
1232 :type 'regexp 1232 :type 'regexp
1233 :group 'python) 1233 :group 'python)
1234 1234
1235 (defun python-input-filter (str) 1235 (defun python-input-filter (str)
1332 (car cmdlist) nil (cdr cmdlist))) 1332 (car cmdlist) nil (cdr cmdlist)))
1333 (setq-default python-buffer (current-buffer)) 1333 (setq-default python-buffer (current-buffer))
1334 (setq python-buffer (current-buffer))) 1334 (setq python-buffer (current-buffer)))
1335 (accept-process-output (get-buffer-process python-buffer) 5) 1335 (accept-process-output (get-buffer-process python-buffer) 5)
1336 (inferior-python-mode))) 1336 (inferior-python-mode)))
1337 (if (eq 'python-mode major-mode) 1337 (if (derived-mode-p 'python-mode)
1338 (setq python-buffer (default-value 'python-buffer))) ; buffer-local 1338 (setq python-buffer (default-value 'python-buffer))) ; buffer-local
1339 ;; Load function definitions we need. 1339 ;; Load function definitions we need.
1340 ;; Before the preoutput function was used, this was done via -c in 1340 ;; Before the preoutput function was used, this was done via -c in
1341 ;; cmdlist, but that loses the banner and doesn't run the startup 1341 ;; cmdlist, but that loses the banner and doesn't run the startup
1342 ;; file. The code might be inline here, but there's enough that it 1342 ;; file. The code might be inline here, but there's enough that it
1439 (interactive "r") 1439 (interactive "r")
1440 (python-send-region start end) 1440 (python-send-region start end)
1441 (python-switch-to-python t)) 1441 (python-switch-to-python t))
1442 1442
1443 (defcustom python-source-modes '(python-mode jython-mode) 1443 (defcustom python-source-modes '(python-mode jython-mode)
1444 "*Used to determine if a buffer contains Python source code. 1444 "Used to determine if a buffer contains Python source code.
1445 If a file is loaded into a buffer that is in one of these major modes, 1445 If a file is loaded into a buffer that is in one of these major modes,
1446 it is considered Python source by `python-load-file', which uses the 1446 it is considered Python source by `python-load-file', which uses the
1447 value to determine defaults." 1447 value to determine defaults."
1448 :type '(repeat function) 1448 :type '(repeat function)
1449 :group 'python) 1449 :group 'python)
1482 See variable `python-buffer'. Starts a new process if necessary." 1482 See variable `python-buffer'. Starts a new process if necessary."
1483 ;; Fixme: Maybe should look for another active process if there 1483 ;; Fixme: Maybe should look for another active process if there
1484 ;; isn't one for `python-buffer'. 1484 ;; isn't one for `python-buffer'.
1485 (unless (comint-check-proc python-buffer) 1485 (unless (comint-check-proc python-buffer)
1486 (run-python nil t)) 1486 (run-python nil t))
1487 (get-buffer-process (or (if (eq major-mode 'inferior-python-mode) 1487 (get-buffer-process (or (if (derived-mode-p 'inferior-python-mode)
1488 (current-buffer) 1488 (current-buffer)
1489 python-buffer)))) 1489 python-buffer))))
1490 1490
1491 (defun python-set-proc () 1491 (defun python-set-proc ()
1492 "Set the default value of `python-buffer' to correspond to this buffer. 1492 "Set the default value of `python-buffer' to correspond to this buffer.
1493 If the current buffer has a local value of `python-buffer', set the 1493 If the current buffer has a local value of `python-buffer', set the
1494 default (global) value to that. The associated Python process is 1494 default (global) value to that. The associated Python process is
1910 (display-completion-list completions symbol)) 1910 (display-completion-list completions symbol))
1911 (message "Making completion list...%s" "done")))))))) 1911 (message "Making completion list...%s" "done"))))))))
1912 1912
1913 (defun python-try-complete (old) 1913 (defun python-try-complete (old)
1914 "Completion function for Python for use with `hippie-expand'." 1914 "Completion function for Python for use with `hippie-expand'."
1915 (when (eq major-mode 'python-mode) ; though we only add it locally 1915 (when (derived-mode-p 'python-mode) ; though we only add it locally
1916 (unless old 1916 (unless old
1917 (let ((symbol (python-partial-symbol))) 1917 (let ((symbol (python-partial-symbol)))
1918 (he-init-string (- (point) (length symbol)) (point)) 1918 (he-init-string (- (point) (length symbol)) (point))
1919 (if (not (he-string-member he-search-string he-tried-table)) 1919 (if (not (he-string-member he-search-string he-tried-table))
1920 (push he-search-string he-tried-table)) 1920 (push he-search-string he-tried-table))
2216 (^ '(- (1+ (current-indentation)))))) 2216 (^ '(- (1+ (current-indentation))))))
2217 (add-hook 'pre-abbrev-expand-hook 'python-pea-hook nil t) 2217 (add-hook 'pre-abbrev-expand-hook 'python-pea-hook nil t)
2218 (if (featurep 'hippie-exp) 2218 (if (featurep 'hippie-exp)
2219 (set (make-local-variable 'hippie-expand-try-functions-list) 2219 (set (make-local-variable 'hippie-expand-try-functions-list)
2220 (cons 'python-try-complete hippie-expand-try-functions-list))) 2220 (cons 'python-try-complete hippie-expand-try-functions-list)))
2221 ;; Python defines TABs as being 8-char wide.
2222 (set (make-local-variable 'tab-width) 8)
2221 (when python-guess-indent (python-guess-indent)) 2223 (when python-guess-indent (python-guess-indent))
2224 ;; Let's make it harder for the user to shoot himself in the foot.
2225 (unless (= tab-width python-indent)
2226 (setq indent-tabs-mode nil))
2222 (set (make-local-variable 'python-command) python-python-command) 2227 (set (make-local-variable 'python-command) python-python-command)
2223 (python-find-imports) 2228 (python-find-imports)
2224 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode 2229 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode
2225 (let ((python-mode-running t)) 2230 (let ((python-mode-running t))
2226 (python-maybe-jython)))) 2231 (python-maybe-jython))))
2227 2232
2228 (custom-add-option 'python-mode-hook 'imenu-add-menubar-index) 2233 (custom-add-option 'python-mode-hook 'imenu-add-menubar-index)
2229 (custom-add-option 'python-mode-hook 2234 (custom-add-option 'python-mode-hook
2230 '(lambda () 2235 (lambda ()
2231 "Turn off Indent Tabs mode." 2236 "Turn off Indent Tabs mode."
2232 (set (make-local-variable 'indent-tabs-mode) nil))) 2237 (set (make-local-variable 'indent-tabs-mode) nil)))
2233 (custom-add-option 'python-mode-hook 'turn-on-eldoc-mode) 2238 (custom-add-option 'python-mode-hook 'turn-on-eldoc-mode)
2234 (custom-add-option 'python-mode-hook 'abbrev-mode) 2239 (custom-add-option 'python-mode-hook 'abbrev-mode)
2235 (custom-add-option 'python-mode-hook 'python-setup-brm) 2240 (custom-add-option 'python-mode-hook 'python-setup-brm)
2236 2241
2237 ;;;###autoload 2242 ;;;###autoload