emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/progmodes/cc-mode.el,v


From: Alan Mackenzie
Subject: [Emacs-diffs] Changes to emacs/lisp/progmodes/cc-mode.el,v
Date: Sat, 24 May 2008 12:47:38 +0000

CVSROOT:        /cvsroot/emacs
Module name:    emacs
Changes by:     Alan Mackenzie <acmacm> 08/05/24 12:47:38

Index: cc-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-mode.el,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -b -r1.74 -r1.75
--- cc-mode.el  15 May 2008 03:30:40 -0000      1.74
+++ cc-mode.el  24 May 2008 12:47:37 -0000      1.75
@@ -715,7 +715,9 @@
   (when c-buffer-is-cc-mode
     (if (or c-file-style c-file-offsets)
        (c-make-styles-buffer-local t))
-    (and c-file-style
+    (when c-file-style
+      (or (stringp c-file-style)
+         (error "c-file-style is not a string"))
         (c-set-style c-file-style))
     (and c-file-offsets
         (mapc
@@ -794,13 +796,15 @@
   (setq c-old-EOM (point)))
 
 (defun c-neutralize-CPP-line (beg end)
-  ;; BEG and END bound a preprocessor line.  Put a "punctuation" syntax-table
-  ;; property on syntactically obtrusive characters, ones which would interact
-  ;; syntactically with stuff outside the CPP line.
+  ;; BEG and END bound a region, typically a preprocessor line.  Put a
+  ;; "punctuation" syntax-table property on syntactically obtrusive
+  ;; characters, ones which would interact syntactically with stuff outside
+  ;; this region.
   ;;
   ;; These are unmatched string delimiters, or unmatched
   ;; parens/brackets/braces.  An unclosed comment is regarded as valid, NOT
   ;; obtrusive.
+  (save-excursion
   (let (s)
     (while
        (progn
@@ -815,7 +819,7 @@
           ((> (nth 0 s) 0)             ; In a (,{,[
            (c-put-char-property (nth 1 s) 'syntax-table '(1))
            t)
-          (t nil))))))
+            (t nil)))))))
 
 (defun c-neutralize-syntax-in-CPP (begg endd old-len)
   ;; "Neutralize" every preprocessor line wholly or partially in the changed
@@ -835,27 +839,43 @@
   ;;
   ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'.
   ;;
-  ;; This function might do invisible changes.
+  ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
+  ;; 
+  ;; This function might make hidden buffer changes.
   (c-save-buffer-state (limits mbeg+1 beg end)
-    ;; First calculate the region, possibly to be extended.
-    (setq beg (min begg c-old-BOM))
+    ;; First determine the region, (beg end), which may need "neutralizing".
+    ;; This may not start inside a string, comment, or macro.
+    (goto-char c-old-BOM)        ; already set to old start of macro or begg.
+    (setq beg
+         (if (setq limits (c-literal-limits))
+             (cdr limits)          ; go forward out of any string or comment.
+           (point)))
+
     (goto-char endd)
-    (when (c-beginning-of-macro)
+    (if (setq limits (c-literal-limits))
+       (goto-char (car limits)))  ; go backward out of any string or comment.
+    (if (c-beginning-of-macro)
       (c-end-of-macro))
     (setq end (max (+ (- c-old-EOM old-len) (- endd begg))
                   (point)))
+
     ;; Clear all old punctuation properties
     (c-clear-char-property-with-value beg end 'syntax-table '(1))
 
     (goto-char beg)
+    (let ((pps-position beg)  pps-state)
     (while (and (< (point) end)
                (search-forward-regexp c-anchored-cpp-prefix end t))
       ;; If we've found a "#" inside a string/comment, ignore it.
-      (if (setq limits (c-literal-limits))
-         (goto-char (cdr limits))
+       (setq pps-state
+             (parse-partial-sexp pps-position (point) nil nil pps-state)
+             pps-position (point))
+       (unless (or (nth 3 pps-state)   ; in a string?
+                   (nth 4 pps-state))  ; in a comment?
        (setq mbeg+1 (point))
        (c-end-of-macro)          ; Do we need to go forward 1 char here?  No!
-       (c-neutralize-CPP-line mbeg+1 (point))))))
+         (c-neutralize-CPP-line mbeg+1 (point))
+         (setq pps-position (point))))))) ; no need to update pps-state.
 
 (defun c-before-change (beg end)
   ;; Function to be put on `before-change-function'.  Primarily, this calls




reply via email to

[Prev in Thread] Current Thread [Next in Thread]