]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-mode.el
Merge from emacs-24, up to 2012-04-10T02:06:19Z!larsi@gnus.org
[gnu-emacs] / lisp / progmodes / cc-mode.el
index 600d4fc8b560f70b16cdcd837ff9cdbefce500b0..7c018feefbb631ba7c85c178e904f072ad285f2d 100644 (file)
@@ -490,6 +490,7 @@ that requires a literal mode spec at compile time."
   (make-local-variable 'paragraph-ignore-fill-prefix)
   (make-local-variable 'adaptive-fill-mode)
   (make-local-variable 'adaptive-fill-regexp)
+  (make-local-variable 'fill-paragraph-handle-comment)
 
   ;; now set their values
   (set (make-local-variable 'parse-sexp-ignore-comments) t)
@@ -500,6 +501,9 @@ that requires a literal mode spec at compile time."
   (set (make-local-variable 'comment-line-break-function)
        'c-indent-new-comment-line)
 
+  ;; For the benefit of adaptive file, which otherwise mis-fills.
+  (setq fill-paragraph-handle-comment nil)
+
   ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
   ;; direct call to `fill-paragraph' behaves better.  This still
   ;; doesn't work with filladapt but it's better than nothing.
@@ -921,8 +925,8 @@ Note that the style variables are always made local to the buffer."
     ;; inside a string, comment, or macro.
     (setq new-bounds (c-extend-font-lock-region-for-macros
                      c-new-BEG c-new-END old-len))
-    (setq c-new-BEG (car new-bounds)
-         c-new-END (cdr new-bounds))
+    (setq c-new-BEG (max (car new-bounds) (c-determine-limit 500 begg))
+         c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
     ;; Clear all old relevant properties.
     (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
     (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
@@ -1110,7 +1114,7 @@ Note that the style variables are always made local to the buffer."
     (goto-char (c-point 'bol new-pos))
     (when lit-limits                   ; Comment or string.
       (goto-char (car lit-limits)))
-    (setq bod-lim (max (- (point) 500) (point-min)))
+    (setq bod-lim (c-determine-limit 500))
 
     (while
        ;; Go to a less nested declaration each time round this loop.
@@ -1128,11 +1132,12 @@ Note that the style variables are always made local to the buffer."
         ;; Try and go out a level to search again.
         (progn
           (c-backward-syntactic-ws bod-lim)
-          (or (memq (char-before) '(?\( ?\[))
-              (and (eq (char-before) ?\<)
-                   (eq (c-get-char-property
-                        (1- (point)) 'syntax-table)
-                       c-<-as-paren-syntax))))
+          (and (> (point) bod-lim)
+               (or (memq (char-before) '(?\( ?\[))
+                   (and (eq (char-before) ?\<)
+                        (eq (c-get-char-property
+                             (1- (point)) 'syntax-table)
+                            c-<-as-paren-syntax)))))
         (not (bobp)))
       (backward-char))
     new-pos))                          ; back over (, [, <.
@@ -1158,7 +1163,7 @@ Note that the style variables are always made local to the buffer."
   ;; Effectively advice around `font-lock-fontify-region' which extends the
   ;; region (BEG END), for example, to avoid context fontification chopping
   ;; off the start of the context.  Do not do anything if it's already been
-  ;; done (i.e. from and after-change fontification.  An example (C++) where
+  ;; done (i.e. from an after-change fontification.  An example (C++) where
   ;; this used to happen is this:
   ;;
   ;;     template <typename T>