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