diff options
| author | Stefan Monnier | 2014-04-10 21:05:03 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-04-10 21:05:03 -0400 |
| commit | 0d6a1375afcf2204f465d12ba5dc903cd0a9eb2e (patch) | |
| tree | bdb8bd9d3c28f3f7d2020eed72776fc4b8b9eb1e | |
| parent | fb2dcc3567ca762f05b452bb9edd27da33322f70 (diff) | |
| download | emacs-0d6a1375afcf2204f465d12ba5dc903cd0a9eb2e.tar.gz emacs-0d6a1375afcf2204f465d12ba5dc903cd0a9eb2e.zip | |
* lisp/newcomment.el (comment-indent-new-line): Sink code where it's used.
Reuse the previous comment's indentation unconditionally if it's on its
own line.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/newcomment.el | 57 |
2 files changed, 41 insertions, 22 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bab1edaffda..e5761ced42b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-04-11 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * newcomment.el (comment-indent-new-line): Sink code where it's used. | ||
| 4 | Reuse the previous comment's indentation unconditionally if it's on its | ||
| 5 | own line. | ||
| 6 | |||
| 1 | 2014-04-09 Daniel Colascione <dancol@dancol.org> | 7 | 2014-04-09 Daniel Colascione <dancol@dancol.org> |
| 2 | 8 | ||
| 3 | * emacs-lisp/lisp.el (backward-up-list): Add `escape-strings', | 9 | * emacs-lisp/lisp.el (backward-up-list): Add `escape-strings', |
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 2d798494b8b..b607eb95df2 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -1390,22 +1390,12 @@ unless optional argument SOFT is non-nil." | |||
| 1390 | ;; If we're not inside a comment, just try to indent. | 1390 | ;; If we're not inside a comment, just try to indent. |
| 1391 | ((not compos) (indent-according-to-mode)) | 1391 | ((not compos) (indent-according-to-mode)) |
| 1392 | (t | 1392 | (t |
| 1393 | (let* ((comment-column | 1393 | (let* ((comstart (buffer-substring compos comin)) |
| 1394 | ;; The continuation indentation should be somewhere between | ||
| 1395 | ;; the current line's indentation (plus 2 for good measure) | ||
| 1396 | ;; and the current comment's indentation, with a preference | ||
| 1397 | ;; for comment-column. | ||
| 1398 | (save-excursion | ||
| 1399 | ;; FIXME: use prev line's info rather than first line's. | ||
| 1400 | (goto-char compos) | ||
| 1401 | (min (current-column) (max comment-column | ||
| 1402 | (+ 2 (current-indentation)))))) | ||
| 1403 | (comstart (buffer-substring compos comin)) | ||
| 1404 | (normalp | 1394 | (normalp |
| 1405 | (string-match (regexp-quote (comment-string-strip | 1395 | (string-match (regexp-quote (comment-string-strip |
| 1406 | comment-start t t)) | 1396 | comment-start t t)) |
| 1407 | comstart)) | 1397 | comstart)) |
| 1408 | (comment-end | 1398 | (comend |
| 1409 | (if normalp comment-end | 1399 | (if normalp comment-end |
| 1410 | ;; The comment starter is not the normal comment-start | 1400 | ;; The comment starter is not the normal comment-start |
| 1411 | ;; so we can't just use comment-end. | 1401 | ;; so we can't just use comment-end. |
| @@ -1416,19 +1406,42 @@ unless optional argument SOFT is non-nil." | |||
| 1416 | (buffer-substring | 1406 | (buffer-substring |
| 1417 | (save-excursion (comment-enter-backward) (point)) | 1407 | (save-excursion (comment-enter-backward) (point)) |
| 1418 | (point)) | 1408 | (point)) |
| 1419 | nil t))))) | 1409 | nil t)))))) |
| 1420 | (comment-start comstart) | 1410 | (if (and comment-multi-line (> (length comend) 0)) |
| 1421 | (continuep (or comment-multi-line | ||
| 1422 | (cadr (assoc comment-style comment-styles)))) | ||
| 1423 | ;; Force comment-continue to be recreated from comment-start. | ||
| 1424 | ;; FIXME: wrong if comment-continue was set explicitly! | ||
| 1425 | ;; FIXME: use prev line's continuation if available. | ||
| 1426 | (comment-continue nil)) | ||
| 1427 | (if (and comment-multi-line (> (length comment-end) 0)) | ||
| 1428 | (indent-according-to-mode) | 1411 | (indent-according-to-mode) |
| 1429 | (insert-and-inherit ?\n) | 1412 | (insert-and-inherit ?\n) |
| 1430 | (forward-char -1) | 1413 | (forward-char -1) |
| 1431 | (comment-indent continuep) | 1414 | (let* ((comment-column |
| 1415 | ;; The continuation indentation should be somewhere | ||
| 1416 | ;; between the current line's indentation (plus 2 for | ||
| 1417 | ;; good measure) and the current comment's indentation, | ||
| 1418 | ;; with a preference for comment-column. | ||
| 1419 | (save-excursion | ||
| 1420 | ;; FIXME: use prev line's info rather than first | ||
| 1421 | ;; line's. | ||
| 1422 | (goto-char compos) | ||
| 1423 | (min (current-column) | ||
| 1424 | (max comment-column | ||
| 1425 | (+ 2 (current-indentation)))))) | ||
| 1426 | (comment-indent-function | ||
| 1427 | ;; If the previous comment is on its own line, then | ||
| 1428 | ;; reuse its indentation unconditionally. | ||
| 1429 | ;; Important for modes like Python/Haskell where | ||
| 1430 | ;; auto-indentation is unreliable. | ||
| 1431 | (if (save-excursion (goto-char compos) | ||
| 1432 | (skip-chars-backward " \t") | ||
| 1433 | (bolp)) | ||
| 1434 | (lambda () comment-column) comment-indent-function)) | ||
| 1435 | (comment-start comstart) | ||
| 1436 | (comment-end comend) | ||
| 1437 | (continuep (or comment-multi-line | ||
| 1438 | (cadr (assoc comment-style | ||
| 1439 | comment-styles)))) | ||
| 1440 | ;; Recreate comment-continue from comment-start. | ||
| 1441 | ;; FIXME: wrong if comment-continue was set explicitly! | ||
| 1442 | ;; FIXME: use prev line's continuation if available. | ||
| 1443 | (comment-continue nil)) | ||
| 1444 | (comment-indent continuep)) | ||
| 1432 | (save-excursion | 1445 | (save-excursion |
| 1433 | (let ((pt (point))) | 1446 | (let ((pt (point))) |
| 1434 | (end-of-line) | 1447 | (end-of-line) |