diff options
| author | Glenn Morris | 2007-11-02 08:10:40 +0000 |
|---|---|---|
| committer | Glenn Morris | 2007-11-02 08:10:40 +0000 |
| commit | b9b4d12c5fc07ba6cbc418b4679317c5eaaabf3b (patch) | |
| tree | 7f74079303418b4de788feba5a6ea5cbd8a2736d | |
| parent | 50865d784b5ef48a49d51bcef13f9f46c043ac3f (diff) | |
| download | emacs-b9b4d12c5fc07ba6cbc418b4679317c5eaaabf3b.tar.gz emacs-b9b4d12c5fc07ba6cbc418b4679317c5eaaabf3b.zip | |
(comment-indent): Let comment-insert-comment-function,
if defined, do all the work of inserting a new comment.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/newcomment.el | 77 |
2 files changed, 42 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e1a30beccd1..c4c6b1cb8a9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2007-11-02 Glenn Morris <rgm@gnu.org> | 1 | 2007-11-02 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * newcomment.el (comment-indent): Let comment-insert-comment-function, | ||
| 4 | if defined, do all the work of inserting a new comment. | ||
| 5 | |||
| 3 | * simple.el (bad-packages-alist): Revert previous change. | 6 | * simple.el (bad-packages-alist): Revert previous change. |
| 4 | 7 | ||
| 5 | 2007-11-02 Dan Nicolaescu <dann@ics.uci.edu> | 8 | 2007-11-02 Dan Nicolaescu <dann@ics.uci.edu> |
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 06dc7efbc99..dbc07f5bad0 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el | |||
| @@ -599,19 +599,20 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." | |||
| 599 | (let* ((eolpos (line-end-position)) | 599 | (let* ((eolpos (line-end-position)) |
| 600 | (begpos (comment-search-forward eolpos t)) | 600 | (begpos (comment-search-forward eolpos t)) |
| 601 | cpos indent) | 601 | cpos indent) |
| 602 | ;; An existing comment? | 602 | (if (and comment-insert-comment-function (not begpos)) |
| 603 | (if begpos | 603 | ;; If no comment and c-i-c-f is set, let it do everything. |
| 604 | (progn | 604 | (funcall comment-insert-comment-function) |
| 605 | (if (and (not (looking-at "[\t\n ]")) | 605 | ;; An existing comment? |
| 606 | (looking-at comment-end-skip)) | 606 | (if begpos |
| 607 | ;; The comment is empty and we have skipped all its space | 607 | (progn |
| 608 | ;; and landed right before the comment-ender: | 608 | (if (and (not (looking-at "[\t\n ]")) |
| 609 | ;; Go back to the middle of the space. | 609 | (looking-at comment-end-skip)) |
| 610 | (forward-char (/ (skip-chars-backward " \t") -2))) | 610 | ;; The comment is empty and we have skipped all its space |
| 611 | (setq cpos (point-marker))) | 611 | ;; and landed right before the comment-ender: |
| 612 | ;; Go back to the middle of the space. | ||
| 613 | (forward-char (/ (skip-chars-backward " \t") -2))) | ||
| 614 | (setq cpos (point-marker))) | ||
| 612 | ;; If none, insert one. | 615 | ;; If none, insert one. |
| 613 | (if comment-insert-comment-function | ||
| 614 | (funcall comment-insert-comment-function) | ||
| 615 | (save-excursion | 616 | (save-excursion |
| 616 | ;; Some `comment-indent-function's insist on not moving | 617 | ;; Some `comment-indent-function's insist on not moving |
| 617 | ;; comments that are in column 0, so we first go to the | 618 | ;; comments that are in column 0, so we first go to the |
| @@ -624,32 +625,32 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any." | |||
| 624 | (setq begpos (point)) | 625 | (setq begpos (point)) |
| 625 | (insert starter) | 626 | (insert starter) |
| 626 | (setq cpos (point-marker)) | 627 | (setq cpos (point-marker)) |
| 627 | (insert ender)))) | 628 | (insert ender))) |
| 628 | (goto-char begpos) | 629 | (goto-char begpos) |
| 629 | ;; Compute desired indent. | 630 | ;; Compute desired indent. |
| 630 | (setq indent (save-excursion (funcall comment-indent-function))) | 631 | (setq indent (save-excursion (funcall comment-indent-function))) |
| 631 | ;; If `indent' is nil and there's code before the comment, we can't | 632 | ;; If `indent' is nil and there's code before the comment, we can't |
| 632 | ;; use `indent-according-to-mode', so we default to comment-column. | 633 | ;; use `indent-according-to-mode', so we default to comment-column. |
| 633 | (unless (or indent (save-excursion (skip-chars-backward " \t") (bolp))) | 634 | (unless (or indent (save-excursion (skip-chars-backward " \t") (bolp))) |
| 634 | (setq indent comment-column)) | 635 | (setq indent comment-column)) |
| 635 | (if (not indent) | 636 | (if (not indent) |
| 636 | ;; comment-indent-function refuses: delegate to line-indent. | 637 | ;; comment-indent-function refuses: delegate to line-indent. |
| 637 | (indent-according-to-mode) | 638 | (indent-according-to-mode) |
| 638 | ;; If the comment is at the right of code, adjust the indentation. | 639 | ;; If the comment is at the right of code, adjust the indentation. |
| 639 | (unless (save-excursion (skip-chars-backward " \t") (bolp)) | 640 | (unless (save-excursion (skip-chars-backward " \t") (bolp)) |
| 640 | (setq indent (comment-choose-indent indent))) | 641 | (setq indent (comment-choose-indent indent))) |
| 641 | ;; Update INDENT to leave at least one space | 642 | ;; Update INDENT to leave at least one space |
| 642 | ;; after other nonwhite text on the line. | 643 | ;; after other nonwhite text on the line. |
| 643 | (save-excursion | 644 | (save-excursion |
| 644 | (skip-chars-backward " \t") | 645 | (skip-chars-backward " \t") |
| 645 | (unless (bolp) | 646 | (unless (bolp) |
| 646 | (setq indent (max indent (1+ (current-column)))))) | 647 | (setq indent (max indent (1+ (current-column)))))) |
| 647 | ;; If that's different from comment's current position, change it. | 648 | ;; If that's different from comment's current position, change it. |
| 648 | (unless (= (current-column) indent) | 649 | (unless (= (current-column) indent) |
| 649 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) | 650 | (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
| 650 | (indent-to indent))) | 651 | (indent-to indent))) |
| 651 | (goto-char cpos) | 652 | (goto-char cpos) |
| 652 | (set-marker cpos nil)))) | 653 | (set-marker cpos nil))))) |
| 653 | 654 | ||
| 654 | ;;;###autoload | 655 | ;;;###autoload |
| 655 | (defun comment-set-column (arg) | 656 | (defun comment-set-column (arg) |