diff options
| author | Fabián Ezequiel Gallina | 2012-08-07 23:30:08 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-08-07 23:30:08 -0300 |
| commit | 2d79ec42a2955c3c9ecce804576c624d75e08e19 (patch) | |
| tree | 582df22a1f7d8afb17ae4c61159c3b161097d9aa /lisp/progmodes/python.el | |
| parent | 2bd255dd8f047650e4c4441061b25532d6290289 (diff) | |
| download | emacs-2d79ec42a2955c3c9ecce804576c624d75e08e19.tar.gz emacs-2d79ec42a2955c3c9ecce804576c624d75e08e19.zip | |
* progmodes/python.el Fixed defsubst warning.
(python-syntax-context) Rename from python-info-ppss-context.
(python-syntax-context-type): Rename from
python-info-ppss-context-type.
(python-syntax-comment-or-string-p): Rename from
python-info-ppss-comment-or-string-p.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 152 |
1 files changed, 79 insertions, 73 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 01c17a70f98..58d984f8d4d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -353,6 +353,40 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 353 | 353 | ||
| 354 | 354 | ||
| 355 | ;;; Font-lock and syntax | 355 | ;;; Font-lock and syntax |
| 356 | |||
| 357 | (defun python-syntax-context (type &optional syntax-ppss) | ||
| 358 | "Return non-nil if point is on TYPE using SYNTAX-PPSS. | ||
| 359 | TYPE can be `comment', `string' or `paren'. It returns the start | ||
| 360 | character address of the specified TYPE." | ||
| 361 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 362 | (case type | ||
| 363 | (comment (and (nth 4 ppss) (nth 8 ppss))) | ||
| 364 | (string (and (not (nth 4 ppss)) (nth 8 ppss))) | ||
| 365 | (paren (nth 1 ppss)) | ||
| 366 | (t nil)))) | ||
| 367 | |||
| 368 | (defun python-syntax-context-type (&optional syntax-ppss) | ||
| 369 | "Return the context type using SYNTAX-PPSS. | ||
| 370 | The type returned can be `comment', `string' or `paren'." | ||
| 371 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 372 | (cond | ||
| 373 | ((nth 8 ppss) (if (nth 4 ppss) 'comment 'string)) | ||
| 374 | ((nth 1 ppss) 'paren)))) | ||
| 375 | |||
| 376 | (defsubst python-syntax-comment-or-string-p () | ||
| 377 | "Return non-nil if point is inside 'comment or 'string." | ||
| 378 | (nth 8 (syntax-ppss))) | ||
| 379 | |||
| 380 | (define-obsolete-function-alias | ||
| 381 | 'python-info-ppss-context #'python-syntax-context "24.2") | ||
| 382 | |||
| 383 | (define-obsolete-function-alias | ||
| 384 | 'python-info-ppss-context-type #'python-syntax-context-type "24.2") | ||
| 385 | |||
| 386 | (define-obsolete-function-alias | ||
| 387 | 'python-info-ppss-comment-or-string-p | ||
| 388 | #'python-syntax-comment-or-string-p "24.2") | ||
| 389 | |||
| 356 | (defvar python-font-lock-keywords | 390 | (defvar python-font-lock-keywords |
| 357 | ;; Keywords | 391 | ;; Keywords |
| 358 | `(,(rx symbol-start | 392 | `(,(rx symbol-start |
| @@ -439,9 +473,9 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 439 | (? ?\[ (+ (not (any ?\]))) ?\]) (* space) | 473 | (? ?\[ (+ (not (any ?\]))) ?\]) (* space) |
| 440 | assignment-operator))) | 474 | assignment-operator))) |
| 441 | (when (re-search-forward re limit t) | 475 | (when (re-search-forward re limit t) |
| 442 | (while (and (python-info-ppss-context 'paren) | 476 | (while (and (python-syntax-context 'paren) |
| 443 | (re-search-forward re limit t))) | 477 | (re-search-forward re limit t))) |
| 444 | (if (and (not (python-info-ppss-context 'paren)) | 478 | (if (and (not (python-syntax-context 'paren)) |
| 445 | (not (equal (char-after (point-marker)) ?=))) | 479 | (not (equal (char-after (point-marker)) ?=))) |
| 446 | t | 480 | t |
| 447 | (set-match-data nil))))) | 481 | (set-match-data nil))))) |
| @@ -454,10 +488,10 @@ This variant of `rx' supports common python named REGEXPS." | |||
| 454 | assignment-operator))) | 488 | assignment-operator))) |
| 455 | (when (and (re-search-forward re limit t) | 489 | (when (and (re-search-forward re limit t) |
| 456 | (goto-char (nth 3 (match-data)))) | 490 | (goto-char (nth 3 (match-data)))) |
| 457 | (while (and (python-info-ppss-context 'paren) | 491 | (while (and (python-syntax-context 'paren) |
| 458 | (re-search-forward re limit t)) | 492 | (re-search-forward re limit t)) |
| 459 | (goto-char (nth 3 (match-data)))) | 493 | (goto-char (nth 3 (match-data)))) |
| 460 | (if (not (python-info-ppss-context 'paren)) | 494 | (if (not (python-syntax-context 'paren)) |
| 461 | t | 495 | t |
| 462 | (set-match-data nil))))) | 496 | (set-match-data nil))))) |
| 463 | (1 font-lock-variable-name-face nil nil)))) | 497 | (1 font-lock-variable-name-face nil nil)))) |
| @@ -582,7 +616,7 @@ These make `python-indent-calculate-indentation' subtract the value of | |||
| 582 | (re-search-forward | 616 | (re-search-forward |
| 583 | (python-rx line-start block-start) nil t)) | 617 | (python-rx line-start block-start) nil t)) |
| 584 | (when (and | 618 | (when (and |
| 585 | (not (python-info-ppss-context-type)) | 619 | (not (python-syntax-context-type)) |
| 586 | (progn | 620 | (progn |
| 587 | (goto-char (line-end-position)) | 621 | (goto-char (line-end-position)) |
| 588 | (python-util-forward-comment -1) | 622 | (python-util-forward-comment -1) |
| @@ -632,14 +666,14 @@ START is the buffer position where the sexp starts." | |||
| 632 | (bobp)) | 666 | (bobp)) |
| 633 | 'no-indent) | 667 | 'no-indent) |
| 634 | ;; Inside a paren | 668 | ;; Inside a paren |
| 635 | ((setq start (python-info-ppss-context 'paren ppss)) | 669 | ((setq start (python-syntax-context 'paren ppss)) |
| 636 | 'inside-paren) | 670 | 'inside-paren) |
| 637 | ;; Inside string | 671 | ;; Inside string |
| 638 | ((setq start (python-info-ppss-context 'string ppss)) | 672 | ((setq start (python-syntax-context 'string ppss)) |
| 639 | 'inside-string) | 673 | 'inside-string) |
| 640 | ;; After backslash | 674 | ;; After backslash |
| 641 | ((setq start (when (not (or (python-info-ppss-context 'string ppss) | 675 | ((setq start (when (not (or (python-syntax-context 'string ppss) |
| 642 | (python-info-ppss-context 'comment ppss))) | 676 | (python-syntax-context 'comment ppss))) |
| 643 | (let ((line-beg-pos (line-beginning-position))) | 677 | (let ((line-beg-pos (line-beginning-position))) |
| 644 | (when (python-info-line-ends-backslash-p | 678 | (when (python-info-line-ends-backslash-p |
| 645 | (1- line-beg-pos)) | 679 | (1- line-beg-pos)) |
| @@ -657,7 +691,7 @@ START is the buffer position where the sexp starts." | |||
| 657 | (while (and (re-search-backward | 691 | (while (and (re-search-backward |
| 658 | (python-rx block-start) nil t) | 692 | (python-rx block-start) nil t) |
| 659 | (or | 693 | (or |
| 660 | (python-info-ppss-context-type) | 694 | (python-syntax-context-type) |
| 661 | (python-info-continuation-line-p)))) | 695 | (python-info-continuation-line-p)))) |
| 662 | (when (looking-at (python-rx block-start)) | 696 | (when (looking-at (python-rx block-start)) |
| 663 | (point-marker))))) | 697 | (point-marker))))) |
| @@ -721,13 +755,13 @@ START is the buffer position where the sexp starts." | |||
| 721 | (while (prog2 | 755 | (while (prog2 |
| 722 | (forward-line -1) | 756 | (forward-line -1) |
| 723 | (and (not (bobp)) | 757 | (and (not (bobp)) |
| 724 | (python-info-ppss-context 'paren)))) | 758 | (python-syntax-context 'paren)))) |
| 725 | (goto-char (line-end-position)) | 759 | (goto-char (line-end-position)) |
| 726 | (while (and (re-search-backward | 760 | (while (and (re-search-backward |
| 727 | "\\." (line-beginning-position) t) | 761 | "\\." (line-beginning-position) t) |
| 728 | (python-info-ppss-context-type))) | 762 | (python-syntax-context-type))) |
| 729 | (if (and (looking-at "\\.") | 763 | (if (and (looking-at "\\.") |
| 730 | (not (python-info-ppss-context-type))) | 764 | (not (python-syntax-context-type))) |
| 731 | ;; The indentation is the same column of the | 765 | ;; The indentation is the same column of the |
| 732 | ;; first matching dot that's not inside a | 766 | ;; first matching dot that's not inside a |
| 733 | ;; comment, a string or a paren | 767 | ;; comment, a string or a paren |
| @@ -783,7 +817,7 @@ START is the buffer position where the sexp starts." | |||
| 783 | (when (and (looking-at (regexp-opt '(")" "]" "}"))) | 817 | (when (and (looking-at (regexp-opt '(")" "]" "}"))) |
| 784 | (progn | 818 | (progn |
| 785 | (forward-char 1) | 819 | (forward-char 1) |
| 786 | (not (python-info-ppss-context 'paren)))) | 820 | (not (python-syntax-context 'paren)))) |
| 787 | (goto-char context-start) | 821 | (goto-char context-start) |
| 788 | (current-indentation)))) | 822 | (current-indentation)))) |
| 789 | ;; If open paren is contained on a line by itself add another | 823 | ;; If open paren is contained on a line by itself add another |
| @@ -883,7 +917,7 @@ See `python-indent-line' for details." | |||
| 883 | (defun python-indent-dedent-line () | 917 | (defun python-indent-dedent-line () |
| 884 | "De-indent current line." | 918 | "De-indent current line." |
| 885 | (interactive "*") | 919 | (interactive "*") |
| 886 | (when (and (not (python-info-ppss-comment-or-string-p)) | 920 | (when (and (not (python-syntax-comment-or-string-p)) |
| 887 | (<= (point-marker) (save-excursion | 921 | (<= (point-marker) (save-excursion |
| 888 | (back-to-indentation) | 922 | (back-to-indentation) |
| 889 | (point-marker))) | 923 | (point-marker))) |
| @@ -974,7 +1008,7 @@ With numeric ARG, just insert that many colons. With | |||
| 974 | (when (and (not arg) | 1008 | (when (and (not arg) |
| 975 | (eolp) | 1009 | (eolp) |
| 976 | (not (equal ?: (char-after (- (point-marker) 2)))) | 1010 | (not (equal ?: (char-after (- (point-marker) 2)))) |
| 977 | (not (python-info-ppss-comment-or-string-p))) | 1011 | (not (python-syntax-comment-or-string-p))) |
| 978 | (let ((indentation (current-indentation)) | 1012 | (let ((indentation (current-indentation)) |
| 979 | (calculated-indentation (python-indent-calculate-indentation))) | 1013 | (calculated-indentation (python-indent-calculate-indentation))) |
| 980 | (python-info-closing-block-message) | 1014 | (python-info-closing-block-message) |
| @@ -998,7 +1032,7 @@ automatically if needed." | |||
| 998 | (goto-char (line-beginning-position)) | 1032 | (goto-char (line-beginning-position)) |
| 999 | ;; If after going to the beginning of line the point | 1033 | ;; If after going to the beginning of line the point |
| 1000 | ;; is still inside a paren it's ok to do the trick | 1034 | ;; is still inside a paren it's ok to do the trick |
| 1001 | (when (python-info-ppss-context 'paren) | 1035 | (when (python-syntax-context 'paren) |
| 1002 | (let ((indentation (python-indent-calculate-indentation))) | 1036 | (let ((indentation (python-indent-calculate-indentation))) |
| 1003 | (when (< (current-indentation) indentation) | 1037 | (when (< (current-indentation) indentation) |
| 1004 | (indent-line-to indentation))))))) | 1038 | (indent-line-to indentation))))))) |
| @@ -1032,7 +1066,7 @@ non-nil if point is moved to `beginning-of-defun'." | |||
| 1032 | (end-of-line 1)) | 1066 | (end-of-line 1)) |
| 1033 | (while (and (funcall re-search-fn | 1067 | (while (and (funcall re-search-fn |
| 1034 | python-nav-beginning-of-defun-regexp nil t) | 1068 | python-nav-beginning-of-defun-regexp nil t) |
| 1035 | (python-info-ppss-context-type))) | 1069 | (python-syntax-context-type))) |
| 1036 | (and (python-info-looking-at-beginning-of-defun) | 1070 | (and (python-info-looking-at-beginning-of-defun) |
| 1037 | (or (not (= (line-number-at-pos pos) | 1071 | (or (not (= (line-number-at-pos pos) |
| 1038 | (line-number-at-pos))) | 1072 | (line-number-at-pos))) |
| @@ -1082,15 +1116,15 @@ Returns nil if point is not in a def or class." | |||
| 1082 | (equal (char-after (+ (point) (current-indentation))) ?#) | 1116 | (equal (char-after (+ (point) (current-indentation))) ?#) |
| 1083 | (<= (current-indentation) beg-defun-indent) | 1117 | (<= (current-indentation) beg-defun-indent) |
| 1084 | (looking-at (python-rx decorator)) | 1118 | (looking-at (python-rx decorator)) |
| 1085 | (python-info-ppss-context-type)))) | 1119 | (python-syntax-context-type)))) |
| 1086 | (forward-line 1) | 1120 | (forward-line 1) |
| 1087 | ;; If point falls inside a paren or string context the point is | 1121 | ;; If point falls inside a paren or string context the point is |
| 1088 | ;; forwarded at the end of it (or end of buffer if its not closed) | 1122 | ;; forwarded at the end of it (or end of buffer if its not closed) |
| 1089 | (let ((context-type (python-info-ppss-context-type))) | 1123 | (let ((context-type (python-syntax-context-type))) |
| 1090 | (when (memq context-type '(paren string)) | 1124 | (when (memq context-type '(paren string)) |
| 1091 | ;; Slow but safe. | 1125 | ;; Slow but safe. |
| 1092 | (while (and (not (eobp)) | 1126 | (while (and (not (eobp)) |
| 1093 | (python-info-ppss-context-type)) | 1127 | (python-syntax-context-type)) |
| 1094 | (forward-line 1))))))) | 1128 | (forward-line 1))))))) |
| 1095 | 1129 | ||
| 1096 | (defun python-nav-beginning-of-statement () | 1130 | (defun python-nav-beginning-of-statement () |
| @@ -1102,8 +1136,8 @@ Returns nil if point is not in a def or class." | |||
| 1102 | (save-excursion | 1136 | (save-excursion |
| 1103 | (forward-line -1) | 1137 | (forward-line -1) |
| 1104 | (python-info-line-ends-backslash-p)) | 1138 | (python-info-line-ends-backslash-p)) |
| 1105 | (python-info-ppss-context 'string) | 1139 | (python-syntax-context 'string) |
| 1106 | (python-info-ppss-context 'paren)) | 1140 | (python-syntax-context 'paren)) |
| 1107 | (forward-line -1))))) | 1141 | (forward-line -1))))) |
| 1108 | 1142 | ||
| 1109 | (defun python-nav-end-of-statement () | 1143 | (defun python-nav-end-of-statement () |
| @@ -1113,8 +1147,8 @@ Returns nil if point is not in a def or class." | |||
| 1113 | (not (eobp)) | 1147 | (not (eobp)) |
| 1114 | (when (or | 1148 | (when (or |
| 1115 | (python-info-line-ends-backslash-p) | 1149 | (python-info-line-ends-backslash-p) |
| 1116 | (python-info-ppss-context 'string) | 1150 | (python-syntax-context 'string) |
| 1117 | (python-info-ppss-context 'paren)) | 1151 | (python-syntax-context 'paren)) |
| 1118 | (forward-line 1))))) | 1152 | (forward-line 1))))) |
| 1119 | 1153 | ||
| 1120 | (defun python-nav-backward-statement (&optional arg) | 1154 | (defun python-nav-backward-statement (&optional arg) |
| @@ -1202,13 +1236,13 @@ backward to previous block." | |||
| 1202 | (python-nav-end-of-statement) | 1236 | (python-nav-end-of-statement) |
| 1203 | (while (and | 1237 | (while (and |
| 1204 | (re-search-forward block-start-regexp nil t) | 1238 | (re-search-forward block-start-regexp nil t) |
| 1205 | (python-info-ppss-context-type))) | 1239 | (python-syntax-context-type))) |
| 1206 | (setq arg (1- arg))) | 1240 | (setq arg (1- arg))) |
| 1207 | (while (< arg 0) | 1241 | (while (< arg 0) |
| 1208 | (python-nav-beginning-of-statement) | 1242 | (python-nav-beginning-of-statement) |
| 1209 | (while (and | 1243 | (while (and |
| 1210 | (re-search-backward block-start-regexp nil t) | 1244 | (re-search-backward block-start-regexp nil t) |
| 1211 | (python-info-ppss-context-type))) | 1245 | (python-syntax-context-type))) |
| 1212 | (setq arg (1+ arg))) | 1246 | (setq arg (1+ arg))) |
| 1213 | (python-nav-beginning-of-statement) | 1247 | (python-nav-beginning-of-statement) |
| 1214 | (if (not (looking-at (python-rx block-start))) | 1248 | (if (not (looking-at (python-rx block-start))) |
| @@ -1920,7 +1954,7 @@ completions on the current context." | |||
| 1920 | (while (or | 1954 | (while (or |
| 1921 | ;; honor initial paren depth | 1955 | ;; honor initial paren depth |
| 1922 | (> (car (syntax-ppss)) paren-depth) | 1956 | (> (car (syntax-ppss)) paren-depth) |
| 1923 | (python-info-ppss-context 'string)) | 1957 | (python-syntax-context 'string)) |
| 1924 | (forward-char -1)))) | 1958 | (forward-char -1)))) |
| 1925 | (point))) | 1959 | (point))) |
| 1926 | (end (point)) | 1960 | (end (point)) |
| @@ -2140,7 +2174,7 @@ Optional argument JUSTIFY defines if the paragraph should be justified." | |||
| 2140 | ((funcall python-fill-comment-function justify)) | 2174 | ((funcall python-fill-comment-function justify)) |
| 2141 | ;; Strings/Docstrings | 2175 | ;; Strings/Docstrings |
| 2142 | ((save-excursion (skip-chars-forward "\"'uUrR") | 2176 | ((save-excursion (skip-chars-forward "\"'uUrR") |
| 2143 | (python-info-ppss-context 'string)) | 2177 | (python-syntax-context 'string)) |
| 2144 | (funcall python-fill-string-function justify)) | 2178 | (funcall python-fill-string-function justify)) |
| 2145 | ;; Decorators | 2179 | ;; Decorators |
| 2146 | ((equal (char-after (save-excursion | 2180 | ((equal (char-after (save-excursion |
| @@ -2148,7 +2182,7 @@ Optional argument JUSTIFY defines if the paragraph should be justified." | |||
| 2148 | (point-marker))) ?@) | 2182 | (point-marker))) ?@) |
| 2149 | (funcall python-fill-decorator-function justify)) | 2183 | (funcall python-fill-decorator-function justify)) |
| 2150 | ;; Parens | 2184 | ;; Parens |
| 2151 | ((or (python-info-ppss-context 'paren) | 2185 | ((or (python-syntax-context 'paren) |
| 2152 | (looking-at (python-rx open-paren)) | 2186 | (looking-at (python-rx open-paren)) |
| 2153 | (save-excursion | 2187 | (save-excursion |
| 2154 | (skip-syntax-forward "^(" (line-end-position)) | 2188 | (skip-syntax-forward "^(" (line-end-position)) |
| @@ -2168,13 +2202,13 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2168 | (string-start-marker | 2202 | (string-start-marker |
| 2169 | (progn | 2203 | (progn |
| 2170 | (skip-chars-forward "\"'uUrR") | 2204 | (skip-chars-forward "\"'uUrR") |
| 2171 | (goto-char (python-info-ppss-context 'string)) | 2205 | (goto-char (python-syntax-context 'string)) |
| 2172 | (skip-chars-forward "\"'uUrR") | 2206 | (skip-chars-forward "\"'uUrR") |
| 2173 | (point-marker))) | 2207 | (point-marker))) |
| 2174 | (reg-start (line-beginning-position)) | 2208 | (reg-start (line-beginning-position)) |
| 2175 | (string-end-marker | 2209 | (string-end-marker |
| 2176 | (progn | 2210 | (progn |
| 2177 | (while (python-info-ppss-context 'string) | 2211 | (while (python-syntax-context 'string) |
| 2178 | (goto-char (1+ (point-marker)))) | 2212 | (goto-char (1+ (point-marker)))) |
| 2179 | (skip-chars-backward "\"'") | 2213 | (skip-chars-backward "\"'") |
| 2180 | (point-marker))) | 2214 | (point-marker))) |
| @@ -2212,16 +2246,16 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'." | |||
| 2212 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." | 2246 | JUSTIFY should be used (if applicable) as in `fill-paragraph'." |
| 2213 | (save-restriction | 2247 | (save-restriction |
| 2214 | (narrow-to-region (progn | 2248 | (narrow-to-region (progn |
| 2215 | (while (python-info-ppss-context 'paren) | 2249 | (while (python-syntax-context 'paren) |
| 2216 | (goto-char (1- (point-marker)))) | 2250 | (goto-char (1- (point-marker)))) |
| 2217 | (point-marker) | 2251 | (point-marker) |
| 2218 | (line-beginning-position)) | 2252 | (line-beginning-position)) |
| 2219 | (progn | 2253 | (progn |
| 2220 | (when (not (python-info-ppss-context 'paren)) | 2254 | (when (not (python-syntax-context 'paren)) |
| 2221 | (end-of-line) | 2255 | (end-of-line) |
| 2222 | (when (not (python-info-ppss-context 'paren)) | 2256 | (when (not (python-syntax-context 'paren)) |
| 2223 | (skip-syntax-backward "^)"))) | 2257 | (skip-syntax-backward "^)"))) |
| 2224 | (while (python-info-ppss-context 'paren) | 2258 | (while (python-syntax-context 'paren) |
| 2225 | (goto-char (1+ (point-marker)))) | 2259 | (goto-char (1+ (point-marker)))) |
| 2226 | (point-marker))) | 2260 | (point-marker))) |
| 2227 | (let ((paragraph-start "\f\\|[ \t]*$") | 2261 | (let ((paragraph-start "\f\\|[ \t]*$") |
| @@ -2259,7 +2293,7 @@ the if condition." | |||
| 2259 | ;; Only expand in code. | 2293 | ;; Only expand in code. |
| 2260 | :enable-function (lambda () | 2294 | :enable-function (lambda () |
| 2261 | (and | 2295 | (and |
| 2262 | (not (python-info-ppss-comment-or-string-p)) | 2296 | (not (python-syntax-comment-or-string-p)) |
| 2263 | python-skeleton-autoinsert))) | 2297 | python-skeleton-autoinsert))) |
| 2264 | 2298 | ||
| 2265 | (defmacro python-skeleton-define (name doc &rest skel) | 2299 | (defmacro python-skeleton-define (name doc &rest skel) |
| @@ -2579,7 +2613,7 @@ not inside a defun." | |||
| 2579 | With optional argument REPLACE-SELF convert \"self\" to current | 2613 | With optional argument REPLACE-SELF convert \"self\" to current |
| 2580 | parent defun name." | 2614 | parent defun name." |
| 2581 | (let ((name | 2615 | (let ((name |
| 2582 | (and (not (python-info-ppss-comment-or-string-p)) | 2616 | (and (not (python-syntax-comment-or-string-p)) |
| 2583 | (with-syntax-table python-dotty-syntax-table | 2617 | (with-syntax-table python-dotty-syntax-table |
| 2584 | (let ((sym (symbol-at-point))) | 2618 | (let ((sym (symbol-at-point))) |
| 2585 | (and sym | 2619 | (and sym |
| @@ -2657,7 +2691,7 @@ With optional argument LINE-NUMBER, check that line instead." | |||
| 2657 | (goto-char line-number)) | 2691 | (goto-char line-number)) |
| 2658 | (while (and (not (eobp)) | 2692 | (while (and (not (eobp)) |
| 2659 | (goto-char (line-end-position)) | 2693 | (goto-char (line-end-position)) |
| 2660 | (python-info-ppss-context 'paren) | 2694 | (python-syntax-context 'paren) |
| 2661 | (not (equal (char-before (point)) ?\\))) | 2695 | (not (equal (char-before (point)) ?\\))) |
| 2662 | (forward-line 1)) | 2696 | (forward-line 1)) |
| 2663 | (when (equal (char-before) ?\\) | 2697 | (when (equal (char-before) ?\\) |
| @@ -2674,7 +2708,7 @@ Optional argument LINE-NUMBER forces the line number to check against." | |||
| 2674 | (when (python-info-line-ends-backslash-p) | 2708 | (when (python-info-line-ends-backslash-p) |
| 2675 | (while (save-excursion | 2709 | (while (save-excursion |
| 2676 | (goto-char (line-beginning-position)) | 2710 | (goto-char (line-beginning-position)) |
| 2677 | (python-info-ppss-context 'paren)) | 2711 | (python-syntax-context 'paren)) |
| 2678 | (forward-line -1)) | 2712 | (forward-line -1)) |
| 2679 | (back-to-indentation) | 2713 | (back-to-indentation) |
| 2680 | (point-marker))))) | 2714 | (point-marker))))) |
| @@ -2688,10 +2722,10 @@ where the continued line ends." | |||
| 2688 | (widen) | 2722 | (widen) |
| 2689 | (let* ((context-type (progn | 2723 | (let* ((context-type (progn |
| 2690 | (back-to-indentation) | 2724 | (back-to-indentation) |
| 2691 | (python-info-ppss-context-type))) | 2725 | (python-syntax-context-type))) |
| 2692 | (line-start (line-number-at-pos)) | 2726 | (line-start (line-number-at-pos)) |
| 2693 | (context-start (when context-type | 2727 | (context-start (when context-type |
| 2694 | (python-info-ppss-context context-type)))) | 2728 | (python-syntax-context context-type)))) |
| 2695 | (cond ((equal context-type 'paren) | 2729 | (cond ((equal context-type 'paren) |
| 2696 | ;; Lines inside a paren are always a continuation line | 2730 | ;; Lines inside a paren are always a continuation line |
| 2697 | ;; (except the first one). | 2731 | ;; (except the first one). |
| @@ -2736,41 +2770,13 @@ operator." | |||
| 2736 | assignment-operator | 2770 | assignment-operator |
| 2737 | not-simple-operator) | 2771 | not-simple-operator) |
| 2738 | (line-end-position) t) | 2772 | (line-end-position) t) |
| 2739 | (not (python-info-ppss-context-type)))) | 2773 | (not (python-syntax-context-type)))) |
| 2740 | (skip-syntax-forward "\s") | 2774 | (skip-syntax-forward "\s") |
| 2741 | (point-marker))))) | 2775 | (point-marker))))) |
| 2742 | 2776 | ||
| 2743 | (defun python-info-ppss-context (type &optional syntax-ppss) | ||
| 2744 | "Return non-nil if point is on TYPE using SYNTAX-PPSS. | ||
| 2745 | TYPE can be `comment', `string' or `paren'. It returns the start | ||
| 2746 | character address of the specified TYPE." | ||
| 2747 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 2748 | (case type | ||
| 2749 | (comment | ||
| 2750 | (and (nth 4 ppss) | ||
| 2751 | (nth 8 ppss))) | ||
| 2752 | (string | ||
| 2753 | (and (not (nth 4 ppss)) | ||
| 2754 | (nth 8 ppss))) | ||
| 2755 | (paren | ||
| 2756 | (nth 1 ppss)) | ||
| 2757 | (t nil)))) | ||
| 2758 | |||
| 2759 | (defun python-info-ppss-context-type (&optional syntax-ppss) | ||
| 2760 | "Return the context type using SYNTAX-PPSS. | ||
| 2761 | The type returned can be `comment', `string' or `paren'." | ||
| 2762 | (let ((ppss (or syntax-ppss (syntax-ppss)))) | ||
| 2763 | (cond | ||
| 2764 | ((nth 8 ppss) (if (nth 4 ppss) 'comment 'string)) | ||
| 2765 | ((nth 1 ppss) 'paren)))) | ||
| 2766 | |||
| 2767 | (defsubst python-info-ppss-comment-or-string-p () | ||
| 2768 | "Return non-nil if point is inside 'comment or 'string." | ||
| 2769 | (nth 8 (syntax-ppss))) | ||
| 2770 | |||
| 2771 | (defun python-info-looking-at-beginning-of-defun (&optional syntax-ppss) | 2777 | (defun python-info-looking-at-beginning-of-defun (&optional syntax-ppss) |
| 2772 | "Check if point is at `beginning-of-defun' using SYNTAX-PPSS." | 2778 | "Check if point is at `beginning-of-defun' using SYNTAX-PPSS." |
| 2773 | (and (not (python-info-ppss-context-type (or syntax-ppss (syntax-ppss)))) | 2779 | (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss)))) |
| 2774 | (save-excursion | 2780 | (save-excursion |
| 2775 | (beginning-of-line 1) | 2781 | (beginning-of-line 1) |
| 2776 | (looking-at python-nav-beginning-of-defun-regexp)))) | 2782 | (looking-at python-nav-beginning-of-defun-regexp)))) |
| @@ -2816,7 +2822,7 @@ to \"^python-\"." | |||
| 2816 | (defun python-util-forward-comment (&optional direction) | 2822 | (defun python-util-forward-comment (&optional direction) |
| 2817 | "Python mode specific version of `forward-comment'. | 2823 | "Python mode specific version of `forward-comment'. |
| 2818 | Optional argument DIRECTION defines the direction to move to." | 2824 | Optional argument DIRECTION defines the direction to move to." |
| 2819 | (let ((comment-start (python-info-ppss-context 'comment)) | 2825 | (let ((comment-start (python-syntax-context 'comment)) |
| 2820 | (factor (if (< (or direction 0) 0) | 2826 | (factor (if (< (or direction 0) 0) |
| 2821 | -99999 | 2827 | -99999 |
| 2822 | 99999))) | 2828 | 99999))) |