;;
;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
+;; Externally maintained major modes which use CC-mode's engine include:
+;; - cuda-mode
+;; - csharp-mode (https://github.com/josteink/csharp-mode)
+;; - haxe-mode
+;; - d-mode
+;; - dart-mode
+;; - cc-php-js-cs.el
+;; - php-mode
+;; - yang-mode
+;; - math-mode (mathematica)
+;; - unrealscript-mode
+;; - groovy-mode
+
;;; Code:
;; For Emacs < 22.2.
(not (string-equal c-indentation-style
style)))))))
(c-setup-paragraph-variables)
- (c-make-noise-macro-regexps)
;; we have to do something special for c-offsets-alist so that the
;; buffer local value has its own alist structure.
(funcall fn (point-min) (point-max)))
c-get-state-before-change-functions)
(mapc (lambda (fn)
- (if (not (eq fn 'c-restore-<>-properties))
- (funcall fn (point-min) (point-max)
- (- (point-max) (point-min)))))
+ (funcall fn (point-min) (point-max)
+ (- (point-max) (point-min))))
c-before-font-lock-functions))))
(set (make-local-variable 'outline-regexp) "[^#\n\^M]")
\f
;;; Change hooks, linking with Font Lock and electric-indent-mode.
-;; Buffer local variables recording Beginning/End-of-Macro position before a
-;; change, when a macro straddles, respectively, the BEG or END (or both) of
-;; the change region. Otherwise these have the values BEG/END.
-(defvar c-old-BOM 0)
-(make-variable-buffer-local 'c-old-BOM)
-(defvar c-old-EOM 0)
-(make-variable-buffer-local 'c-old-EOM)
-
(defun c-called-from-text-property-change-p ()
;; Is the primitive which invoked `before-change-functions' or
;; `after-change-functions' one which merely changes text properties? This
'(put-text-property remove-list-of-text-properties)))
(defun c-extend-region-for-CPP (beg end)
- ;; Set c-old-BOM or c-old-EOM respectively to BEG, END, each extended to the
- ;; beginning/end of any preprocessor construct they may be in.
+ ;; Adjust `c-new-BEG', `c-new-END' respectively to the beginning and end of
+ ;; any preprocessor construct they may be in.
;;
;; Point is undefined both before and after this function call; the buffer
;; has already been widened, and match-data saved. The return value is
;; This function is in the C/C++/ObjC values of
;; `c-get-state-before-change-functions' and is called exclusively as a
;; before change function.
- (goto-char beg)
+ (goto-char c-new-BEG)
(c-beginning-of-macro)
- (setq c-old-BOM (point))
+ (setq c-new-BEG (point))
- (goto-char end)
+ (goto-char c-new-END)
(when (c-beginning-of-macro)
(c-end-of-macro)
(or (eobp) (forward-char))) ; Over the terminating NL which may be marked
; with a c-cpp-delimiter category property
- (setq c-old-EOM (point)))
-
-(defun c-extend-font-lock-region-for-macros (begg endd &optional old-len)
- ;; Extend the region (BEGG ENDD) to cover all (possibly changed)
- ;; preprocessor macros; return the cons (new-BEG . new-END). OLD-LEN should
- ;; be either the old length parameter when called from an
- ;; after-change-function, or nil otherwise. This defun uses the variables
- ;; c-old-BOM, c-new-BOM.
+ (setq c-new-END (point)))
+
+(defun c-extend-font-lock-region-for-macros (begg endd old-len)
+ ;; Extend the region (c-new-BEG c-new-END) to cover all (possibly changed)
+ ;; preprocessor macros; The return value has no significance.
;;
;; Point is undefined on both entry and exit to this function. The buffer
;; will have been widened on entry.
- (let (limits new-beg new-end)
- (goto-char c-old-BOM) ; already set to old start of macro or begg.
- (setq new-beg
- (min begg
- (if (setq limits (c-state-literal-at (point)))
- (cdr limits) ; go forward out of any string or comment.
- (point))))
-
- (goto-char endd)
- (if (setq limits (c-state-literal-at (point)))
- (goto-char (car limits))) ; go backward out of any string or comment.
- (if (c-beginning-of-macro)
- (c-end-of-macro))
- (setq new-end (max endd
- (if old-len
- (+ (- c-old-EOM old-len) (- endd begg))
- c-old-EOM)
- (point)))
- (cons new-beg new-end)))
+ ;;
+ ;; This function is in the C/C++/ObjC value of `c-before-font-lock-functions'.
+ (goto-char endd)
+ (if (c-beginning-of-macro)
+ (c-end-of-macro))
+ (setq c-new-END (max endd c-new-END (point)))
+ ;; Determine the region, (c-new-BEG c-new-END), which will get font
+ ;; locked. This restricts the region should there be long macros.
+ (setq c-new-BEG (max c-new-BEG (c-determine-limit 500 begg))
+ c-new-END (min c-new-END (c-determine-+ve-limit 500 endd))))
(defun c-neutralize-CPP-line (beg end)
;; BEG and END bound a region, typically a preprocessor line. Put a
(t nil)))))))
(defun c-neutralize-syntax-in-and-mark-CPP (begg endd old-len)
- ;; (i) Extend the font lock region to cover all changed preprocessor
- ;; regions; it does this by setting the variables `c-new-BEG' and
- ;; `c-new-END' to the new boundaries.
- ;;
- ;; (ii) "Neutralize" every preprocessor line wholly or partially in the
- ;; extended changed region. "Restore" lines which were CPP lines before the
- ;; change and are no longer so; these can be located from the Buffer local
- ;; variables `c-old-BOM' and `c-old-EOM'.
+ ;; (i) "Neutralize" every preprocessor line wholly or partially in the
+ ;; changed region. "Restore" lines which were CPP lines before the change
+ ;; and are no longer so.
;;
- ;; (iii) Mark every CPP construct by placing a `category' property value
+ ;; (ii) Mark each CPP construct by placing a `category' property value
;; `c-cpp-delimiter' at its start and end. The marked characters are the
;; opening # and usually the terminating EOL, but sometimes the character
- ;; before a comment/string delimiter.
+ ;; before a comment delimiter.
;;
;; That is, set syntax-table properties on characters that would otherwise
;; interact syntactically with those outside the CPP line(s).
;; Note: SPEED _MATTERS_ IN THIS FUNCTION!!!
;;
;; This function might make hidden buffer changes.
- (c-save-buffer-state (new-bounds)
- ;; First determine the region, (c-new-BEG c-new-END), which will get font
- ;; locked. It might need "neutralizing". This region may not start
- ;; 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 (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-save-buffer-state (limits )
+ ;; Clear 'syntax-table properties "punctuation":
(c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
;; CPP "comment" markers:
;; Add needed properties to each CPP construct in the region.
(goto-char c-new-BEG)
+ (if (setq limits (c-literal-limits)) ; Go past any literal.
+ (goto-char (cdr limits)))
(skip-chars-backward " \t")
(let ((pps-position (point)) pps-state mbeg)
(while (and (< (point) c-new-END)
(nth 4 pps-state)))) ; in a comment?
(goto-char (match-beginning 1))
(setq mbeg (point))
- (if (> (c-syntactic-end-of-macro) mbeg)
+ (if (> (c-no-comment-end-of-macro) mbeg)
(progn
(c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
(if (eval-when-compile
(backward-char)) ; back over (, [, <.
(and (/= new-pos pos) new-pos)))
-(defun c-change-expand-fl-region (beg end old-len)
+(defun c-change-expand-fl-region (_beg _end _old-len)
;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
;; region. This will usually be the smallest sequence of whole lines
;; containing `c-new-BEG' and `c-new-END', but if `c-new-BEG' is in a
;;
;; This is called from an after-change-function, but the parameters BEG END
;; and OLD-LEN are not used.
- (if font-lock-mode
- (setq c-new-BEG
- (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
- c-new-END (c-point 'bonl c-new-END))))
+ (if font-lock-mode
+ (setq c-new-BEG
+ (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
+ c-new-END
+ (save-excursion
+ (goto-char c-new-END)
+ (if (bolp)
+ (point)
+ (c-point 'bonl c-new-END))))))
(defun c-context-expand-fl-region (beg end)
;; Return a cons (NEW-BEG . NEW-END), where NEW-BEG is the beginning of a
Key bindings:
\\{c-mode-map}"
+ :after-hook (progn (c-make-noise-macro-regexps)
+ (c-make-macro-with-semi-re)
+ (c-update-modeline))
(c-initialize-cc-mode t)
- (set-syntax-table c-mode-syntax-table)
- (setq local-abbrev-table c-mode-abbrev-table
- abbrev-mode t)
- (use-local-map c-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'c-mode)
- (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
(cc-imenu-init cc-imenu-c-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for C++
Key bindings:
\\{c++-mode-map}"
+ :after-hook (progn (c-make-noise-macro-regexps)
+ (c-make-macro-with-semi-re)
+ (c-update-modeline))
(c-initialize-cc-mode t)
- (set-syntax-table c++-mode-syntax-table)
- (setq local-abbrev-table c++-mode-abbrev-table
- abbrev-mode t)
- (use-local-map c++-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'c++-mode)
- (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'c++-mode)
(easy-menu-add c-c++-menu)
(cc-imenu-init cc-imenu-c++-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for Objective-C
Key bindings:
\\{objc-mode-map}"
+ :after-hook (progn (c-make-noise-macro-regexps)
+ (c-make-macro-with-semi-re)
+ (c-update-modeline))
(c-initialize-cc-mode t)
- (set-syntax-table objc-mode-syntax-table)
- (setq local-abbrev-table objc-mode-abbrev-table
- abbrev-mode t)
- (use-local-map objc-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'objc-mode)
- (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'objc-mode)
(easy-menu-add c-objc-menu)
(cc-imenu-init nil 'cc-imenu-objc-function)
- (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for Java
Key bindings:
\\{java-mode-map}"
+ :after-hook (c-update-modeline)
(c-initialize-cc-mode t)
- (set-syntax-table java-mode-syntax-table)
- (setq local-abbrev-table java-mode-abbrev-table
- abbrev-mode t)
- (use-local-map java-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'java-mode)
(c-common-init 'java-mode)
(easy-menu-add c-java-menu)
(cc-imenu-init cc-imenu-java-generic-expression)
- (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for CORBA's IDL language
Key bindings:
\\{idl-mode-map}"
+ :after-hook (c-update-modeline)
(c-initialize-cc-mode t)
- (set-syntax-table idl-mode-syntax-table)
- (setq local-abbrev-table idl-mode-abbrev-table)
- (use-local-map idl-mode-map)
(c-init-language-vars-for 'idl-mode)
(c-common-init 'idl-mode)
(easy-menu-add c-idl-menu)
;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
- (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for Pike
Key bindings:
\\{pike-mode-map}"
+ :after-hook (c-update-modeline)
(c-initialize-cc-mode t)
- (set-syntax-table pike-mode-syntax-table)
- (setq local-abbrev-table pike-mode-abbrev-table
- abbrev-mode t)
- (use-local-map pike-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'pike-mode)
(c-common-init 'pike-mode)
(easy-menu-add c-pike-menu)
;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
- (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; Support for AWK
(defvar awk-mode-map
(let ((map (c-make-inherited-keymap)))
;; Add bindings which are only useful for awk.
- (define-key map "#" 'self-insert-command)
- (define-key map "/" 'self-insert-command)
- (define-key map "*" 'self-insert-command)
+ (define-key map "#" 'self-insert-command);Overrides electric parent binding.
+ (define-key map "/" 'self-insert-command);Overrides electric parent binding.
+ (define-key map "*" 'self-insert-command);Overrides electric parent binding.
(define-key map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
(define-key map "\C-c\C-p" 'undefined)
(define-key map "\C-c\C-u" 'undefined)
Key bindings:
\\{awk-mode-map}"
+ :after-hook (c-update-modeline)
;; We need the next line to stop the macro defining
;; `awk-mode-syntax-table'. This would mask the real table which is
;; declared in cc-awk.el and hasn't yet been loaded.
:syntax-table nil
(require 'cc-awk) ; Added 2003/6/10.
(c-initialize-cc-mode t)
- (set-syntax-table awk-mode-syntax-table)
- (setq local-abbrev-table awk-mode-abbrev-table
- abbrev-mode t)
- (use-local-map awk-mode-map)
+ (setq abbrev-mode t)
(c-init-language-vars-for 'awk-mode)
(c-common-init 'awk-mode)
(c-awk-unstick-NL-prop)
-
- (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
- (c-update-modeline))
+ (c-run-mode-hooks 'c-mode-common-hook))
\f
;; bug reporting