Mercurial > emacs
comparison lisp/progmodes/cc-cmds.el @ 27111:cad48fa4c22d
(c-fill-paragraph): Count number of spaces
at comment end, and re-insert them after filling.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 03 Jan 2000 14:49:24 +0000 |
parents | 0c7659f0428f |
children | 4fe5cb975331 |
comparison
equal
deleted
inserted
replaced
27110:3687809feff2 | 27111:cad48fa4c22d |
---|---|
2071 ;; and include it in the fill. We'll change it | 2071 ;; and include it in the fill. We'll change it |
2072 ;; back to a space afterwards. | 2072 ;; back to a space afterwards. |
2073 (let ((ender-start (progn | 2073 (let ((ender-start (progn |
2074 (goto-char (cdr lit-limits)) | 2074 (goto-char (cdr lit-limits)) |
2075 (skip-syntax-backward "^w ") | 2075 (skip-syntax-backward "^w ") |
2076 (point)))) | 2076 (point))) |
2077 spaces) | |
2077 (goto-char (cdr lit-limits)) | 2078 (goto-char (cdr lit-limits)) |
2078 (setq tmp-post (point-marker)) | 2079 (setq tmp-post (point-marker)) |
2079 (insert ?\n) | 2080 (insert ?\n) |
2080 (set-marker end (point)) | 2081 (set-marker end (point)) |
2081 (forward-line -1) | 2082 (forward-line -1) |
2082 (if (and (looking-at (concat "[ \t]*\\(" | 2083 (if (and (looking-at (concat "[ \t]*\\(\\(" |
2083 c-comment-prefix-regexp | 2084 c-comment-prefix-regexp |
2084 "\\)[ \t]*")) | 2085 "\\)[ \t]*\\)")) |
2085 (eq ender-start (match-end 0))) | 2086 (eq ender-start (match-end 0))) |
2086 ;; The comment ender is prefixed by nothing | 2087 ;; The comment ender is prefixed by nothing |
2087 ;; but a comment line prefix. Remove it | 2088 ;; but a comment line prefix. Remove it |
2088 ;; along with surrounding ws. | 2089 ;; along with surrounding ws. |
2089 nil | 2090 (setq spaces (- (match-end 1) (match-end 2))) |
2090 (goto-char ender-start)) | 2091 (goto-char ender-start)) |
2091 ;(skip-chars-backward " \t\r\n") | 2092 (skip-chars-backward " \t\r\n") |
2092 (when (/= (point) ender-start) | 2093 (when (/= (point) ender-start) |
2093 (insert ?x) ; Insert first to keep marks right. | 2094 ;; Keep one or two spaces between the text and |
2094 (delete-region (point) (1+ ender-start)) | 2095 ;; the ender, depending on how many there are now. |
2095 (setq hang-ender-stuck t))))) | 2096 (unless spaces (setq spaces (- ender-start (point)))) |
2097 (setq spaces (max (min spaces 2) 1)) | |
2098 ; Insert the filler first to keep marks right. | |
2099 (insert (make-string spaces ?x)) | |
2100 (delete-region (point) (+ ender-start spaces)) | |
2101 (setq hang-ender-stuck spaces))))) | |
2096 (when (<= beg (car lit-limits)) | 2102 (when (<= beg (car lit-limits)) |
2097 ;; The region to be filled includes the comment starter. | 2103 ;; The region to be filled includes the comment starter. |
2098 (goto-char (car lit-limits)) | 2104 (goto-char (car lit-limits)) |
2099 (if (looking-at (concat "\\(" comment-start-skip "\\)$")) | 2105 (if (looking-at (concat "\\(" comment-start-skip "\\)$")) |
2100 ;; Begin filling with the next line. | 2106 ;; Begin filling with the next line. |
2185 (save-excursion | 2191 (save-excursion |
2186 (goto-char tmp-post) | 2192 (goto-char tmp-post) |
2187 (delete-char 1) | 2193 (delete-char 1) |
2188 (when hang-ender-stuck | 2194 (when hang-ender-stuck |
2189 (skip-syntax-backward "^w ") | 2195 (skip-syntax-backward "^w ") |
2190 (forward-char -1) | 2196 (forward-char (- hang-ender-stuck)) |
2191 (insert ?\ ) | 2197 (insert (make-string hang-ender-stuck ?\ )) |
2192 (delete-char 1)) | 2198 (delete-char hang-ender-stuck)) |
2193 (set-marker tmp-post nil))))) | 2199 (set-marker tmp-post nil))))) |
2194 (set-marker end nil)) | 2200 (set-marker end nil)) |
2195 ;; Always return t. This has the effect that if filling isn't done | 2201 ;; Always return t. This has the effect that if filling isn't done |
2196 ;; above, it isn't done at all, and it's therefore effectively | 2202 ;; above, it isn't done at all, and it's therefore effectively |
2197 ;; disabled in normal code. | 2203 ;; disabled in normal code. |