aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2008-05-24 12:47:37 +0000
committerAlan Mackenzie2008-05-24 12:47:37 +0000
commitc5fcadd11f10cb938322281209d3e40076b4b607 (patch)
treecb11271d867622ff3ff466cdd665ad79fe978c52
parentdc3762147867441835c95bb3926cdb2bf5294e6a (diff)
downloademacs-c5fcadd11f10cb938322281209d3e40076b4b607.tar.gz
emacs-c5fcadd11f10cb938322281209d3e40076b4b607.zip
(c-postprocess-file-styles): Throw an error if c-file-style is set to a
non-string. (c-neutralize-CPP-line): Surround by `save-excursion'. (c-neutralize-syntax-in-CPP): Optimize for speed.
-rw-r--r--lisp/progmodes/cc-mode.el86
1 files changed, 53 insertions, 33 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index a80564a81d1..03d1019bd53 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -715,8 +715,10 @@ Note that the style variables are always made local to the buffer."
715 (when c-buffer-is-cc-mode 715 (when c-buffer-is-cc-mode
716 (if (or c-file-style c-file-offsets) 716 (if (or c-file-style c-file-offsets)
717 (c-make-styles-buffer-local t)) 717 (c-make-styles-buffer-local t))
718 (and c-file-style 718 (when c-file-style
719 (c-set-style c-file-style)) 719 (or (stringp c-file-style)
720 (error "c-file-style is not a string"))
721 (c-set-style c-file-style))
720 (and c-file-offsets 722 (and c-file-offsets
721 (mapc 723 (mapc
722 (lambda (langentry) 724 (lambda (langentry)
@@ -794,28 +796,30 @@ Note that the style variables are always made local to the buffer."
794 (setq c-old-EOM (point))) 796 (setq c-old-EOM (point)))
795 797
796(defun c-neutralize-CPP-line (beg end) 798(defun c-neutralize-CPP-line (beg end)
797 ;; BEG and END bound a preprocessor line. Put a "punctuation" syntax-table 799 ;; BEG and END bound a region, typically a preprocessor line. Put a
798 ;; property on syntactically obtrusive characters, ones which would interact 800 ;; "punctuation" syntax-table property on syntactically obtrusive
799 ;; syntactically with stuff outside the CPP line. 801 ;; characters, ones which would interact syntactically with stuff outside
802 ;; this region.
800 ;; 803 ;;
801 ;; These are unmatched string delimiters, or unmatched 804 ;; These are unmatched string delimiters, or unmatched
802 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT 805 ;; parens/brackets/braces. An unclosed comment is regarded as valid, NOT
803 ;; obtrusive. 806 ;; obtrusive.
804 (let (s) 807 (save-excursion
805 (while 808 (let (s)
806 (progn 809 (while
807 (setq s (parse-partial-sexp beg end -1)) 810 (progn
808 (cond 811 (setq s (parse-partial-sexp beg end -1))
809 ((< (nth 0 s) 0) ; found an unmated ),},] 812 (cond
810 (c-put-char-property (1- (point)) 'syntax-table '(1)) 813 ((< (nth 0 s) 0) ; found an unmated ),},]
811 t) 814 (c-put-char-property (1- (point)) 'syntax-table '(1))
812 ((nth 3 s) ; In a string 815 t)
813 (c-put-char-property (nth 8 s) 'syntax-table '(1)) 816 ((nth 3 s) ; In a string
814 t) 817 (c-put-char-property (nth 8 s) 'syntax-table '(1))
815 ((> (nth 0 s) 0) ; In a (,{,[ 818 t)
816 (c-put-char-property (nth 1 s) 'syntax-table '(1)) 819 ((> (nth 0 s) 0) ; In a (,{,[
817 t) 820 (c-put-char-property (nth 1 s) 'syntax-table '(1))
818 (t nil)))))) 821 t)
822 (t nil)))))))
819 823
820(defun c-neutralize-syntax-in-CPP (begg endd old-len) 824(defun c-neutralize-syntax-in-CPP (begg endd old-len)
821 ;; "Neutralize" every preprocessor line wholly or partially in the changed 825 ;; "Neutralize" every preprocessor line wholly or partially in the changed
@@ -835,27 +839,43 @@ Note that the style variables are always made local to the buffer."
835 ;; 839 ;;
836 ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'. 840 ;; This function is the C/C++/ObjC value of `c-before-font-lock-function'.
837 ;; 841 ;;
838 ;; This function might do invisible changes. 842 ;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
843 ;;
844 ;; This function might make hidden buffer changes.
839 (c-save-buffer-state (limits mbeg+1 beg end) 845 (c-save-buffer-state (limits mbeg+1 beg end)
840 ;; First calculate the region, possibly to be extended. 846 ;; First determine the region, (beg end), which may need "neutralizing".
841 (setq beg (min begg c-old-BOM)) 847 ;; This may not start inside a string, comment, or macro.
848 (goto-char c-old-BOM) ; already set to old start of macro or begg.
849 (setq beg
850 (if (setq limits (c-literal-limits))
851 (cdr limits) ; go forward out of any string or comment.
852 (point)))
853
842 (goto-char endd) 854 (goto-char endd)
843 (when (c-beginning-of-macro) 855 (if (setq limits (c-literal-limits))
844 (c-end-of-macro)) 856 (goto-char (car limits))) ; go backward out of any string or comment.
857 (if (c-beginning-of-macro)
858 (c-end-of-macro))
845 (setq end (max (+ (- c-old-EOM old-len) (- endd begg)) 859 (setq end (max (+ (- c-old-EOM old-len) (- endd begg))
846 (point))) 860 (point)))
861
847 ;; Clear all old punctuation properties 862 ;; Clear all old punctuation properties
848 (c-clear-char-property-with-value beg end 'syntax-table '(1)) 863 (c-clear-char-property-with-value beg end 'syntax-table '(1))
849 864
850 (goto-char beg) 865 (goto-char beg)
851 (while (and (< (point) end) 866 (let ((pps-position beg) pps-state)
852 (search-forward-regexp c-anchored-cpp-prefix end t)) 867 (while (and (< (point) end)
853 ;; If we've found a "#" inside a string/comment, ignore it. 868 (search-forward-regexp c-anchored-cpp-prefix end t))
854 (if (setq limits (c-literal-limits)) 869 ;; If we've found a "#" inside a string/comment, ignore it.
855 (goto-char (cdr limits)) 870 (setq pps-state
856 (setq mbeg+1 (point)) 871 (parse-partial-sexp pps-position (point) nil nil pps-state)
857 (c-end-of-macro) ; Do we need to go forward 1 char here? No! 872 pps-position (point))
858 (c-neutralize-CPP-line mbeg+1 (point)))))) 873 (unless (or (nth 3 pps-state) ; in a string?
874 (nth 4 pps-state)) ; in a comment?
875 (setq mbeg+1 (point))
876 (c-end-of-macro) ; Do we need to go forward 1 char here? No!
877 (c-neutralize-CPP-line mbeg+1 (point))
878 (setq pps-position (point))))))) ; no need to update pps-state.
859 879
860(defun c-before-change (beg end) 880(defun c-before-change (beg end)
861 ;; Function to be put on `before-change-function'. Primarily, this calls 881 ;; Function to be put on `before-change-function'. Primarily, this calls