diff options
| author | Fabián Ezequiel Gallina | 2012-05-17 00:03:36 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-05-17 00:03:36 -0300 |
| commit | dc4f2e532630fa58381b9d3e52350279c98e89b7 (patch) | |
| tree | 7f181fffc0471c2e115fbe39ddb27147561b2261 | |
| parent | 479a14cc3a9a9a036f34f334d2bab8036932cf71 (diff) | |
| download | emacs-dc4f2e532630fa58381b9d3e52350279c98e89b7.tar.gz emacs-dc4f2e532630fa58381b9d3e52350279c98e89b7.zip | |
Enhancements on indentation for lines after a backslash continuation.
Backslashed continuations with parens in the middle are now handled
correctly. Things like this are now indented properly:
objects = Thing.objects.all() \
.filter(
type="toy",
status="bought"
subtype="car"
) \
.aggregate(
Sum('amount')
) \
.values_list()
New Functions:
* `python-info-beginning-of-backlash' returns the point where a
backslashed line start.
| -rw-r--r-- | lisp/progmodes/python.el | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5527d851d1d..ff790bdc25c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -701,7 +701,12 @@ START is the buffer position where the sexp starts." | |||
| 701 | ((save-excursion | 701 | ((save-excursion |
| 702 | (back-to-indentation) | 702 | (back-to-indentation) |
| 703 | (when (looking-at "\\.") | 703 | (when (looking-at "\\.") |
| 704 | (forward-line -1) | 704 | ;; If after moving one line back point is inside a paren it |
| 705 | ;; needs to move back until it's not anymore | ||
| 706 | (while (prog2 | ||
| 707 | (forward-line -1) | ||
| 708 | (and (not (bobp)) | ||
| 709 | (python-info-ppss-context 'paren)))) | ||
| 705 | (goto-char (line-end-position)) | 710 | (goto-char (line-end-position)) |
| 706 | (while (and (re-search-backward | 711 | (while (and (re-search-backward |
| 707 | "\\." (line-beginning-position) t) | 712 | "\\." (line-beginning-position) t) |
| @@ -742,10 +747,12 @@ START is the buffer position where the sexp starts." | |||
| 742 | (current-column)))) | 747 | (current-column)))) |
| 743 | (t | 748 | (t |
| 744 | (forward-line -1) | 749 | (forward-line -1) |
| 750 | (goto-char (python-info-beginning-of-backlash)) | ||
| 745 | (if (save-excursion | 751 | (if (save-excursion |
| 746 | (and | 752 | (and |
| 747 | (python-info-line-ends-backslash-p) | ||
| 748 | (forward-line -1) | 753 | (forward-line -1) |
| 754 | (goto-char | ||
| 755 | (or (python-info-beginning-of-backlash) (point))) | ||
| 749 | (python-info-line-ends-backslash-p))) | 756 | (python-info-line-ends-backslash-p))) |
| 750 | ;; The two previous lines ended in a backslash so we must | 757 | ;; The two previous lines ended in a backslash so we must |
| 751 | ;; respect previous line indentation. | 758 | ;; respect previous line indentation. |
| @@ -2535,11 +2542,31 @@ not inside a defun." | |||
| 2535 | With optional argument LINE-NUMBER, check that line instead." | 2542 | With optional argument LINE-NUMBER, check that line instead." |
| 2536 | (save-excursion | 2543 | (save-excursion |
| 2537 | (save-restriction | 2544 | (save-restriction |
| 2545 | (widen) | ||
| 2538 | (when line-number | 2546 | (when line-number |
| 2539 | (goto-char line-number)) | 2547 | (goto-char line-number)) |
| 2548 | (while (and (not (eobp)) | ||
| 2549 | (goto-char (line-end-position)) | ||
| 2550 | (python-info-ppss-context 'paren) | ||
| 2551 | (not (equal (char-before (point)) ?\\))) | ||
| 2552 | (forward-line 1)) | ||
| 2553 | (when (equal (char-before) ?\\) | ||
| 2554 | (point-marker))))) | ||
| 2555 | |||
| 2556 | (defun python-info-beginning-of-backlash (&optional line-number) | ||
| 2557 | "Return the point where the backlashed line starts." | ||
| 2558 | (save-excursion | ||
| 2559 | (save-restriction | ||
| 2540 | (widen) | 2560 | (widen) |
| 2541 | (goto-char (line-end-position)) | 2561 | (when line-number |
| 2542 | (equal (char-after (1- (point))) ?\\)))) | 2562 | (goto-char line-number)) |
| 2563 | (when (python-info-line-ends-backslash-p) | ||
| 2564 | (while (save-excursion | ||
| 2565 | (goto-char (line-beginning-position)) | ||
| 2566 | (python-info-ppss-context 'paren)) | ||
| 2567 | (forward-line -1)) | ||
| 2568 | (back-to-indentation) | ||
| 2569 | (point-marker))))) | ||
| 2543 | 2570 | ||
| 2544 | (defun python-info-continuation-line-p () | 2571 | (defun python-info-continuation-line-p () |
| 2545 | "Check if current line is continuation of another. | 2572 | "Check if current line is continuation of another. |