diff options
| author | Martin Stjernholm | 2002-04-24 01:27:15 +0000 |
|---|---|---|
| committer | Martin Stjernholm | 2002-04-24 01:27:15 +0000 |
| commit | 07cc1196d2c8c68bd703dae8c431ea4bb49464d6 (patch) | |
| tree | b7a238c7dc797be18d18b3895bade3228e12792a | |
| parent | 603c85d373459d0d3d6664b787fd773082364361 (diff) | |
| download | emacs-07cc1196d2c8c68bd703dae8c431ea4bb49464d6.tar.gz emacs-07cc1196d2c8c68bd703dae8c431ea4bb49464d6.zip | |
(c-mask-comment): A better way to ensure point doesn't move around
unexpectedly. Also handles the paragraph fill case.
| -rw-r--r-- | lisp/progmodes/cc-cmds.el | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 96b72eb1754..b23b7657996 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el | |||
| @@ -2761,10 +2761,14 @@ command to conveniently insert and align the necessary backslashes." | |||
| 2761 | '("" . 0)))))) | 2761 | '("" . 0)))))) |
| 2762 | )) | 2762 | )) |
| 2763 | 2763 | ||
| 2764 | (defun c-mask-comment (fill-mode apply-outside-literal fun &rest args) | 2764 | (defun c-mask-comment (fill-paragraph apply-outside-literal fun &rest args) |
| 2765 | ;; Calls FUN with ARGS ar arguments. If point is inside a comment, | 2765 | ;; Calls FUN with ARGS ar arguments. If point is inside a comment, |
| 2766 | ;; the comment starter and ender are masked and the buffer is | 2766 | ;; the comment starter and ender are masked and the buffer is |
| 2767 | ;; narrowed to make it look like a normal paragraph during the call. | 2767 | ;; narrowed to make it look like a normal paragraph during the call. |
| 2768 | ;; | ||
| 2769 | ;; FILL-PARAGRAPH is non-nil if called for paragraph filling. The | ||
| 2770 | ;; position of point is then less significant when doing masking and | ||
| 2771 | ;; narrowing. | ||
| 2768 | (let (fill | 2772 | (let (fill |
| 2769 | ;; beg and end limits the region to narrow. end is a marker. | 2773 | ;; beg and end limits the region to narrow. end is a marker. |
| 2770 | beg end | 2774 | beg end |
| @@ -2790,7 +2794,7 @@ command to conveniently insert and align the necessary backslashes." | |||
| 2790 | ;; Widen to catch comment limits correctly. | 2794 | ;; Widen to catch comment limits correctly. |
| 2791 | (widen) | 2795 | (widen) |
| 2792 | (unless c-lit-limits | 2796 | (unless c-lit-limits |
| 2793 | (setq c-lit-limits (c-literal-limits nil fill-mode))) | 2797 | (setq c-lit-limits (c-literal-limits nil fill-paragraph))) |
| 2794 | (setq c-lit-limits (c-collect-line-comments c-lit-limits)) | 2798 | (setq c-lit-limits (c-collect-line-comments c-lit-limits)) |
| 2795 | (unless c-lit-type | 2799 | (unless c-lit-type |
| 2796 | (setq c-lit-type (c-literal-type c-lit-limits)))) | 2800 | (setq c-lit-type (c-literal-type c-lit-limits)))) |
| @@ -2840,8 +2844,8 @@ command to conveniently insert and align the necessary backslashes." | |||
| 2840 | "\\)\\*/")) | 2844 | "\\)\\*/")) |
| 2841 | (eq (cdr c-lit-limits) (match-end 0)) | 2845 | (eq (cdr c-lit-limits) (match-end 0)) |
| 2842 | ;; Leave the comment ender on its own line. | 2846 | ;; Leave the comment ender on its own line. |
| 2843 | (set-marker end (max (point) here)))) | 2847 | (set-marker end (point)))) |
| 2844 | (when fill-mode | 2848 | (when fill-paragraph |
| 2845 | ;; The comment ender should hang. Replace all cruft | 2849 | ;; The comment ender should hang. Replace all cruft |
| 2846 | ;; between it and the last word with one or two 'x' | 2850 | ;; between it and the last word with one or two 'x' |
| 2847 | ;; and include it in the region. We'll change them | 2851 | ;; and include it in the region. We'll change them |
| @@ -2900,13 +2904,11 @@ command to conveniently insert and align the necessary backslashes." | |||
| 2900 | ;; The region includes the comment starter. | 2904 | ;; The region includes the comment starter. |
| 2901 | (save-excursion | 2905 | (save-excursion |
| 2902 | (goto-char (car c-lit-limits)) | 2906 | (goto-char (car c-lit-limits)) |
| 2903 | (when (and (looking-at comment-start-skip) | 2907 | (if (looking-at (concat "\\(" comment-start-skip "\\)$")) |
| 2904 | (> here (match-end 0))) | 2908 | ;; Begin with the next line. |
| 2905 | (if (eq (match-end 0) (c-point 'eol)) | 2909 | (setq beg (c-point 'bonl)) |
| 2906 | ;; Begin with the next line. | 2910 | ;; Fake the fill prefix in the first line. |
| 2907 | (setq beg (c-point 'bonl)) | 2911 | (setq tmp-pre t))))) |
| 2908 | ;; Fake the fill prefix in the first line. | ||
| 2909 | (setq tmp-pre t)))))) | ||
| 2910 | ((eq c-lit-type 'string) ; String. | 2912 | ((eq c-lit-type 'string) ; String. |
| 2911 | (save-excursion | 2913 | (save-excursion |
| 2912 | (when (>= end (cdr c-lit-limits)) | 2914 | (when (>= end (cdr c-lit-limits)) |
| @@ -2984,24 +2986,24 @@ Warning: Regexp from `c-comment-prefix-regexp' doesn't match the comment prefix | |||
| 2984 | "")))) | 2986 | "")))) |
| 2985 | (car (or fill (c-guess-fill-prefix | 2987 | (car (or fill (c-guess-fill-prefix |
| 2986 | c-lit-limits c-lit-type)))))) | 2988 | c-lit-limits c-lit-type)))))) |
| 2987 | ;; Don't remember why I added this, but it doesn't | 2989 | ;; Save the relative position of point if it's |
| 2988 | ;; work correctly since `here' can point anywhere | 2990 | ;; outside the region we're going to narrow. Want |
| 2989 | ;; after the deletes and inserts above. | 2991 | ;; to restore it in that case, but otherwise it |
| 2990 | ;(point-rel (cond ((< here beg) (- here beg)) | 2992 | ;; should be moved according to the called |
| 2991 | ; ((> here end) (- here end)))) | 2993 | ;; function. |
| 2992 | ) | 2994 | (point-rel (cond ((< (point) beg) (- (point) beg)) |
| 2995 | ((> (point) end) (- (point) end))))) | ||
| 2993 | ;; Preparations finally done! Now we can call the | 2996 | ;; Preparations finally done! Now we can call the |
| 2994 | ;; actual function. | 2997 | ;; actual function. |
| 2995 | (prog1 | 2998 | (prog1 |
| 2996 | (save-restriction | 2999 | (save-restriction |
| 2997 | (narrow-to-region beg end) | 3000 | (narrow-to-region beg end) |
| 2998 | (apply fun args)) | 3001 | (apply fun args)) |
| 2999 | ;(if point-rel | 3002 | (if point-rel |
| 3000 | ; ;; Restore point if it was outside the region. | 3003 | ;; Restore point if it was outside the region. |
| 3001 | ; (if (< point-rel 0) | 3004 | (if (< point-rel 0) |
| 3002 | ; (goto-char (+ beg point-rel)) | 3005 | (goto-char (+ beg point-rel)) |
| 3003 | ; (goto-char (+ end point-rel)))) | 3006 | (goto-char (+ end point-rel)))))) |
| 3004 | )) | ||
| 3005 | (when apply-outside-literal | 3007 | (when apply-outside-literal |
| 3006 | (apply fun args)))) | 3008 | (apply fun args)))) |
| 3007 | (when (consp tmp-pre) | 3009 | (when (consp tmp-pre) |