Mercurial > emacs
comparison lisp/progmodes/cc-mode.el @ 90320:8a1ee48a8386
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-26
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 119-122)
- Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 26 Feb 2006 07:09:24 +0000 |
parents | 4b3d39451150 3d8b060d10fb |
children | 8a8e69664178 |
comparison
equal
deleted
inserted
replaced
90319:c6cf8c705e11 | 90320:8a1ee48a8386 |
---|---|
1 ;;; cc-mode.el --- major mode for editing C and similar languages | 1 ;;; cc-mode.el --- major mode for editing C and similar languages |
2 | 2 |
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 | 3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 Free Software |
4 ;; Free Software Foundation, Inc. | 4 ;; Foundation, Inc. |
5 | 5 |
6 ;; Authors: 2003- Alan Mackenzie | 6 ;; Authors: 2003- Alan Mackenzie |
7 ;; 1998- Martin Stjernholm | 7 ;; 1998- Martin Stjernholm |
8 ;; 1992-1999 Barry A. Warsaw | 8 ;; 1992-1999 Barry A. Warsaw |
9 ;; 1987 Dave Detlefs and Stewart Clamen | 9 ;; 1987 Dave Detlefs and Stewart Clamen |
240 (if normal-erase-is-backspace | 240 (if normal-erase-is-backspace |
241 (progn | 241 (progn |
242 (define-key c-mode-base-map (kbd "C-c C-<delete>") | 242 (define-key c-mode-base-map (kbd "C-c C-<delete>") |
243 'c-hungry-delete-forward) | 243 'c-hungry-delete-forward) |
244 (define-key c-mode-base-map (kbd "C-c C-<backspace>") | 244 (define-key c-mode-base-map (kbd "C-c C-<backspace>") |
245 'c-hungry-backspace)) | 245 'c-hungry-delete-backwards)) |
246 (define-key c-mode-base-map (kbd "C-c C-<delete>") | 246 (define-key c-mode-base-map (kbd "C-c C-<delete>") |
247 'c-hungry-backspace) | 247 'c-hungry-delete-backwards) |
248 (define-key c-mode-base-map (kbd "C-c C-<backspace>") | 248 (define-key c-mode-base-map (kbd "C-c C-<backspace>") |
249 'c-hungry-delete-forward))) | 249 'c-hungry-delete-forward))) |
250 | 250 |
251 (if c-mode-base-map | 251 (if c-mode-base-map |
252 nil | 252 nil |
302 ;; We bind the forward deletion key and (implicitly) C-d to | 302 ;; We bind the forward deletion key and (implicitly) C-d to |
303 ;; `c-electric-delete-forward', and the backward deletion key to | 303 ;; `c-electric-delete-forward', and the backward deletion key to |
304 ;; `c-electric-backspace'. The hungry variants are bound to the | 304 ;; `c-electric-backspace'. The hungry variants are bound to the |
305 ;; same keys but prefixed with C-c. This implies that C-c C-d is | 305 ;; same keys but prefixed with C-c. This implies that C-c C-d is |
306 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c | 306 ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c |
307 ;; <backspace> to `c-hungry-backspace' but also C-c C-<backspace>, | 307 ;; <backspace> to `c-hungry-delete-backwards' but also |
308 ;; so that the Ctrl key can be held down during the whole sequence | 308 ;; C-c C-<backspace>, so that the Ctrl key can be held down during |
309 ;; regardless of the direction. This in turn implies that we bind | 309 ;; the whole sequence regardless of the direction. This in turn |
310 ;; C-c C-<delete> to `c-hungry-delete-forward', for the same reason. | 310 ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward', |
311 ;; for the same reason. | |
311 | 312 |
312 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21 | 313 ;; Bind the electric deletion functions to C-d and DEL. Emacs 21 |
313 ;; automatically maps the [delete] and [backspace] keys to these two | 314 ;; automatically maps the [delete] and [backspace] keys to these two |
314 ;; depending on window system and user preferences. (In earlier | 315 ;; depending on window system and user preferences. (In earlier |
315 ;; versions it's possible to do the same by using `function-key-map'.) | 316 ;; versions it's possible to do the same by using `function-key-map'.) |
316 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward) | 317 (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward) |
317 (define-key c-mode-base-map "\177" 'c-electric-backspace) | 318 (define-key c-mode-base-map "\177" 'c-electric-backspace) |
318 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward) | 319 (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward) |
319 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-backspace) | 320 (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-delete-backwards) |
320 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-backspace) | 321 (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-delete-backwards) |
321 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty. | 322 (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty. |
322 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty. | 323 (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty. |
323 'c-hungry-delete-forward) | 324 'c-hungry-delete-forward) |
324 (when (boundp 'normal-erase-is-backspace) | 325 (when (boundp 'normal-erase-is-backspace) |
325 ;; The automatic C-d and DEL mapping functionality doesn't extend | 326 ;; The automatic C-d and DEL mapping functionality doesn't extend |
337 ;; `c-electric-delete' and `c-hungry-delete' functions. | 338 ;; `c-electric-delete' and `c-hungry-delete' functions. |
338 (define-key c-mode-base-map [delete] 'c-electric-delete) | 339 (define-key c-mode-base-map [delete] 'c-electric-delete) |
339 (define-key c-mode-base-map [backspace] 'c-electric-backspace) | 340 (define-key c-mode-base-map [backspace] 'c-electric-backspace) |
340 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete) | 341 (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete) |
341 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete) | 342 (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete) |
342 (define-key c-mode-base-map (kbd "C-c <backspace>") 'c-hungry-backspace) | 343 (define-key c-mode-base-map (kbd "C-c <backspace>") |
343 (define-key c-mode-base-map (kbd "C-c C-<backspace>") 'c-hungry-backspace)) | 344 'c-hungry-delete-backwards) |
345 (define-key c-mode-base-map (kbd "C-c C-<backspace>") | |
346 'c-hungry-delete-backwards)) | |
344 | 347 |
345 (define-key c-mode-base-map "#" 'c-electric-pound) | 348 (define-key c-mode-base-map "#" 'c-electric-pound) |
346 (define-key c-mode-base-map "{" 'c-electric-brace) | 349 (define-key c-mode-base-map "{" 'c-electric-brace) |
347 (define-key c-mode-base-map "}" 'c-electric-brace) | 350 (define-key c-mode-base-map "}" 'c-electric-brace) |
348 (define-key c-mode-base-map "/" 'c-electric-slash) | 351 (define-key c-mode-base-map "/" 'c-electric-slash) |
412 (c-save-buffer-state () | 415 (c-save-buffer-state () |
413 ;; When `combine-after-change-calls' is used we might get calls | 416 ;; When `combine-after-change-calls' is used we might get calls |
414 ;; with regions outside the current narrowing. This has been | 417 ;; with regions outside the current narrowing. This has been |
415 ;; observed in Emacs 20.7. | 418 ;; observed in Emacs 20.7. |
416 (save-restriction | 419 (save-restriction |
417 (widen) | 420 (save-match-data ; c-recognize-<>-arglists changes match-data |
418 | 421 (widen) |
419 (when (> end (point-max)) | 422 |
420 ;; Some emacsen might return positions past the end. This has been | 423 (when (> end (point-max)) |
421 ;; observed in Emacs 20.7 when rereading a buffer changed on disk | 424 ;; Some emacsen might return positions past the end. This has been |
422 ;; (haven't been able to minimize it, but Emacs 21.3 appears to | 425 ;; observed in Emacs 20.7 when rereading a buffer changed on disk |
423 ;; work). | 426 ;; (haven't been able to minimize it, but Emacs 21.3 appears to |
424 (setq end (point-max)) | 427 ;; work). |
425 (when (> beg end) | 428 (setq end (point-max)) |
426 (setq beg end))) | 429 (when (> beg end) |
427 | 430 (setq beg end))) |
428 (c-invalidate-sws-region-after beg end) | 431 |
429 (c-invalidate-state-cache beg) | 432 (c-invalidate-sws-region-after beg end) |
430 (c-invalidate-find-decl-cache beg) | 433 (c-invalidate-state-cache beg) |
431 | 434 (c-invalidate-find-decl-cache beg) |
432 (when c-recognize-<>-arglists | 435 |
433 (c-after-change-check-<>-operators beg end))))) | 436 (when c-recognize-<>-arglists |
437 (c-after-change-check-<>-operators beg end)))))) | |
434 | 438 |
435 (defun c-basic-common-init (mode default-style) | 439 (defun c-basic-common-init (mode default-style) |
436 "Do the necessary initialization for the syntax handling routines | 440 "Do the necessary initialization for the syntax handling routines |
437 and the line breaking/filling code. Intended to be used by other | 441 and the line breaking/filling code. Intended to be used by other |
438 packages that embed CC Mode. | 442 packages that embed CC Mode. |
548 | 552 |
549 ;; setup the comment indent variable in a Emacs version portable way | 553 ;; setup the comment indent variable in a Emacs version portable way |
550 (make-local-variable 'comment-indent-function) | 554 (make-local-variable 'comment-indent-function) |
551 (setq comment-indent-function 'c-comment-indent) | 555 (setq comment-indent-function 'c-comment-indent) |
552 | 556 |
553 ;; Put submode indicators onto minor-mode-alist, but only once. | 557 ;; ;; Put submode indicators onto minor-mode-alist, but only once. |
554 (or (assq 'c-submode-indicators minor-mode-alist) | 558 ;; (or (assq 'c-submode-indicators minor-mode-alist) |
555 (setq minor-mode-alist | 559 ;; (setq minor-mode-alist |
556 (cons '(c-submode-indicators c-submode-indicators) | 560 ;; (cons '(c-submode-indicators c-submode-indicators) |
557 minor-mode-alist))) | 561 ;; minor-mode-alist))) |
562 (c-update-modeline) | |
558 | 563 |
559 ;; Install the functions that ensure that various internal caches | 564 ;; Install the functions that ensure that various internal caches |
560 ;; don't become invalid due to buffer changes. | 565 ;; don't become invalid due to buffer changes. |
561 (make-local-hook 'after-change-functions) | 566 (make-local-hook 'after-change-functions) |
562 (add-hook 'after-change-functions 'c-after-change nil t)) | 567 (add-hook 'after-change-functions 'c-after-change nil t)) |
626 (let ((rfn (assq mode c-require-final-newline))) | 631 (let ((rfn (assq mode c-require-final-newline))) |
627 (when rfn | 632 (when rfn |
628 (make-local-variable 'require-final-newline) | 633 (make-local-variable 'require-final-newline) |
629 (and (cdr rfn) | 634 (and (cdr rfn) |
630 (setq require-final-newline mode-require-final-newline))))) | 635 (setq require-final-newline mode-require-final-newline))))) |
636 | |
637 (defun c-remove-any-local-eval-or-mode-variables () | |
638 ;; If the buffer specifies `mode' or `eval' in its File Local Variable list | |
639 ;; or on the first line, remove all occurrences. See | |
640 ;; `c-postprocess-file-styles' for justification. There is no need to save | |
641 ;; point here, or even bother too much about the buffer contents. | |
642 ;; | |
643 ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables' | |
644 ;; in files.el. | |
645 (goto-char (point-max)) | |
646 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) | |
647 (let (lv-point (prefix "") (suffix "")) | |
648 (when (let ((case-fold-search t)) | |
649 (search-forward "Local Variables:" nil t)) | |
650 (setq lv-point (point)) | |
651 ;; The prefix is what comes before "local variables:" in its line. | |
652 ;; The suffix is what comes after "local variables:" in its line. | |
653 (skip-chars-forward " \t") | |
654 (or (eolp) | |
655 (setq suffix (buffer-substring (point) | |
656 (progn (end-of-line) (point))))) | |
657 (goto-char (match-beginning 0)) | |
658 (or (bolp) | |
659 (setq prefix | |
660 (buffer-substring (point) | |
661 (progn (beginning-of-line) (point))))) | |
662 | |
663 (while (search-forward-regexp | |
664 (concat "^[ \t]*" | |
665 (regexp-quote prefix) | |
666 "\\(mode\\|eval\\):.*" | |
667 (regexp-quote suffix) | |
668 "$") | |
669 nil t) | |
670 (beginning-of-line) | |
671 (kill-line 1))) | |
672 | |
673 ;; Delete the first line, if we've got one, in case it contains a mode spec. | |
674 (unless (and lv-point | |
675 (progn (goto-char lv-point) | |
676 (forward-line 0) | |
677 (bobp))) | |
678 (goto-char (point-min)) | |
679 (unless (eobp) | |
680 (kill-line 1))))) | |
631 | 681 |
632 (defun c-postprocess-file-styles () | 682 (defun c-postprocess-file-styles () |
633 "Function that post processes relevant file local variables in CC Mode. | 683 "Function that post processes relevant file local variables in CC Mode. |
634 Currently, this function simply applies any style and offset settings | 684 Currently, this function simply applies any style and offset settings |
635 found in the file's Local Variable list. It first applies any style | 685 found in the file's Local Variable list. It first applies any style |
654 ;; Problem: The file local variable block might have explicitly set a | 704 ;; Problem: The file local variable block might have explicitly set a |
655 ;; style variable. The `c-set-style' or `mapcar' call might have | 705 ;; style variable. The `c-set-style' or `mapcar' call might have |
656 ;; overwritten this. So we run `hack-local-variables' again to remedy | 706 ;; overwritten this. So we run `hack-local-variables' again to remedy |
657 ;; this. There are no guarantees this will work properly, particularly as | 707 ;; this. There are no guarantees this will work properly, particularly as |
658 ;; we have no control over what the other hook functions on | 708 ;; we have no control over what the other hook functions on |
659 ;; `hack-local-variables-hook' would have done, or what any "eval" | 709 ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove |
660 ;; expression will do when evaluated again. C'est la vie! ACM, | 710 ;; any `eval' or `mode' expressions before we evaluate again (see below). |
661 ;; 2005/11/2. | 711 ;; ACM, 2005/11/2. |
712 ;; | |
713 ;; Problem (bug reported by Gustav Broberg): if one of the variables is | |
714 ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc. | |
715 ;; We prevent this by temporarily removing `mode' from the Local Variables | |
716 ;; section. | |
662 (if (or c-file-style c-file-offsets) | 717 (if (or c-file-style c-file-offsets) |
663 (let ((hack-local-variables-hook nil)) | 718 (c-tentative-buffer-changes |
664 (hack-local-variables))))) | 719 (let ((hack-local-variables-hook nil)) |
720 (c-remove-any-local-eval-or-mode-variables) | |
721 (hack-local-variables)) | |
722 nil)))) | |
665 | 723 |
666 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) | 724 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles) |
667 | 725 |
668 (defmacro c-run-mode-hooks (&rest hooks) | 726 (defmacro c-run-mode-hooks (&rest hooks) |
669 ;; Emacs 21.1 has introduced a system with delayed mode hooks that | 727 ;; Emacs 21.1 has introduced a system with delayed mode hooks that |