diff options
| author | Karl Heuer | 1998-12-14 02:50:10 +0000 |
|---|---|---|
| committer | Karl Heuer | 1998-12-14 02:50:10 +0000 |
| commit | 4044f853251d04c63f3e6fbd8de14c59ec9df99a (patch) | |
| tree | d6a3ef6045841ffcc658909531cb2ade3e02f896 | |
| parent | b78fba0277fbca08c9775dbc875d44b53f2477fb (diff) | |
| download | emacs-4044f853251d04c63f3e6fbd8de14c59ec9df99a.tar.gz emacs-4044f853251d04c63f3e6fbd8de14c59ec9df99a.zip | |
(comment-region): Handle comment-padding
separately for insertion and for deletion, in the right way for each.
| -rw-r--r-- | lisp/simple.el | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 6a4734a8004..5012d600d75 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -2772,8 +2772,10 @@ not end the comment. Blank lines do not get comments." | |||
| 2772 | (save-excursion | 2772 | (save-excursion |
| 2773 | (save-restriction | 2773 | (save-restriction |
| 2774 | (let ((cs comment-start) (ce comment-end) | 2774 | (let ((cs comment-start) (ce comment-end) |
| 2775 | (cp (when comment-padding | ||
| 2776 | (make-string comment-padding ? ))) | ||
| 2775 | numarg) | 2777 | numarg) |
| 2776 | (if (consp arg) (setq numarg t) | 2778 | (if (consp arg) (setq numarg t) |
| 2777 | (setq numarg (prefix-numeric-value arg)) | 2779 | (setq numarg (prefix-numeric-value arg)) |
| 2778 | ;; For positive arg > 1, replicate the comment delims now, | 2780 | ;; For positive arg > 1, replicate the comment delims now, |
| 2779 | ;; then insert the replicated strings just once. | 2781 | ;; then insert the replicated strings just once. |
| @@ -2781,13 +2783,11 @@ not end the comment. Blank lines do not get comments." | |||
| 2781 | (setq cs (concat cs comment-start) | 2783 | (setq cs (concat cs comment-start) |
| 2782 | ce (concat ce comment-end)) | 2784 | ce (concat ce comment-end)) |
| 2783 | (setq numarg (1- numarg)))) | 2785 | (setq numarg (1- numarg)))) |
| 2784 | (when comment-padding | ||
| 2785 | (setq cs (concat cs (make-string comment-padding ? )))) | ||
| 2786 | ;; Loop over all lines from BEG to END. | 2786 | ;; Loop over all lines from BEG to END. |
| 2787 | (narrow-to-region beg end) | 2787 | (narrow-to-region beg end) |
| 2788 | (goto-char beg) | 2788 | (goto-char beg) |
| 2789 | (while (not (eobp)) | 2789 | (if (or (eq numarg t) (< numarg 0)) |
| 2790 | (if (or (eq numarg t) (< numarg 0)) | 2790 | (while (not (eobp)) |
| 2791 | (progn | 2791 | (progn |
| 2792 | ;; Delete comment start from beginning of line. | 2792 | ;; Delete comment start from beginning of line. |
| 2793 | (if (eq numarg t) | 2793 | (if (eq numarg t) |
| @@ -2797,8 +2797,11 @@ not end the comment. Blank lines do not get comments." | |||
| 2797 | (while (and (> 1 (setq count (1+ count))) | 2797 | (while (and (> 1 (setq count (1+ count))) |
| 2798 | (looking-at (regexp-quote cs))) | 2798 | (looking-at (regexp-quote cs))) |
| 2799 | (delete-char (length cs))))) | 2799 | (delete-char (length cs))))) |
| 2800 | ;; Delete comment padding from beginning of line | ||
| 2801 | (when (and comment-padding (looking-at (regexp-quote cp))) | ||
| 2802 | (delete-char comment-padding)) | ||
| 2800 | ;; Delete comment end from end of line. | 2803 | ;; Delete comment end from end of line. |
| 2801 | (if (string= "" ce) | 2804 | (if (string= "" ce) |
| 2802 | nil | 2805 | nil |
| 2803 | (if (eq numarg t) | 2806 | (if (eq numarg t) |
| 2804 | (progn | 2807 | (progn |
| @@ -2823,14 +2826,18 @@ not end the comment. Blank lines do not get comments." | |||
| 2823 | (backward-char (length ce)) | 2826 | (backward-char (length ce)) |
| 2824 | (if (looking-at (regexp-quote ce)) | 2827 | (if (looking-at (regexp-quote ce)) |
| 2825 | (delete-char (length ce))))))))) | 2828 | (delete-char (length ce))))))))) |
| 2826 | (forward-line 1)) | 2829 | (forward-line 1))) |
| 2830 | |||
| 2831 | (when comment-padding | ||
| 2832 | (setq cs (concat cs cp))) | ||
| 2833 | (while (not (eobp)) | ||
| 2827 | ;; Insert at beginning and at end. | 2834 | ;; Insert at beginning and at end. |
| 2828 | (if (looking-at "[ \t]*$") () | 2835 | (if (looking-at "[ \t]*$") () |
| 2829 | (insert cs) | 2836 | (insert cs) |
| 2830 | (if (string= "" ce) () | 2837 | (if (string= "" ce) () |
| 2831 | (end-of-line) | 2838 | (end-of-line) |
| 2832 | (insert ce))) | 2839 | (insert ce))) |
| 2833 | (search-forward "\n" nil 'move))))))) | 2840 | (search-forward "\n" nil 'move))))))) |
| 2834 | 2841 | ||
| 2835 | (defun backward-word (arg) | 2842 | (defun backward-word (arg) |
| 2836 | "Move backward until encountering the end of a word. | 2843 | "Move backward until encountering the end of a word. |