aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:03:35 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:35 -0300
commit6cad4c6e3015b4b7758fa8e88f853e856bf0a705 (patch)
treee21075e99bfef27103bc5cf2d57b91e50ee59f2e /lisp/progmodes/python.el
parent0674d3fadbd4c5755598dc2791a179dbbe1d018e (diff)
downloademacs-6cad4c6e3015b4b7758fa8e88f853e856bf0a705.tar.gz
emacs-6cad4c6e3015b4b7758fa8e88f853e856bf0a705.zip
Beautified code
* All columns are now less that 79 chars. * Removed tabs that were beign used to indent code. * Reindented the whole file.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el339
1 files changed, 177 insertions, 162 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 3244f299778..3dd94c3793f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -260,48 +260,48 @@
260 (define-key map "\C-c\C-f" 'python-eldoc-at-point) 260 (define-key map "\C-c\C-f" 'python-eldoc-at-point)
261 ;; Utilities 261 ;; Utilities
262 (substitute-key-definition 'complete-symbol 'completion-at-point 262 (substitute-key-definition 'complete-symbol 'completion-at-point
263 map global-map) 263 map global-map)
264 (easy-menu-define python-menu map "Python Mode menu" 264 (easy-menu-define python-menu map "Python Mode menu"
265 `("Python" 265 `("Python"
266 :help "Python-specific Features" 266 :help "Python-specific Features"
267 ["Shift region left" python-indent-shift-left :active mark-active 267 ["Shift region left" python-indent-shift-left :active mark-active
268 :help "Shift region left by a single indentation step"] 268 :help "Shift region left by a single indentation step"]
269 ["Shift region right" python-indent-shift-right :active mark-active 269 ["Shift region right" python-indent-shift-right :active mark-active
270 :help "Shift region right by a single indentation step"] 270 :help "Shift region right by a single indentation step"]
271 "-" 271 "-"
272 ["Start of def/class" beginning-of-defun 272 ["Start of def/class" beginning-of-defun
273 :help "Go to start of outermost definition around point"] 273 :help "Go to start of outermost definition around point"]
274 ["End of def/class" end-of-defun 274 ["End of def/class" end-of-defun
275 :help "Go to end of definition around point"] 275 :help "Go to end of definition around point"]
276 ["Mark def/class" mark-defun 276 ["Mark def/class" mark-defun
277 :help "Mark outermost definition around point"] 277 :help "Mark outermost definition around point"]
278 ["Jump to def/class" python-nav-jump-to-defun 278 ["Jump to def/class" python-nav-jump-to-defun
279 :help "Jump to a class or function definition"] 279 :help "Jump to a class or function definition"]
280 "--" 280 "--"
281 ("Skeletons") 281 ("Skeletons")
282 "---" 282 "---"
283 ["Start interpreter" run-python 283 ["Start interpreter" run-python
284 :help "Run inferior Python process in a separate buffer"] 284 :help "Run inferior Python process in a separate buffer"]
285 ["Switch to shell" python-shell-switch-to-shell 285 ["Switch to shell" python-shell-switch-to-shell
286 :help "Switch to running inferior Python process"] 286 :help "Switch to running inferior Python process"]
287 ["Eval string" python-shell-send-string 287 ["Eval string" python-shell-send-string
288 :help "Eval string in inferior Python session"] 288 :help "Eval string in inferior Python session"]
289 ["Eval buffer" python-shell-send-buffer 289 ["Eval buffer" python-shell-send-buffer
290 :help "Eval buffer in inferior Python session"] 290 :help "Eval buffer in inferior Python session"]
291 ["Eval region" python-shell-send-region 291 ["Eval region" python-shell-send-region
292 :help "Eval region in inferior Python session"] 292 :help "Eval region in inferior Python session"]
293 ["Eval defun" python-shell-send-defun 293 ["Eval defun" python-shell-send-defun
294 :help "Eval defun in inferior Python session"] 294 :help "Eval defun in inferior Python session"]
295 ["Eval file" python-shell-send-file 295 ["Eval file" python-shell-send-file
296 :help "Eval file in inferior Python session"] 296 :help "Eval file in inferior Python session"]
297 ["Debugger" pdb :help "Run pdb under GUD"] 297 ["Debugger" pdb :help "Run pdb under GUD"]
298 "----" 298 "----"
299 ["Check file" python-check 299 ["Check file" python-check
300 :help "Check file for errors"] 300 :help "Check file for errors"]
301 ["Help on symbol" python-eldoc-at-point 301 ["Help on symbol" python-eldoc-at-point
302 :help "Get help on symbol at point"] 302 :help "Get help on symbol at point"]
303 ["Complete symbol" completion-at-point 303 ["Complete symbol" completion-at-point
304 :help "Complete symbol before point"])) 304 :help "Complete symbol before point"]))
305 map) 305 map)
306 "Keymap for `python-mode'.") 306 "Keymap for `python-mode'.")
307 307
@@ -316,13 +316,15 @@
316 "except" "finally" "for" "while" "with") 316 "except" "finally" "for" "while" "with")
317 symbol-end)) 317 symbol-end))
318 `(decorator . ,(rx line-start (* space) ?@ (any letter ?_) 318 `(decorator . ,(rx line-start (* space) ?@ (any letter ?_)
319 (* (any word ?_)))) 319 (* (any word ?_))))
320 `(defun . ,(rx symbol-start (or "def" "class") symbol-end)) 320 `(defun . ,(rx symbol-start (or "def" "class") symbol-end))
321 `(symbol-name . ,(rx (any letter ?_) (* (any word ?_)))) 321 `(symbol-name . ,(rx (any letter ?_) (* (any word ?_))))
322 `(open-paren . ,(rx (or "{" "[" "("))) 322 `(open-paren . ,(rx (or "{" "[" "(")))
323 `(close-paren . ,(rx (or "}" "]" ")"))) 323 `(close-paren . ,(rx (or "}" "]" ")")))
324 `(simple-operator . ,(rx (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))) 324 `(simple-operator . ,(rx (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%)))
325 `(not-simple-operator . ,(rx (not (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%)))) 325 `(not-simple-operator . ,(rx
326 (not
327 (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))))
326 `(operator . ,(rx (or "+" "-" "/" "&" "^" "~" "|" "*" "<" ">" 328 `(operator . ,(rx (or "+" "-" "/" "&" "^" "~" "|" "*" "<" ">"
327 "=" "%" "**" "//" "<<" ">>" "<=" "!=" 329 "=" "%" "**" "//" "<<" ">>" "<=" "!="
328 "==" ">=" "is" "not"))) 330 "==" ">=" "is" "not")))
@@ -331,14 +333,15 @@
331 "Additional Python specific sexps for `python-rx'")) 333 "Additional Python specific sexps for `python-rx'"))
332 334
333(defmacro python-rx (&rest regexps) 335(defmacro python-rx (&rest regexps)
334 "Python mode specialized rx macro which supports common python named REGEXPS." 336 "Python mode specialized rx macro.
335 (let ((rx-constituents (append python-rx-constituents rx-constituents))) 337This variant of `rx' supports common python named REGEXPS."
336 (cond ((null regexps) 338 (let ((rx-constituents (append python-rx-constituents rx-constituents)))
337 (error "No regexp")) 339 (cond ((null regexps)
338 ((cdr regexps) 340 (error "No regexp"))
339 (rx-to-string `(and ,@regexps) t)) 341 ((cdr regexps)
340 (t 342 (rx-to-string `(and ,@regexps) t))
341 (rx-to-string (car regexps) t))))) 343 (t
344 (rx-to-string (car regexps) t)))))
342 345
343 346
344;;; Font-lock and syntax 347;;; Font-lock and syntax
@@ -434,7 +437,7 @@
434 ;; string delimiters. Fixme: Is there a better way? 437 ;; string delimiters. Fixme: Is there a better way?
435 ;; First avoid a sequence preceded by an odd number of backslashes. 438 ;; First avoid a sequence preceded by an odd number of backslashes.
436 `((,(concat "\\(?:\\([RUru]\\)[Rr]?\\|^\\|[^\\]\\(?:\\\\.\\)*\\)" ;Prefix. 439 `((,(concat "\\(?:\\([RUru]\\)[Rr]?\\|^\\|[^\\]\\(?:\\\\.\\)*\\)" ;Prefix.
437 "\\(?:\\('\\)'\\('\\)\\|\\(?2:\"\\)\"\\(?3:\"\\)\\)") 440 "\\(?:\\('\\)'\\('\\)\\|\\(?2:\"\\)\"\\(?3:\"\\)\\)")
438 (3 (python-quote-syntax))))) 441 (3 (python-quote-syntax)))))
439 442
440(defun python-quote-syntax () 443(defun python-quote-syntax ()
@@ -459,8 +462,8 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
459 (cond 462 (cond
460 ((eq t (nth 3 syntax)) ; after unclosed fence 463 ((eq t (nth 3 syntax)) ; after unclosed fence
461 ;; Consider property for the last char if in a fenced string. 464 ;; Consider property for the last char if in a fenced string.
462 (goto-char (nth 8 syntax)) ; fence position 465 (goto-char (nth 8 syntax)) ; fence position
463 (skip-chars-forward "uUrR") ; skip any prefix 466 (skip-chars-forward "uUrR") ; skip any prefix
464 ;; Is it a matching sequence? 467 ;; Is it a matching sequence?
465 (if (eq (char-after) (char-after (match-beginning 2))) 468 (if (eq (char-after) (char-after (match-beginning 2)))
466 (put-text-property (match-beginning 3) (match-end 3) 469 (put-text-property (match-beginning 3) (match-end 3)
@@ -480,11 +483,11 @@ Used for syntactic keywords. N is the match number (1, 2 or 3)."
480 ;; Give punctuation syntax to ASCII that normally has symbol 483 ;; Give punctuation syntax to ASCII that normally has symbol
481 ;; syntax or has word syntax and isn't a letter. 484 ;; syntax or has word syntax and isn't a letter.
482 (let ((symbol (string-to-syntax "_")) 485 (let ((symbol (string-to-syntax "_"))
483 (sst (standard-syntax-table))) 486 (sst (standard-syntax-table)))
484 (dotimes (i 128) 487 (dotimes (i 128)
485 (unless (= i ?_) 488 (unless (= i ?_)
486 (if (equal symbol (aref sst i)) 489 (if (equal symbol (aref sst i))
487 (modify-syntax-entry i "." table))))) 490 (modify-syntax-entry i "." table)))))
488 (modify-syntax-entry ?$ "." table) 491 (modify-syntax-entry ?$ "." table)
489 (modify-syntax-entry ?% "." table) 492 (modify-syntax-entry ?% "." table)
490 ;; exceptions 493 ;; exceptions
@@ -531,39 +534,39 @@ These make `python-indent-calculate-indentation' subtract the value of
531 534
532(defun python-indent-guess-indent-offset () 535(defun python-indent-guess-indent-offset ()
533 "Guess and set `python-indent-offset' for the current buffer." 536 "Guess and set `python-indent-offset' for the current buffer."
534 (save-excursion 537 (save-excursion
535 (save-restriction 538 (save-restriction
536 (widen) 539 (widen)
537 (goto-char (point-min)) 540 (goto-char (point-min))
538 (let ((block-end)) 541 (let ((block-end))
539 (while (and (not block-end) 542 (while (and (not block-end)
540 (re-search-forward 543 (re-search-forward
541 (python-rx line-start block-start) nil t)) 544 (python-rx line-start block-start) nil t))
542 (when (and 545 (when (and
543 (not (python-info-ppss-context-type)) 546 (not (python-info-ppss-context-type))
544 (progn 547 (progn
545 (goto-char (line-end-position)) 548 (goto-char (line-end-position))
546 (python-util-forward-comment -1) 549 (python-util-forward-comment -1)
547 (if (equal (char-before) ?:) 550 (if (equal (char-before) ?:)
548 t 551 t
549 (forward-line 1) 552 (forward-line 1)
550 (when (python-info-block-continuation-line-p) 553 (when (python-info-block-continuation-line-p)
551 (while (and (python-info-continuation-line-p) 554 (while (and (python-info-continuation-line-p)
552 (not (eobp))) 555 (not (eobp)))
553 (forward-line 1)) 556 (forward-line 1))
554 (python-util-forward-comment -1) 557 (python-util-forward-comment -1)
555 (when (equal (char-before) ?:) 558 (when (equal (char-before) ?:)
556 t))))) 559 t)))))
557 (setq block-end (point-marker)))) 560 (setq block-end (point-marker))))
558 (let ((indentation 561 (let ((indentation
559 (when block-end 562 (when block-end
560 (goto-char block-end) 563 (goto-char block-end)
561 (python-util-forward-comment) 564 (python-util-forward-comment)
562 (current-indentation)))) 565 (current-indentation))))
563 (if indentation 566 (if indentation
564 (setq python-indent-offset indentation) 567 (setq python-indent-offset indentation)
565 (message "Can't guess python-indent-offset, using defaults: %s" 568 (message "Can't guess python-indent-offset, using defaults: %s"
566 python-indent-offset))))))) 569 python-indent-offset)))))))
567 570
568(defun python-indent-context () 571(defun python-indent-context ()
569 "Get information on indentation context. 572 "Get information on indentation context.
@@ -599,7 +602,8 @@ START is the buffer position where the sexp starts."
599 ((setq start (when (not (or (python-info-ppss-context 'string ppss) 602 ((setq start (when (not (or (python-info-ppss-context 'string ppss)
600 (python-info-ppss-context 'comment ppss))) 603 (python-info-ppss-context 'comment ppss)))
601 (let ((line-beg-pos (line-beginning-position))) 604 (let ((line-beg-pos (line-beginning-position)))
602 (when (python-info-line-ends-backslash-p (1- line-beg-pos)) 605 (when (python-info-line-ends-backslash-p
606 (1- line-beg-pos))
603 (- line-beg-pos 2))))) 607 (- line-beg-pos 2)))))
604 'after-backslash) 608 'after-backslash)
605 ;; After beginning of block 609 ;; After beginning of block
@@ -677,7 +681,8 @@ START is the buffer position where the sexp starts."
677 (when (looking-at "\\.") 681 (when (looking-at "\\.")
678 (forward-line -1) 682 (forward-line -1)
679 (goto-char (line-end-position)) 683 (goto-char (line-end-position))
680 (while (and (re-search-backward "\\." (line-beginning-position) t) 684 (while (and (re-search-backward
685 "\\." (line-beginning-position) t)
681 (or (python-info-ppss-context 'comment) 686 (or (python-info-ppss-context 'comment)
682 (python-info-ppss-context 'string) 687 (python-info-ppss-context 'string)
683 (python-info-ppss-context 'paren)))) 688 (python-info-ppss-context 'paren))))
@@ -1043,7 +1048,7 @@ Returns nil if point is not in a def or class."
1043 (python-info-line-ends-backslash-p)) 1048 (python-info-line-ends-backslash-p))
1044 (python-info-ppss-context 'string) 1049 (python-info-ppss-context 'string)
1045 (python-info-ppss-context 'paren)) 1050 (python-info-ppss-context 'paren))
1046 (forward-line -1))))) 1051 (forward-line -1)))))
1047 1052
1048(defun python-nav-sentence-end () 1053(defun python-nav-sentence-end ()
1049 "Move to end of current sentence." 1054 "Move to end of current sentence."
@@ -1054,7 +1059,7 @@ Returns nil if point is not in a def or class."
1054 (python-info-line-ends-backslash-p) 1059 (python-info-line-ends-backslash-p)
1055 (python-info-ppss-context 'string) 1060 (python-info-ppss-context 'string)
1056 (python-info-ppss-context 'paren)) 1061 (python-info-ppss-context 'paren))
1057 (forward-line 1))))) 1062 (forward-line 1)))))
1058 1063
1059(defun python-nav-backward-sentence (&optional arg) 1064(defun python-nav-backward-sentence (&optional arg)
1060 "Move backward to start of sentence. With ARG, do it arg times. 1065 "Move backward to start of sentence. With ARG, do it arg times.
@@ -1234,14 +1239,14 @@ virtualenv."
1234 1239
1235(defcustom python-shell-compilation-regexp-alist 1240(defcustom python-shell-compilation-regexp-alist
1236 `((,(rx line-start (1+ (any " \t")) "File \"" 1241 `((,(rx line-start (1+ (any " \t")) "File \""
1237 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c 1242 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c
1238 "\", line " (group (1+ digit))) 1243 "\", line " (group (1+ digit)))
1239 1 2) 1244 1 2)
1240 (,(rx " in file " (group (1+ not-newline)) " on line " 1245 (,(rx " in file " (group (1+ not-newline)) " on line "
1241 (group (1+ digit))) 1246 (group (1+ digit)))
1242 1 2) 1247 1 2)
1243 (,(rx line-start "> " (group (1+ (not (any "(\"<")))) 1248 (,(rx line-start "> " (group (1+ (not (any "(\"<"))))
1244 "(" (group (1+ digit)) ")" (1+ (not (any "("))) "()") 1249 "(" (group (1+ digit)) ")" (1+ (not (any "("))) "()")
1245 1 2)) 1250 1 2))
1246 "`compilation-error-regexp-alist' for inferior Python." 1251 "`compilation-error-regexp-alist' for inferior Python."
1247 :type '(alist string) 1252 :type '(alist string)
@@ -1684,18 +1689,19 @@ completions on the current context."
1684 "Do completion at point for PROCESS." 1689 "Do completion at point for PROCESS."
1685 (with-syntax-table python-dotty-syntax-table 1690 (with-syntax-table python-dotty-syntax-table
1686 (let* ((line (substring-no-properties 1691 (let* ((line (substring-no-properties
1687 (buffer-substring (point-at-bol) (point)) nil nil)) 1692 (buffer-substring (point-at-bol) (point)) nil nil))
1688 (input (substring-no-properties 1693 (input (substring-no-properties
1689 (or (comint-word (current-word)) "") nil nil)) 1694 (or (comint-word (current-word)) "") nil nil))
1690 (prompt (buffer-substring-no-properties 1695 (prompt (buffer-substring-no-properties
1691 (overlay-start comint-last-prompt-overlay) 1696 (overlay-start comint-last-prompt-overlay)
1692 (overlay-end comint-last-prompt-overlay))) 1697 (overlay-end comint-last-prompt-overlay)))
1693 (completion-code 1698 (completion-code
1694 (cond ((and (> (length python-shell-completion-pdb-string-code) 0) 1699 (cond ((and (> (length python-shell-completion-pdb-string-code) 0)
1695 (string-match 1700 (string-match
1696 (concat "^" python-shell-prompt-pdb-regexp) prompt)) 1701 (concat "^" python-shell-prompt-pdb-regexp) prompt))
1697 python-shell-completion-pdb-string-code) 1702 python-shell-completion-pdb-string-code)
1698 ((and (> (length python-shell-completion-module-string-code) 0) 1703 ((and (>
1704 (length python-shell-completion-module-string-code) 0)
1699 (string-match 1705 (string-match
1700 (concat "^" python-shell-prompt-regexp) prompt) 1706 (concat "^" python-shell-prompt-regexp) prompt)
1701 (string-match "^\\(from\\|import\\)[ \t]" line)) 1707 (string-match "^\\(from\\|import\\)[ \t]" line))
@@ -1708,18 +1714,18 @@ completions on the current context."
1708 (and completion-code (> (length input) 0) 1714 (and completion-code (> (length input) 0)
1709 (python-shell-completion--get-completions 1715 (python-shell-completion--get-completions
1710 line process completion-code))) 1716 line process completion-code)))
1711 (completion (when completions 1717 (completion (when completions
1712 (try-completion input completions)))) 1718 (try-completion input completions))))
1713 (cond ((eq completion t) 1719 (cond ((eq completion t)
1714 (if (eq this-command last-command) 1720 (if (eq this-command last-command)
1715 (when python-shell-completion-original-window-configuration 1721 (when python-shell-completion-original-window-configuration
1716 (set-window-configuration 1722 (set-window-configuration
1717 python-shell-completion-original-window-configuration))) 1723 python-shell-completion-original-window-configuration)))
1718 (setq python-shell-completion-original-window-configuration nil) 1724 (setq python-shell-completion-original-window-configuration nil)
1719 t) 1725 t)
1720 ((null completion) 1726 ((null completion)
1721 (message "Can't find completion for \"%s\"" input) 1727 (message "Can't find completion for \"%s\"" input)
1722 (ding) 1728 (ding)
1723 nil) 1729 nil)
1724 ((not (string= input completion)) 1730 ((not (string= input completion))
1725 (progn (delete-char (- (length input))) 1731 (progn (delete-char (- (length input)))
@@ -1740,7 +1746,7 @@ completions on the current context."
1740 (and comint-last-prompt-overlay 1746 (and comint-last-prompt-overlay
1741 (> (point-marker) (overlay-end comint-last-prompt-overlay)) 1747 (> (point-marker) (overlay-end comint-last-prompt-overlay))
1742 (python-shell-completion--do-completion-at-point 1748 (python-shell-completion--do-completion-at-point
1743 (get-buffer-process (current-buffer))))) 1749 (get-buffer-process (current-buffer)))))
1744 1750
1745(defun python-shell-completion-complete-or-indent () 1751(defun python-shell-completion-complete-or-indent ()
1746 "Complete or indent depending on the context. 1752 "Complete or indent depending on the context.
@@ -1808,13 +1814,15 @@ Argument OUTPUT is a string with the output from the comint process."
1808 ;; but in some cases (like when doing a step-in) it is 1814 ;; but in some cases (like when doing a step-in) it is
1809 ;; on the second. 1815 ;; on the second.
1810 (when (or (looking-at python-pdbtrack-stacktrace-info-regexp) 1816 (when (or (looking-at python-pdbtrack-stacktrace-info-regexp)
1811 (and (forward-line) 1817 (and
1812 (looking-at python-pdbtrack-stacktrace-info-regexp))) 1818 (forward-line)
1819 (looking-at python-pdbtrack-stacktrace-info-regexp)))
1813 (setq line-number (string-to-number 1820 (setq line-number (string-to-number
1814 (match-string-no-properties 2))) 1821 (match-string-no-properties 2)))
1815 (match-string-no-properties 1))))) 1822 (match-string-no-properties 1)))))
1816 (if (and file-name line-number) 1823 (if (and file-name line-number)
1817 (let* ((tracked-buffer (python-pdbtrack-set-tracked-buffer file-name)) 1824 (let* ((tracked-buffer
1825 (python-pdbtrack-set-tracked-buffer file-name))
1818 (shell-buffer (current-buffer)) 1826 (shell-buffer (current-buffer))
1819 (tracked-buffer-window (get-buffer-window tracked-buffer)) 1827 (tracked-buffer-window (get-buffer-window tracked-buffer))
1820 (tracked-buffer-line-pos)) 1828 (tracked-buffer-line-pos))
@@ -1855,7 +1863,8 @@ inferior python process is updated properly."
1855 (error "Completion needs an inferior Python process running") 1863 (error "Completion needs an inferior Python process running")
1856 (python-shell-completion--do-completion-at-point process)))) 1864 (python-shell-completion--do-completion-at-point process))))
1857 1865
1858(add-to-list 'debug-ignored-errors "^Completion needs an inferior Python process running.") 1866(add-to-list 'debug-ignored-errors
1867 "^Completion needs an inferior Python process running.")
1859 1868
1860 1869
1861;;; Fill paragraph 1870;;; Fill paragraph
@@ -2031,7 +2040,7 @@ the if condition."
2031The skeleton will be bound to python-skeleton-NAME and will 2040The skeleton will be bound to python-skeleton-NAME and will
2032be added to `python-mode-abbrev-table'." 2041be added to `python-mode-abbrev-table'."
2033 (let* ((name (symbol-name name)) 2042 (let* ((name (symbol-name name))
2034 (function-name (intern (concat "python-skeleton-" name)))) 2043 (function-name (intern (concat "python-skeleton-" name))))
2035 `(progn 2044 `(progn
2036 (define-abbrev python-mode-abbrev-table ,name "" ',function-name) 2045 (define-abbrev python-mode-abbrev-table ,name "" ',function-name)
2037 (setq python-skeleton-available 2046 (setq python-skeleton-available
@@ -2046,7 +2055,7 @@ be added to `python-mode-abbrev-table'."
2046 "Define a `python-mode' auxiliary skeleton using NAME DOC and SKEL. 2055 "Define a `python-mode' auxiliary skeleton using NAME DOC and SKEL.
2047The skeleton will be bound to python-skeleton-NAME." 2056The skeleton will be bound to python-skeleton-NAME."
2048 (let* ((name (symbol-name name)) 2057 (let* ((name (symbol-name name))
2049 (function-name (intern (concat "python-skeleton--" name))) 2058 (function-name (intern (concat "python-skeleton--" name)))
2050 (msg (format 2059 (msg (format
2051 "Add '%s' clause? " name))) 2060 "Add '%s' clause? " name)))
2052 (when (not skel) 2061 (when (not skel)
@@ -2107,15 +2116,15 @@ The skeleton will be bound to python-skeleton-NAME."
2107 "Function name: " 2116 "Function name: "
2108 "def " str " (" ("Parameter, %s: " 2117 "def " str " (" ("Parameter, %s: "
2109 (unless (equal ?\( (char-before)) ", ") 2118 (unless (equal ?\( (char-before)) ", ")
2110 str) "):" \n 2119 str) "):" \n
2111 "\"\"\"" - "\"\"\"" \n 2120 "\"\"\"" - "\"\"\"" \n
2112 > _ \n) 2121 > _ \n)
2113 2122
2114(python-skeleton-define class nil 2123(python-skeleton-define class nil
2115 "Class name: " 2124 "Class name: "
2116 "class " str " (" ("Inheritance, %s: " 2125 "class " str " (" ("Inheritance, %s: "
2117 (unless (equal ?\( (char-before)) ", ") 2126 (unless (equal ?\( (char-before)) ", ")
2118 str) 2127 str)
2119 & ")" | -2 2128 & ")" | -2
2120 ":" \n 2129 ":" \n
2121 "\"\"\"" - "\"\"\"" \n 2130 "\"\"\"" - "\"\"\"" \n
@@ -2166,7 +2175,7 @@ The skeleton will be bound to python-skeleton-NAME."
2166 (python-shell-send-string-no-output 2175 (python-shell-send-string-no-output
2167 (format python-ffap-string-code module) process))) 2176 (format python-ffap-string-code module) process)))
2168 (when module-file 2177 (when module-file
2169 (substring-no-properties module-file 1 -1)))))) 2178 (substring-no-properties module-file 1 -1))))))
2170 2179
2171(eval-after-load "ffap" 2180(eval-after-load "ffap"
2172 '(progn 2181 '(progn
@@ -2197,8 +2206,8 @@ Runs COMMAND, a shell command, as if by `compile'. See
2197`python-check-command' for the default." 2206`python-check-command' for the default."
2198 (interactive 2207 (interactive
2199 (list (read-string "Check command: " 2208 (list (read-string "Check command: "
2200 (or python-check-custom-command 2209 (or python-check-custom-command
2201 (concat python-check-command " " 2210 (concat python-check-command " "
2202 (shell-quote-argument 2211 (shell-quote-argument
2203 (or 2212 (or
2204 (let ((name (buffer-file-name))) 2213 (let ((name (buffer-file-name)))
@@ -2272,20 +2281,24 @@ will be used. If not FORCE-PROCESS is passed what
2272 (current-word) 2281 (current-word)
2273 (concat current-defun "." (current-word)))))) 2282 (concat current-defun "." (current-word))))))
2274 (ppss (syntax-ppss)) 2283 (ppss (syntax-ppss))
2275 (help (when (and input 2284 (help (when (and
2276 (not (string= input (concat current-defun "."))) 2285 input
2277 (not (or (python-info-ppss-context 'string ppss) 2286 (not (string= input (concat current-defun ".")))
2278 (python-info-ppss-context 'comment ppss)))) 2287 (not (or (python-info-ppss-context 'string ppss)
2279 (when (string-match (concat 2288 (python-info-ppss-context 'comment ppss))))
2280 (regexp-quote (concat current-defun ".")) 2289 (when (string-match
2281 "self\\.") input) 2290 (concat
2291 (regexp-quote (concat current-defun "."))
2292 "self\\.") input)
2282 (with-temp-buffer 2293 (with-temp-buffer
2283 (insert input) 2294 (insert input)
2284 (goto-char (point-min)) 2295 (goto-char (point-min))
2285 (forward-word) 2296 (forward-word)
2286 (forward-char) 2297 (forward-char)
2287 (delete-region (point-marker) (search-forward "self.")) 2298 (delete-region
2288 (setq input (buffer-substring (point-min) (point-max))))) 2299 (point-marker) (search-forward "self."))
2300 (setq input (buffer-substring
2301 (point-min) (point-max)))))
2289 (python-shell-send-string-no-output 2302 (python-shell-send-string-no-output
2290 (format python-eldoc-string-code input) process)))) 2303 (format python-eldoc-string-code input) process))))
2291 (with-current-buffer (process-buffer process) 2304 (with-current-buffer (process-buffer process)
@@ -2306,18 +2319,18 @@ inferior python process is updated properly."
2306(defun python-eldoc-at-point (symbol) 2319(defun python-eldoc-at-point (symbol)
2307 "Get help on SYMBOL using `help'. 2320 "Get help on SYMBOL using `help'.
2308Interactively, prompt for symbol." 2321Interactively, prompt for symbol."
2309 (interactive 2322 (interactive
2310 (let ((symbol (with-syntax-table python-dotty-syntax-table 2323 (let ((symbol (with-syntax-table python-dotty-syntax-table
2311 (current-word))) 2324 (current-word)))
2312 (enable-recursive-minibuffers t)) 2325 (enable-recursive-minibuffers t))
2313 (list (read-string (if symbol 2326 (list (read-string (if symbol
2314 (format "Describe symbol (default %s): " symbol) 2327 (format "Describe symbol (default %s): " symbol)
2315 "Describe symbol: ") 2328 "Describe symbol: ")
2316 nil nil symbol)))) 2329 nil nil symbol))))
2317 (let ((process (python-shell-get-process))) 2330 (let ((process (python-shell-get-process)))
2318 (if (not process) 2331 (if (not process)
2319 (message "Eldoc needs an inferior Python process running.") 2332 (message "Eldoc needs an inferior Python process running.")
2320 (message (python-eldoc--get-doc-at-point symbol process))))) 2333 (message (python-eldoc--get-doc-at-point symbol process)))))
2321 2334
2322 2335
2323;;; Imenu 2336;;; Imenu
@@ -2496,15 +2509,15 @@ not inside a defun."
2496 (point-marker)))))))) 2509 (point-marker))))))))
2497 2510
2498(defun python-info-line-ends-backslash-p (&optional line-number) 2511(defun python-info-line-ends-backslash-p (&optional line-number)
2499 "Return non-nil if current line ends with backslash. 2512 "Return non-nil if current line ends with backslash.
2500With optional argument LINE-NUMBER, check that line instead." 2513With optional argument LINE-NUMBER, check that line instead."
2501 (save-excursion 2514 (save-excursion
2502 (save-restriction 2515 (save-restriction
2503 (when line-number 2516 (when line-number
2504 (goto-char line-number)) 2517 (goto-char line-number))
2505 (widen) 2518 (widen)
2506 (goto-char (line-end-position)) 2519 (goto-char (line-end-position))
2507 (equal (char-after (1- (point))) ?\\)))) 2520 (equal (char-after (1- (point))) ?\\))))
2508 2521
2509(defun python-info-continuation-line-p () 2522(defun python-info-continuation-line-p ()
2510 "Check if current line is continuation of another. 2523 "Check if current line is continuation of another.
@@ -2622,8 +2635,8 @@ to \"^python-\"."
2622 (and (symbolp (car pair)) 2635 (and (symbolp (car pair))
2623 (string-match (or regexp "^python-") 2636 (string-match (or regexp "^python-")
2624 (symbol-name (car pair))) 2637 (symbol-name (car pair)))
2625 (set (make-local-variable (car pair)) 2638 (set (make-local-variable (car pair))
2626 (cdr pair)))) 2639 (cdr pair))))
2627 (buffer-local-variables from-buffer))) 2640 (buffer-local-variables from-buffer)))
2628 2641
2629(defun python-util-forward-comment (&optional direction) 2642(defun python-util-forward-comment (&optional direction)
@@ -2658,11 +2671,13 @@ if that value is non-nil."
2658 nil nil nil nil 2671 nil nil nil nil
2659 (font-lock-syntactic-keywords . python-font-lock-syntactic-keywords))) 2672 (font-lock-syntactic-keywords . python-font-lock-syntactic-keywords)))
2660 2673
2661 (set (make-local-variable 'indent-line-function) #'python-indent-line-function) 2674 (set (make-local-variable 'indent-line-function)
2675 #'python-indent-line-function)
2662 (set (make-local-variable 'indent-region-function) #'python-indent-region) 2676 (set (make-local-variable 'indent-region-function) #'python-indent-region)
2663 2677
2664 (set (make-local-variable 'paragraph-start) "\\s-*$") 2678 (set (make-local-variable 'paragraph-start) "\\s-*$")
2665 (set (make-local-variable 'fill-paragraph-function) 'python-fill-paragraph-function) 2679 (set (make-local-variable 'fill-paragraph-function)
2680 'python-fill-paragraph-function)
2666 2681
2667 (set (make-local-variable 'beginning-of-defun-function) 2682 (set (make-local-variable 'beginning-of-defun-function)
2668 #'python-beginning-of-defun-function) 2683 #'python-beginning-of-defun-function)
@@ -2680,14 +2695,14 @@ if that value is non-nil."
2680 (set (make-local-variable 'skeleton-further-elements) 2695 (set (make-local-variable 'skeleton-further-elements)
2681 '((abbrev-mode nil) 2696 '((abbrev-mode nil)
2682 (< '(backward-delete-char-untabify (min python-indent-offset 2697 (< '(backward-delete-char-untabify (min python-indent-offset
2683 (current-column)))) 2698 (current-column))))
2684 (^ '(- (1+ (current-indentation)))))) 2699 (^ '(- (1+ (current-indentation))))))
2685 2700
2686 (set (make-local-variable 'eldoc-documentation-function) 2701 (set (make-local-variable 'eldoc-documentation-function)
2687 #'python-eldoc-function) 2702 #'python-eldoc-function)
2688 2703
2689 (add-to-list 'hs-special-modes-alist 2704 (add-to-list 'hs-special-modes-alist
2690 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#" 2705 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#"
2691 ,(lambda (arg) 2706 ,(lambda (arg)
2692 (python-end-of-defun-function)) nil)) 2707 (python-end-of-defun-function)) nil))
2693 2708