PageRenderTime 59ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/emacs/elisp/cc-mode.el

http://inkedmn.googlecode.com/
Emacs Lisp | 1306 lines | 798 code | 176 blank | 332 comment | 21 complexity | 6aac3ccd781549716fc4cb7be990cee4 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. ;;; cc-mode.el --- major mode for editing C and similar languages
  2. ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 Free Software
  3. ;; Foundation, Inc.
  4. ;; Authors: 2003- Alan Mackenzie
  5. ;; 1998- Martin Stjernholm
  6. ;; 1992-1999 Barry A. Warsaw
  7. ;; 1987 Dave Detlefs and Stewart Clamen
  8. ;; 1985 Richard M. Stallman
  9. ;; Maintainer: bug-cc-mode@gnu.org
  10. ;; Created: a long, long, time ago. adapted from the original c-mode.el
  11. ;; Keywords: c languages oop
  12. ;; This file is part of GNU Emacs.
  13. ;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;; it under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17. ;; GNU Emacs is distributed in the hope that it will be useful,
  18. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;; GNU General Public License for more details.
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with this program; see the file COPYING. If not, write to
  23. ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  24. ;; Boston, MA 02110-1301, USA.
  25. ;;; Commentary:
  26. ;; NOTE: Read the commentary below for the right way to submit bug reports!
  27. ;; NOTE: See the accompanying texinfo manual for details on using this mode!
  28. ;; Note: The version string is in cc-defs.
  29. ;; This package provides GNU Emacs major modes for editing C, C++,
  30. ;; Objective-C, Java, CORBA's IDL, Pike and AWK code. As of the
  31. ;; latest Emacs and XEmacs releases, it is the default package for
  32. ;; editing these languages. This package is called "CC Mode", and
  33. ;; should be spelled exactly this way.
  34. ;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
  35. ;; CORBA's IDL, Pike and AWK with a consistent indentation model
  36. ;; across all modes. This indentation model is intuitive and very
  37. ;; flexible, so that almost any desired style of indentation can be
  38. ;; supported. Installation, usage, and programming details are
  39. ;; contained in an accompanying texinfo manual.
  40. ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
  41. ;; cplus-md1.el..
  42. ;; To submit bug reports, type "C-c C-b". These will be sent to
  43. ;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
  44. ;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
  45. ;; contacts the CC Mode maintainers. Questions can sent to
  46. ;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
  47. ;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
  48. ;; personal accounts; we reserve the right to ignore such email!
  49. ;; Many, many thanks go out to all the folks on the beta test list.
  50. ;; Without their patience, testing, insight, code contributions, and
  51. ;; encouragement CC Mode would be a far inferior package.
  52. ;; You can get the latest version of CC Mode, including PostScript
  53. ;; documentation and separate individual files from:
  54. ;;
  55. ;; http://cc-mode.sourceforge.net/
  56. ;;
  57. ;; You can join a moderated CC Mode announcement-only mailing list by
  58. ;; visiting
  59. ;;
  60. ;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
  61. ;;; Code:
  62. (eval-when-compile
  63. (let ((load-path
  64. (if (and (boundp 'byte-compile-dest-file)
  65. (stringp byte-compile-dest-file))
  66. (cons (file-name-directory byte-compile-dest-file) load-path)
  67. load-path)))
  68. (load "cc-bytecomp" nil t)))
  69. (cc-require 'cc-defs)
  70. (cc-require-when-compile 'cc-langs)
  71. (cc-require 'cc-vars)
  72. (cc-require 'cc-engine)
  73. (cc-require 'cc-styles)
  74. (cc-require 'cc-cmds)
  75. (cc-require 'cc-align)
  76. (cc-require 'cc-menus)
  77. ;; Silence the compiler.
  78. (cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
  79. (cc-bytecomp-defun set-keymap-parents) ; XEmacs
  80. (cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
  81. (cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
  82. ;; We set these variables during mode init, yet we don't require
  83. ;; font-lock.
  84. (cc-bytecomp-defvar font-lock-defaults)
  85. (cc-bytecomp-defvar font-lock-syntactic-keywords)
  86. ;; Menu support for both XEmacs and Emacs. If you don't have easymenu
  87. ;; with your version of Emacs, you are incompatible!
  88. (cc-external-require 'easymenu)
  89. ;; Autoload directive for emacsen that doesn't have an older CC Mode
  90. ;; version in the dist.
  91. (autoload 'c-subword-mode "cc-subword"
  92. "Mode enabling subword movement and editing keys." t)
  93. ;; Load cc-fonts first after font-lock is loaded, since it isn't
  94. ;; necessary until font locking is requested.
  95. (eval-after-load "font-lock"
  96. '(require 'cc-fonts))
  97. ;; cc-langs isn't loaded when we're byte compiled, so add autoload
  98. ;; directives for the interface functions.
  99. (autoload 'c-make-init-lang-vars-fun "cc-langs")
  100. (autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
  101. ;; Other modes and packages which depend on CC Mode should do the
  102. ;; following to make sure everything is loaded and available for their
  103. ;; use:
  104. ;;
  105. ;; (require 'cc-mode)
  106. ;;
  107. ;; And in the major mode function:
  108. ;;
  109. ;; (c-initialize-cc-mode t)
  110. ;; (c-init-language-vars some-mode)
  111. ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
  112. ;;
  113. ;; If you're not writing a derived mode using the language variable
  114. ;; system, then some-mode is one of the language modes directly
  115. ;; supported by CC Mode. You can then use (c-init-language-vars-for
  116. ;; 'some-mode) instead of `c-init-language-vars'.
  117. ;; `c-init-language-vars-for' is a function that avoids the rather
  118. ;; large expansion of `c-init-language-vars'.
  119. ;;
  120. ;; If you use `c-basic-common-init' then you might want to call
  121. ;; `c-font-lock-init' too to set up CC Mode's font lock support.
  122. ;;
  123. ;; See cc-langs.el for further info. A small example of a derived mode
  124. ;; is also available at <http://cc-mode.sourceforge.net/
  125. ;; derived-mode-ex.el>.
  126. (defun c-leave-cc-mode-mode ()
  127. (setq c-buffer-is-cc-mode nil))
  128. (defun c-init-language-vars-for (mode)
  129. "Initialize the language variables for one of the language modes
  130. directly supported by CC Mode. This can be used instead of the
  131. `c-init-language-vars' macro if the language you want to use is one of
  132. those, rather than a derived language defined through the language
  133. variable system (see \"cc-langs.el\")."
  134. (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
  135. ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
  136. ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
  137. ((eq mode 'java-mode) (c-init-language-vars java-mode))
  138. ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
  139. ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
  140. ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
  141. (t (error "Unsupported mode %s" mode))))
  142. ;;;###autoload
  143. (defun c-initialize-cc-mode (&optional new-style-init)
  144. "Initialize CC Mode for use in the current buffer.
  145. If the optional NEW-STYLE-INIT is nil or left out then all necessary
  146. initialization to run CC Mode for the C language is done. Otherwise
  147. only some basic setup is done, and a call to `c-init-language-vars' or
  148. `c-init-language-vars-for' is necessary too (which gives more
  149. control). See \"cc-mode.el\" for more info."
  150. (setq c-buffer-is-cc-mode t)
  151. (let ((initprop 'cc-mode-is-initialized)
  152. c-initialization-ok)
  153. (unless (get 'c-initialize-cc-mode initprop)
  154. (unwind-protect
  155. (progn
  156. (put 'c-initialize-cc-mode initprop t)
  157. (c-initialize-builtin-style)
  158. (run-hooks 'c-initialization-hook)
  159. ;; Fix obsolete variables.
  160. (if (boundp 'c-comment-continuation-stars)
  161. (setq c-block-comment-prefix c-comment-continuation-stars))
  162. (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
  163. (setq c-initialization-ok t))
  164. ;; Will try initialization hooks again if they failed.
  165. (put 'c-initialize-cc-mode initprop c-initialization-ok))))
  166. (unless new-style-init
  167. (c-init-language-vars-for 'c-mode)))
  168. ;;; Common routines.
  169. (defvar c-mode-base-map ()
  170. "Keymap shared by all CC Mode related modes.")
  171. (defun c-make-inherited-keymap ()
  172. (let ((map (make-sparse-keymap)))
  173. ;; Necessary to use `cc-bytecomp-fboundp' below since this
  174. ;; function is called from top-level forms that are evaluated
  175. ;; while cc-bytecomp is active when one does M-x eval-buffer.
  176. (cond
  177. ;; XEmacs
  178. ((cc-bytecomp-fboundp 'set-keymap-parents)
  179. (set-keymap-parents map c-mode-base-map))
  180. ;; Emacs
  181. ((cc-bytecomp-fboundp 'set-keymap-parent)
  182. (set-keymap-parent map c-mode-base-map))
  183. ;; incompatible
  184. (t (error "CC Mode is incompatible with this version of Emacs")))
  185. map))
  186. (defun c-define-abbrev-table (name defs)
  187. ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
  188. ;; sixth argument for SYSTEM-FLAG in emacsen that support it
  189. ;; (currently only Emacs >= 21.2).
  190. (let ((table (or (symbol-value name)
  191. (progn (define-abbrev-table name nil)
  192. (symbol-value name)))))
  193. (while defs
  194. (condition-case nil
  195. (apply 'define-abbrev table (append (car defs) '(t)))
  196. (wrong-number-of-arguments
  197. (apply 'define-abbrev table (car defs))))
  198. (setq defs (cdr defs)))))
  199. (put 'c-define-abbrev-table 'lisp-indent-function 1)
  200. (defun c-bind-special-erase-keys ()
  201. ;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
  202. ;; to the proper keys depending on `normal-erase-is-backspace'.
  203. (if normal-erase-is-backspace
  204. (progn
  205. (define-key c-mode-base-map (kbd "C-c C-<delete>")
  206. 'c-hungry-delete-forward)
  207. (define-key c-mode-base-map (kbd "C-c C-<backspace>")
  208. 'c-hungry-delete-backwards))
  209. (define-key c-mode-base-map (kbd "C-c C-<delete>")
  210. 'c-hungry-delete-backwards)
  211. (define-key c-mode-base-map (kbd "C-c C-<backspace>")
  212. 'c-hungry-delete-forward)))
  213. (if c-mode-base-map
  214. nil
  215. (setq c-mode-base-map (make-sparse-keymap))
  216. ;; Separate M-BS from C-M-h. The former should remain
  217. ;; backward-kill-word.
  218. (define-key c-mode-base-map [(control meta h)] 'c-mark-function)
  219. (define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
  220. (substitute-key-definition 'backward-sentence
  221. 'c-beginning-of-statement
  222. c-mode-base-map global-map)
  223. (substitute-key-definition 'forward-sentence
  224. 'c-end-of-statement
  225. c-mode-base-map global-map)
  226. (substitute-key-definition 'indent-new-comment-line
  227. 'c-indent-new-comment-line
  228. c-mode-base-map global-map)
  229. (substitute-key-definition 'indent-for-tab-command
  230. 'c-indent-command
  231. c-mode-base-map global-map)
  232. (when (fboundp 'comment-indent-new-line)
  233. ;; indent-new-comment-line has changed name to
  234. ;; comment-indent-new-line in Emacs 21.
  235. (substitute-key-definition 'comment-indent-new-line
  236. 'c-indent-new-comment-line
  237. c-mode-base-map global-map))
  238. ;; RMS says don't make these the default.
  239. ;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
  240. ;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
  241. (define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
  242. (define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
  243. (define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
  244. ;; It doesn't suffice to put `c-fill-paragraph' on
  245. ;; `fill-paragraph-function' since `c-fill-paragraph' must be called
  246. ;; before any fill prefix adaption is done. E.g. `filladapt-mode'
  247. ;; replaces `fill-paragraph' and does the adaption before calling
  248. ;; `fill-paragraph-function', and we have to mask comments etc
  249. ;; before that. Also, `c-fill-paragraph' chains on to
  250. ;; `fill-paragraph' and the value on `fill-parapgraph-function' to
  251. ;; do the actual filling work.
  252. (substitute-key-definition 'fill-paragraph 'c-fill-paragraph
  253. c-mode-base-map global-map)
  254. ;; In XEmacs the default fill function is called
  255. ;; fill-paragraph-or-region.
  256. (substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
  257. c-mode-base-map global-map)
  258. ;; We bind the forward deletion key and (implicitly) C-d to
  259. ;; `c-electric-delete-forward', and the backward deletion key to
  260. ;; `c-electric-backspace'. The hungry variants are bound to the
  261. ;; same keys but prefixed with C-c. This implies that C-c C-d is
  262. ;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
  263. ;; <backspace> to `c-hungry-delete-backwards' but also
  264. ;; C-c C-<backspace>, so that the Ctrl key can be held down during
  265. ;; the whole sequence regardless of the direction. This in turn
  266. ;; implies that we bind C-c C-<delete> to `c-hungry-delete-forward',
  267. ;; for the same reason.
  268. ;; Bind the electric deletion functions to C-d and DEL. Emacs 21
  269. ;; automatically maps the [delete] and [backspace] keys to these two
  270. ;; depending on window system and user preferences. (In earlier
  271. ;; versions it's possible to do the same by using `function-key-map'.)
  272. (define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
  273. (define-key c-mode-base-map "\177" 'c-electric-backspace)
  274. (define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward)
  275. (define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-delete-backwards)
  276. (define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-delete-backwards)
  277. (define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty.
  278. (define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty.
  279. 'c-hungry-delete-forward)
  280. (when (boundp 'normal-erase-is-backspace)
  281. ;; The automatic C-d and DEL mapping functionality doesn't extend
  282. ;; to special combinations like C-c C-<delete>, so we have to hook
  283. ;; into the `normal-erase-is-backspace' system to bind it directly
  284. ;; as appropriate.
  285. (add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys)
  286. (c-bind-special-erase-keys))
  287. (when (fboundp 'delete-forward-p)
  288. ;; In XEmacs we fix the forward and backward deletion behavior by
  289. ;; binding the keysyms for the [delete] and [backspace] keys
  290. ;; directly, and use `delete-forward-p' to decide what [delete]
  291. ;; should do. That's done in the XEmacs specific
  292. ;; `c-electric-delete' and `c-hungry-delete' functions.
  293. (define-key c-mode-base-map [delete] 'c-electric-delete)
  294. (define-key c-mode-base-map [backspace] 'c-electric-backspace)
  295. (define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
  296. (define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
  297. (define-key c-mode-base-map (kbd "C-c <backspace>")
  298. 'c-hungry-delete-backwards)
  299. (define-key c-mode-base-map (kbd "C-c C-<backspace>")
  300. 'c-hungry-delete-backwards))
  301. (define-key c-mode-base-map "#" 'c-electric-pound)
  302. (define-key c-mode-base-map "{" 'c-electric-brace)
  303. (define-key c-mode-base-map "}" 'c-electric-brace)
  304. (define-key c-mode-base-map "/" 'c-electric-slash)
  305. (define-key c-mode-base-map "*" 'c-electric-star)
  306. (define-key c-mode-base-map ";" 'c-electric-semi&comma)
  307. (define-key c-mode-base-map "," 'c-electric-semi&comma)
  308. (define-key c-mode-base-map ":" 'c-electric-colon)
  309. (define-key c-mode-base-map "(" 'c-electric-paren)
  310. (define-key c-mode-base-map ")" 'c-electric-paren)
  311. (define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
  312. (define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
  313. (define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
  314. (define-key c-mode-base-map "\C-c\C-c" 'comment-region)
  315. (define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
  316. (define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
  317. (define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
  318. (define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
  319. ;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
  320. (define-key c-mode-base-map "\C-c." 'c-set-style)
  321. ;; conflicts with OOBR
  322. ;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
  323. ;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
  324. (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
  325. )
  326. ;; We don't require the outline package, but we configure it a bit anyway.
  327. (cc-bytecomp-defvar outline-level)
  328. (defun c-mode-menu (modestr)
  329. "Return a menu spec suitable for `easy-menu-define' that is exactly
  330. like the C mode menu except that the menu bar item name is MODESTR
  331. instead of \"C\".
  332. This function is provided for compatibility only; derived modes should
  333. preferably use the `c-mode-menu' language constant directly."
  334. (cons modestr (c-lang-const c-mode-menu c)))
  335. ;; Ugly hack to pull in the definition of `c-populate-syntax-table'
  336. ;; from cc-langs to make it available at runtime. It's either this or
  337. ;; moving the definition for it to cc-defs, but that would mean to
  338. ;; break up the syntax table setup over two files.
  339. (defalias 'c-populate-syntax-table
  340. (cc-eval-when-compile
  341. (let ((f (symbol-function 'c-populate-syntax-table)))
  342. (if (byte-code-function-p f) f (byte-compile f)))))
  343. ;; CAUTION: Try to avoid installing things on
  344. ;; `before-change-functions'. The macro `combine-after-change-calls'
  345. ;; is used and it doesn't work if there are things on that hook. That
  346. ;; can cause font lock functions to run in inconvenient places during
  347. ;; temporary changes in some font lock support modes, causing extra
  348. ;; unnecessary work and font lock glitches due to interactions between
  349. ;; various text properties.
  350. (defun c-after-change (beg end len)
  351. ;; Function put on `after-change-functions' to adjust various caches
  352. ;; etc. Prefer speed to finesse here, since there will be an order
  353. ;; of magnitude more calls to this function than any of the
  354. ;; functions that use the caches.
  355. ;;
  356. ;; Note that care must be taken so that this is called before any
  357. ;; font-lock callbacks since we might get calls to functions using
  358. ;; these caches from inside them, and we must thus be sure that this
  359. ;; has already been executed.
  360. (c-save-buffer-state ()
  361. ;; When `combine-after-change-calls' is used we might get calls
  362. ;; with regions outside the current narrowing. This has been
  363. ;; observed in Emacs 20.7.
  364. (save-restriction
  365. (save-match-data ; c-recognize-<>-arglists changes match-data
  366. (widen)
  367. (when (> end (point-max))
  368. ;; Some emacsen might return positions past the end. This has been
  369. ;; observed in Emacs 20.7 when rereading a buffer changed on disk
  370. ;; (haven't been able to minimize it, but Emacs 21.3 appears to
  371. ;; work).
  372. (setq end (point-max))
  373. (when (> beg end)
  374. (setq beg end)))
  375. (c-invalidate-sws-region-after beg end)
  376. (c-invalidate-state-cache beg)
  377. (c-invalidate-find-decl-cache beg)
  378. (when c-recognize-<>-arglists
  379. (c-after-change-check-<>-operators beg end))))))
  380. (defun c-basic-common-init (mode default-style)
  381. "Do the necessary initialization for the syntax handling routines
  382. and the line breaking/filling code. Intended to be used by other
  383. packages that embed CC Mode.
  384. MODE is the CC Mode flavor to set up, e.g. 'c-mode or 'java-mode.
  385. DEFAULT-STYLE tells which indentation style to install. It has the
  386. same format as `c-default-style'.
  387. Note that `c-init-language-vars' must be called before this function.
  388. This function cannot do that since `c-init-language-vars' is a macro
  389. that requires a literal mode spec at compile time."
  390. (setq c-buffer-is-cc-mode mode)
  391. ;; these variables should always be buffer local; they do not affect
  392. ;; indentation style.
  393. (make-local-variable 'parse-sexp-ignore-comments)
  394. (make-local-variable 'indent-line-function)
  395. (make-local-variable 'indent-region-function)
  396. (make-local-variable 'normal-auto-fill-function)
  397. (make-local-variable 'comment-start)
  398. (make-local-variable 'comment-end)
  399. (make-local-variable 'comment-start-skip)
  400. (make-local-variable 'comment-multi-line)
  401. (make-local-variable 'comment-line-break-function)
  402. (make-local-variable 'paragraph-start)
  403. (make-local-variable 'paragraph-separate)
  404. (make-local-variable 'paragraph-ignore-fill-prefix)
  405. (make-local-variable 'adaptive-fill-mode)
  406. (make-local-variable 'adaptive-fill-regexp)
  407. ;; now set their values
  408. (setq parse-sexp-ignore-comments t
  409. indent-line-function 'c-indent-line
  410. indent-region-function 'c-indent-region
  411. normal-auto-fill-function 'c-do-auto-fill
  412. comment-multi-line t
  413. comment-line-break-function 'c-indent-new-comment-line)
  414. ;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
  415. ;; direct call to `fill-paragraph' behaves better. This still
  416. ;; doesn't work with filladapt but it's better than nothing.
  417. (make-local-variable 'fill-paragraph-function)
  418. (setq fill-paragraph-function 'c-fill-paragraph)
  419. (when (or c-recognize-<>-arglists
  420. (c-major-mode-is 'awk-mode))
  421. ;; We'll use the syntax-table text property to change the syntax
  422. ;; of some chars for this language, so do the necessary setup for
  423. ;; that.
  424. ;;
  425. ;; Note to other package developers: It's ok to turn this on in CC
  426. ;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
  427. ;; off if CC Mode has turned it on.
  428. ;; Emacs.
  429. (when (boundp 'parse-sexp-lookup-properties)
  430. (make-local-variable 'parse-sexp-lookup-properties)
  431. (setq parse-sexp-lookup-properties t))
  432. ;; Same as above for XEmacs.
  433. (when (boundp 'lookup-syntax-properties)
  434. (make-local-variable 'lookup-syntax-properties)
  435. (setq lookup-syntax-properties t)))
  436. ;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
  437. ;; property on each character.
  438. (when (boundp 'text-property-default-nonsticky)
  439. (make-local-variable 'text-property-default-nonsticky)
  440. (let ((elem (assq 'syntax-table text-property-default-nonsticky)))
  441. (if elem
  442. (setcdr elem t)
  443. (setq text-property-default-nonsticky
  444. (cons '(syntax-table . t)
  445. text-property-default-nonsticky))))
  446. (setq text-property-default-nonsticky
  447. (cons '(c-type . t)
  448. text-property-default-nonsticky)))
  449. ;; In Emacs 21 and later it's possible to turn off the ad-hoc
  450. ;; heuristic that open parens in column 0 are defun starters. Since
  451. ;; we have c-state-cache, that heuristic isn't useful and only causes
  452. ;; trouble, so turn it off.
  453. (when (memq 'col-0-paren c-emacs-features)
  454. (make-local-variable 'open-paren-in-column-0-is-defun-start)
  455. (setq open-paren-in-column-0-is-defun-start nil))
  456. (c-clear-found-types)
  457. ;; now set the mode style based on default-style
  458. (let ((style (if (stringp default-style)
  459. default-style
  460. (or (cdr (assq mode default-style))
  461. (cdr (assq 'other default-style))
  462. "gnu"))))
  463. ;; Override style variables if `c-old-style-variable-behavior' is
  464. ;; set. Also override if we are using global style variables,
  465. ;; have already initialized a style once, and are switching to a
  466. ;; different style. (It's doubtful whether this is desirable, but
  467. ;; the whole situation with nonlocal style variables is a bit
  468. ;; awkward. It's at least the most compatible way with the old
  469. ;; style init procedure.)
  470. (c-set-style style (not (or c-old-style-variable-behavior
  471. (and (not c-style-variables-are-local-p)
  472. c-indentation-style
  473. (not (string-equal c-indentation-style
  474. style)))))))
  475. (c-setup-paragraph-variables)
  476. ;; we have to do something special for c-offsets-alist so that the
  477. ;; buffer local value has its own alist structure.
  478. (setq c-offsets-alist (copy-alist c-offsets-alist))
  479. ;; setup the comment indent variable in a Emacs version portable way
  480. (make-local-variable 'comment-indent-function)
  481. (setq comment-indent-function 'c-comment-indent)
  482. ;; ;; Put submode indicators onto minor-mode-alist, but only once.
  483. ;; (or (assq 'c-submode-indicators minor-mode-alist)
  484. ;; (setq minor-mode-alist
  485. ;; (cons '(c-submode-indicators c-submode-indicators)
  486. ;; minor-mode-alist)))
  487. (c-update-modeline)
  488. ;; Install the functions that ensure that various internal caches
  489. ;; don't become invalid due to buffer changes.
  490. (make-local-hook 'after-change-functions)
  491. (add-hook 'after-change-functions 'c-after-change nil t))
  492. (defun c-after-font-lock-init ()
  493. ;; Put on `font-lock-mode-hook'.
  494. (remove-hook 'after-change-functions 'c-after-change t)
  495. (add-hook 'after-change-functions 'c-after-change nil t))
  496. (defun c-font-lock-init ()
  497. "Set up the font-lock variables for using the font-lock support in CC Mode.
  498. This does not load the font-lock package. Use after
  499. `c-basic-common-init' and after cc-fonts has been loaded."
  500. (make-local-variable 'font-lock-defaults)
  501. (setq font-lock-defaults
  502. `(,(if (c-major-mode-is 'awk-mode)
  503. ;; awk-mode currently has only one font lock level.
  504. 'awk-font-lock-keywords
  505. (mapcar 'c-mode-symbol
  506. '("font-lock-keywords" "font-lock-keywords-1"
  507. "font-lock-keywords-2" "font-lock-keywords-3")))
  508. nil nil
  509. ,c-identifier-syntax-modifications
  510. c-beginning-of-syntax
  511. (font-lock-lines-before . 1)
  512. (font-lock-mark-block-function
  513. . c-mark-function)))
  514. (make-local-hook 'font-lock-mode-hook)
  515. (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
  516. (defun c-setup-doc-comment-style ()
  517. "Initialize the variables that depend on the value of `c-doc-comment-style'."
  518. (when (and (featurep 'font-lock)
  519. (symbol-value 'font-lock-mode))
  520. ;; Force font lock mode to reinitialize itself.
  521. (font-lock-mode 0)
  522. (font-lock-mode 1)))
  523. (defun c-common-init (&optional mode)
  524. "Common initialization for all CC Mode modes.
  525. In addition to the work done by `c-basic-common-init' and
  526. `c-font-lock-init', this function sets up various other things as
  527. customary in CC Mode modes but which aren't strictly necessary for CC
  528. Mode to operate correctly.
  529. MODE is the symbol for the mode to initialize, like 'c-mode. See
  530. `c-basic-common-init' for details. It's only optional to be
  531. compatible with old code; callers should always specify it."
  532. (unless mode
  533. ;; Called from an old third party package. The fallback is to
  534. ;; initialize for C.
  535. (c-init-language-vars-for 'c-mode))
  536. (c-basic-common-init mode c-default-style)
  537. (when mode
  538. ;; Only initialize font locking if we aren't called from an old package.
  539. (c-font-lock-init))
  540. (make-local-variable 'outline-regexp)
  541. (make-local-variable 'outline-level)
  542. (setq outline-regexp "[^#\n\^M]"
  543. outline-level 'c-outline-level)
  544. (let ((rfn (assq mode c-require-final-newline)))
  545. (when rfn
  546. (make-local-variable 'require-final-newline)
  547. (and (cdr rfn)
  548. (setq require-final-newline mode-require-final-newline)))))
  549. (defun c-remove-any-local-eval-or-mode-variables ()
  550. ;; If the buffer specifies `mode' or `eval' in its File Local Variable list
  551. ;; or on the first line, remove all occurrences. See
  552. ;; `c-postprocess-file-styles' for justification. There is no need to save
  553. ;; point here, or even bother too much about the buffer contents.
  554. ;;
  555. ;; Most of the code here is derived from Emacs 21.3's `hack-local-variables'
  556. ;; in files.el.
  557. (goto-char (point-max))
  558. (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
  559. (let (lv-point (prefix "") (suffix ""))
  560. (when (let ((case-fold-search t))
  561. (search-forward "Local Variables:" nil t))
  562. (setq lv-point (point))
  563. ;; The prefix is what comes before "local variables:" in its line.
  564. ;; The suffix is what comes after "local variables:" in its line.
  565. (skip-chars-forward " \t")
  566. (or (eolp)
  567. (setq suffix (buffer-substring (point)
  568. (progn (end-of-line) (point)))))
  569. (goto-char (match-beginning 0))
  570. (or (bolp)
  571. (setq prefix
  572. (buffer-substring (point)
  573. (progn (beginning-of-line) (point)))))
  574. (while (search-forward-regexp
  575. (concat "^[ \t]*"
  576. (regexp-quote prefix)
  577. "\\(mode\\|eval\\):.*"
  578. (regexp-quote suffix)
  579. "$")
  580. nil t)
  581. (beginning-of-line)
  582. (kill-line 1)))
  583. ;; Delete the first line, if we've got one, in case it contains a mode spec.
  584. (unless (and lv-point
  585. (progn (goto-char lv-point)
  586. (forward-line 0)
  587. (bobp)))
  588. (goto-char (point-min))
  589. (unless (eobp)
  590. (kill-line 1)))))
  591. (defun c-postprocess-file-styles ()
  592. "Function that post processes relevant file local variables in CC Mode.
  593. Currently, this function simply applies any style and offset settings
  594. found in the file's Local Variable list. It first applies any style
  595. setting found in `c-file-style', then it applies any offset settings
  596. it finds in `c-file-offsets'.
  597. Note that the style variables are always made local to the buffer."
  598. ;; apply file styles and offsets
  599. (when c-buffer-is-cc-mode
  600. (if (or c-file-style c-file-offsets)
  601. (c-make-styles-buffer-local t))
  602. (and c-file-style
  603. (c-set-style c-file-style))
  604. (and c-file-offsets
  605. (mapcar
  606. (lambda (langentry)
  607. (let ((langelem (car langentry))
  608. (offset (cdr langentry)))
  609. (c-set-offset langelem offset)))
  610. c-file-offsets))
  611. ;; Problem: The file local variable block might have explicitly set a
  612. ;; style variable. The `c-set-style' or `mapcar' call might have
  613. ;; overwritten this. So we run `hack-local-variables' again to remedy
  614. ;; this. There are no guarantees this will work properly, particularly as
  615. ;; we have no control over what the other hook functions on
  616. ;; `hack-local-variables-hook' would have done. We now (2006/2/1) remove
  617. ;; any `eval' or `mode' expressions before we evaluate again (see below).
  618. ;; ACM, 2005/11/2.
  619. ;;
  620. ;; Problem (bug reported by Gustav Broberg): if one of the variables is
  621. ;; `mode', this will invoke c-mode (etc.) again, setting up the style etc.
  622. ;; We prevent this by temporarily removing `mode' from the Local Variables
  623. ;; section.
  624. (if (or c-file-style c-file-offsets)
  625. (c-tentative-buffer-changes
  626. (let ((hack-local-variables-hook nil))
  627. (c-remove-any-local-eval-or-mode-variables)
  628. (hack-local-variables))
  629. nil))))
  630. (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
  631. (defmacro c-run-mode-hooks (&rest hooks)
  632. ;; Emacs 21.1 has introduced a system with delayed mode hooks that
  633. ;; require the use of the new function `run-mode-hooks'.
  634. (if (cc-bytecomp-fboundp 'run-mode-hooks)
  635. `(run-mode-hooks ,@hooks)
  636. `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
  637. ;; Support for C
  638. ;;;###autoload
  639. (defvar c-mode-syntax-table nil
  640. "Syntax table used in c-mode buffers.")
  641. (or c-mode-syntax-table
  642. (setq c-mode-syntax-table
  643. (funcall (c-lang-const c-make-mode-syntax-table c))))
  644. (defvar c-mode-abbrev-table nil
  645. "Abbreviation table used in c-mode buffers.")
  646. (c-define-abbrev-table 'c-mode-abbrev-table
  647. '(("else" "else" c-electric-continued-statement 0)
  648. ("while" "while" c-electric-continued-statement 0)))
  649. (defvar c-mode-map ()
  650. "Keymap used in c-mode buffers.")
  651. (if c-mode-map
  652. nil
  653. (setq c-mode-map (c-make-inherited-keymap))
  654. ;; add bindings which are only useful for C
  655. (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
  656. )
  657. (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
  658. (cons "C" (c-lang-const c-mode-menu c)))
  659. ;; In XEmacs >= 21.5 modes should add their own entries to
  660. ;; `auto-mode-alist'. The comment form of autoload is used to avoid
  661. ;; doing this on load. That since `add-to-list' prepends the value
  662. ;; which could cause it to clobber user settings. Later emacsen have
  663. ;; an append option, but it's not safe to use.
  664. ;; The the extension ".C" is associated to C++ while the lowercase
  665. ;; variant goes to C. On case insensitive file systems, this means
  666. ;; that ".c" files also might open C++ mode if the C++ entry comes
  667. ;; first on `auto-mode-alist'. Thus we try to ensure that ".C" comes
  668. ;; after ".c", and since `add-to-list' adds the entry first we have to
  669. ;; add the ".C" entry first.
  670. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(cc\\|hh\\)\\'" . c++-mode))
  671. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode))
  672. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(CC?\\|HH?\\)\\'" . c++-mode))
  673. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.[ch]\\'" . c-mode))
  674. ;; NB: The following two associate yacc and lex files to C Mode, which
  675. ;; is not really suitable for those formats. Anyway, afaik there's
  676. ;; currently no better mode for them, and besides this is legacy.
  677. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
  678. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
  679. ;;;###autoload
  680. (defun c-mode ()
  681. "Major mode for editing K&R and ANSI C code.
  682. To submit a problem report, enter `\\[c-submit-bug-report]' from a
  683. c-mode buffer. This automatically sets up a mail buffer with version
  684. information already added. You just need to add a description of the
  685. problem, including a reproducible test case, and send the message.
  686. To see what version of CC Mode you are running, enter `\\[c-version]'.
  687. The hook `c-mode-common-hook' is run with no args at mode
  688. initialization, then `c-mode-hook'.
  689. Key bindings:
  690. \\{c-mode-map}"
  691. (interactive)
  692. (kill-all-local-variables)
  693. (c-initialize-cc-mode t)
  694. (set-syntax-table c-mode-syntax-table)
  695. (setq major-mode 'c-mode
  696. mode-name "C"
  697. local-abbrev-table c-mode-abbrev-table
  698. abbrev-mode t)
  699. (use-local-map c-mode-map)
  700. (c-init-language-vars-for 'c-mode)
  701. (c-common-init 'c-mode)
  702. (easy-menu-add c-c-menu)
  703. (cc-imenu-init cc-imenu-c-generic-expression)
  704. (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
  705. (c-update-modeline))
  706. ;; Support for C++
  707. ;;;###autoload
  708. (defvar c++-mode-syntax-table nil
  709. "Syntax table used in c++-mode buffers.")
  710. (or c++-mode-syntax-table
  711. (setq c++-mode-syntax-table
  712. (funcall (c-lang-const c-make-mode-syntax-table c++))))
  713. (defvar c++-mode-abbrev-table nil
  714. "Abbreviation table used in c++-mode buffers.")
  715. (c-define-abbrev-table 'c++-mode-abbrev-table
  716. '(("else" "else" c-electric-continued-statement 0)
  717. ("while" "while" c-electric-continued-statement 0)
  718. ("catch" "catch" c-electric-continued-statement 0)))
  719. (defvar c++-mode-map ()
  720. "Keymap used in c++-mode buffers.")
  721. (if c++-mode-map
  722. nil
  723. (setq c++-mode-map (c-make-inherited-keymap))
  724. ;; add bindings which are only useful for C++
  725. (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
  726. (define-key c++-mode-map "\C-c:" 'c-scope-operator)
  727. (define-key c++-mode-map "<" 'c-electric-lt-gt)
  728. (define-key c++-mode-map ">" 'c-electric-lt-gt))
  729. (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
  730. (cons "C++" (c-lang-const c-mode-menu c++)))
  731. ;;;###autoload
  732. (defun c++-mode ()
  733. "Major mode for editing C++ code.
  734. To submit a problem report, enter `\\[c-submit-bug-report]' from a
  735. c++-mode buffer. This automatically sets up a mail buffer with
  736. version information already added. You just need to add a description
  737. of the problem, including a reproducible test case, and send the
  738. message.
  739. To see what version of CC Mode you are running, enter `\\[c-version]'.
  740. The hook `c-mode-common-hook' is run with no args at mode
  741. initialization, then `c++-mode-hook'.
  742. Key bindings:
  743. \\{c++-mode-map}"
  744. (interactive)
  745. (kill-all-local-variables)
  746. (c-initialize-cc-mode t)
  747. (set-syntax-table c++-mode-syntax-table)
  748. (setq major-mode 'c++-mode
  749. mode-name "C++"
  750. local-abbrev-table c++-mode-abbrev-table
  751. abbrev-mode t)
  752. (use-local-map c++-mode-map)
  753. (c-init-language-vars-for 'c++-mode)
  754. (c-common-init 'c++-mode)
  755. (easy-menu-add c-c++-menu)
  756. (cc-imenu-init cc-imenu-c++-generic-expression)
  757. (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
  758. (c-update-modeline))
  759. ;; Support for Objective-C
  760. ;;;###autoload
  761. (defvar objc-mode-syntax-table nil
  762. "Syntax table used in objc-mode buffers.")
  763. (or objc-mode-syntax-table
  764. (setq objc-mode-syntax-table
  765. (funcall (c-lang-const c-make-mode-syntax-table objc))))
  766. (defvar objc-mode-abbrev-table nil
  767. "Abbreviation table used in objc-mode buffers.")
  768. (c-define-abbrev-table 'objc-mode-abbrev-table
  769. '(("else" "else" c-electric-continued-statement 0)
  770. ("while" "while" c-electric-continued-statement 0)))
  771. (defvar objc-mode-map ()
  772. "Keymap used in objc-mode buffers.")
  773. (if objc-mode-map
  774. nil
  775. (setq objc-mode-map (c-make-inherited-keymap))
  776. ;; add bindings which are only useful for Objective-C
  777. (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
  778. (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
  779. (cons "ObjC" (c-lang-const c-mode-menu objc)))
  780. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
  781. ;;;###autoload
  782. (defun objc-mode ()
  783. "Major mode for editing Objective C code.
  784. To submit a problem report, enter `\\[c-submit-bug-report]' from an
  785. objc-mode buffer. This automatically sets up a mail buffer with
  786. version information already added. You just need to add a description
  787. of the problem, including a reproducible test case, and send the
  788. message.
  789. To see what version of CC Mode you are running, enter `\\[c-version]'.
  790. The hook `c-mode-common-hook' is run with no args at mode
  791. initialization, then `objc-mode-hook'.
  792. Key bindings:
  793. \\{objc-mode-map}"
  794. (interactive)
  795. (kill-all-local-variables)
  796. (c-initialize-cc-mode t)
  797. (set-syntax-table objc-mode-syntax-table)
  798. (setq major-mode 'objc-mode
  799. mode-name "ObjC"
  800. local-abbrev-table objc-mode-abbrev-table
  801. abbrev-mode t)
  802. (use-local-map objc-mode-map)
  803. (c-init-language-vars-for 'objc-mode)
  804. (c-common-init 'objc-mode)
  805. (easy-menu-add c-objc-menu)
  806. (cc-imenu-init nil 'cc-imenu-objc-function)
  807. (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
  808. (c-update-modeline))
  809. ;; Support for Java
  810. ;;;###autoload
  811. (defvar java-mode-syntax-table nil
  812. "Syntax table used in java-mode buffers.")
  813. (or java-mode-syntax-table
  814. (setq java-mode-syntax-table
  815. (funcall (c-lang-const c-make-mode-syntax-table java))))
  816. (defvar java-mode-abbrev-table nil
  817. "Abbreviation table used in java-mode buffers.")
  818. (c-define-abbrev-table 'java-mode-abbrev-table
  819. '(("else" "else" c-electric-continued-statement 0)
  820. ("while" "while" c-electric-continued-statement 0)
  821. ("catch" "catch" c-electric-continued-statement 0)
  822. ("finally" "finally" c-electric-continued-statement 0)))
  823. (defvar java-mode-map ()
  824. "Keymap used in java-mode buffers.")
  825. (if java-mode-map
  826. nil
  827. (setq java-mode-map (c-make-inherited-keymap))
  828. ;; add bindings which are only useful for Java
  829. )
  830. ;; Regexp trying to describe the beginning of a Java top-level
  831. ;; definition. This is not used by CC Mode, nor is it maintained
  832. ;; since it's practically impossible to write a regexp that reliably
  833. ;; matches such a construct. Other tools are necessary.
  834. (defconst c-Java-defun-prompt-regexp
  835. "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f\v]*\\)+\\)?\\s-*")
  836. (easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
  837. (cons "Java" (c-lang-const c-mode-menu java)))
  838. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
  839. ;;;###autoload
  840. (defun java-mode ()
  841. "Major mode for editing Java code.
  842. To submit a problem report, enter `\\[c-submit-bug-report]' from a
  843. java-mode buffer. This automatically sets up a mail buffer with
  844. version information already added. You just need to add a description
  845. of the problem, including a reproducible test case, and send the
  846. message.
  847. To see what version of CC Mode you are running, enter `\\[c-version]'.
  848. The hook `c-mode-common-hook' is run with no args at mode
  849. initialization, then `java-mode-hook'.
  850. Key bindings:
  851. \\{java-mode-map}"
  852. (interactive)
  853. (kill-all-local-variables)
  854. (c-initialize-cc-mode t)
  855. (set-syntax-table java-mode-syntax-table)
  856. (setq major-mode 'java-mode
  857. mode-name "Java"
  858. local-abbrev-table java-mode-abbrev-table
  859. abbrev-mode t)
  860. (use-local-map java-mode-map)
  861. (c-init-language-vars-for 'java-mode)
  862. (c-common-init 'java-mode)
  863. (easy-menu-add c-java-menu)
  864. (cc-imenu-init cc-imenu-java-generic-expression)
  865. (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
  866. (c-update-modeline))
  867. ;; Support for CORBA's IDL language
  868. ;;;###autoload
  869. (defvar idl-mode-syntax-table nil
  870. "Syntax table used in idl-mode buffers.")
  871. (or idl-mode-syntax-table
  872. (setq idl-mode-syntax-table
  873. (funcall (c-lang-const c-make-mode-syntax-table idl))))
  874. (defvar idl-mode-abbrev-table nil
  875. "Abbreviation table used in idl-mode buffers.")
  876. (c-define-abbrev-table 'idl-mode-abbrev-table nil)
  877. (defvar idl-mode-map ()
  878. "Keymap used in idl-mode buffers.")
  879. (if idl-mode-map
  880. nil
  881. (setq idl-mode-map (c-make-inherited-keymap))
  882. ;; add bindings which are only useful for IDL
  883. )
  884. (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
  885. (cons "IDL" (c-lang-const c-mode-menu idl)))
  886. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
  887. ;;;###autoload
  888. (defun idl-mode ()
  889. "Major mode for editing CORBA's IDL, PSDL and CIDL code.
  890. To submit a problem report, enter `\\[c-submit-bug-report]' from an
  891. idl-mode buffer. This automatically sets up a mail buffer with
  892. version information already added. You just need to add a description
  893. of the problem, including a reproducible test case, and send the
  894. message.
  895. To see what version of CC Mode you are running, enter `\\[c-version]'.
  896. The hook `c-mode-common-hook' is run with no args at mode
  897. initialization, then `idl-mode-hook'.
  898. Key bindings:
  899. \\{idl-mode-map}"
  900. (interactive)
  901. (kill-all-local-variables)
  902. (c-initialize-cc-mode t)
  903. (set-syntax-table idl-mode-syntax-table)
  904. (setq major-mode 'idl-mode
  905. mode-name "IDL"
  906. local-abbrev-table idl-mode-abbrev-table)
  907. (use-local-map idl-mode-map)
  908. (c-init-language-vars-for 'idl-mode)
  909. (c-common-init 'idl-mode)
  910. (easy-menu-add c-idl-menu)
  911. ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
  912. (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
  913. (c-update-modeline))
  914. ;; Support for Pike
  915. ;;;###autoload
  916. (defvar pike-mode-syntax-table nil
  917. "Syntax table used in pike-mode buffers.")
  918. (or pike-mode-syntax-table
  919. (setq pike-mode-syntax-table
  920. (funcall (c-lang-const c-make-mode-syntax-table pike))))
  921. (defvar pike-mode-abbrev-table nil
  922. "Abbreviation table used in pike-mode buffers.")
  923. (c-define-abbrev-table 'pike-mode-abbrev-table
  924. '(("else" "else" c-electric-continued-statement 0)
  925. ("while" "while" c-electric-continued-statement 0)))
  926. (defvar pike-mode-map ()
  927. "Keymap used in pike-mode buffers.")
  928. (if pike-mode-map
  929. nil
  930. (setq pike-mode-map (c-make-inherited-keymap))
  931. ;; additional bindings
  932. (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
  933. (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
  934. (cons "Pike" (c-lang-const c-mode-menu pike)))
  935. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.\\(u?lpc\\|pike\\|pmod\\(.in\\)?\\)\\'" . pike-mode))
  936. ;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
  937. ;;;###autoload
  938. (defun pike-mode ()
  939. "Major mode for editing Pike code.
  940. To submit a problem report, enter `\\[c-submit-bug-report]' from a
  941. pike-mode buffer. This automatically sets up a mail buffer with
  942. version information already added. You just need to add a description
  943. of the problem, including a reproducible test case, and send the
  944. message.
  945. To see what version of CC Mode you are running, enter `\\[c-version]'.
  946. The hook `c-mode-common-hook' is run with no args at mode
  947. initialization, then `pike-mode-hook'.
  948. Key bindings:
  949. \\{pike-mode-map}"
  950. (interactive)
  951. (kill-all-local-variables)
  952. (c-initialize-cc-mode t)
  953. (set-syntax-table pike-mode-syntax-table)
  954. (setq major-mode 'pike-mode
  955. mode-name "Pike"
  956. local-abbrev-table pike-mode-abbrev-table
  957. abbrev-mode t)
  958. (use-local-map pike-mode-map)
  959. (c-init-language-vars-for 'pike-mode)
  960. (c-common-init 'pike-mode)
  961. (easy-menu-add c-pike-menu)
  962. ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
  963. (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
  964. (c-update-modeline))
  965. ;; Support for AWK
  966. ;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
  967. ;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
  968. ;;;###autoload (add-to-list 'interpreter-mode-alist '("mawk" . awk-mode))
  969. ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
  970. ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
  971. ;;; Autoload directives must be on the top level, so we construct an
  972. ;;; autoload form instead.
  973. ;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
  974. (defvar awk-mode-abbrev-table nil
  975. "Abbreviation table used in awk-mode buffers.")
  976. (c-define-abbrev-table 'awk-mode-abbrev-table
  977. '(("else" "else" c-electric-continued-statement 0)
  978. ("while" "while" c-electric-continued-statement 0)))
  979. (defvar awk-mode-map ()
  980. "Keymap used in awk-mode buffers.")
  981. (if awk-mode-map
  982. nil
  983. (setq awk-mode-map (c-make-inherited-keymap))
  984. ;; add bindings which are only useful for awk.
  985. (define-key awk-mode-map "#" 'self-insert-command)
  986. (define-key awk-mode-map "/" 'self-insert-command)
  987. (define-key awk-mode-map "*" 'self-insert-command)
  988. (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
  989. (define-key awk-mode-map "\C-c\C-p" 'undefined)
  990. (define-key awk-mode-map "\C-c\C-u" 'undefined)
  991. (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
  992. (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
  993. (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
  994. (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
  995. (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
  996. (cons "AWK" (c-lang-const c-mode-menu awk)))
  997. (defun awk-mode ()
  998. "Major mode for editing AWK code.
  999. To submit a problem report, enter `\\[c-submit-bug-report]' from an
  1000. awk-mode buffer. This automatically sets up a mail buffer with version
  1001. information already added. You just need to add a description of the
  1002. problem, including a reproducible test case, and send the message.
  1003. To see what version of CC Mode you are running, enter `\\[c-version]'.
  1004. The hook `c-mode-common-hook' is run with no args at mode
  1005. initialization, then `awk-mode-hook'.
  1006. Key bindings:
  1007. \\{awk-mode-map}"
  1008. (interactive)
  1009. (require 'cc-awk) ; Added 2003/6/10.
  1010. (kill-all-local-variables)
  1011. (c-initialize-cc-mode t)
  1012. (set-syntax-table awk-mode-syntax-table)
  1013. (setq major-mode 'awk-mode
  1014. mode-name "AWK"
  1015. local-abbrev-table awk-mode-abbrev-table
  1016. abbrev-mode t)
  1017. (use-local-map awk-mode-map)
  1018. (c-init-language-vars-for 'awk-mode)
  1019. (c-common-init 'awk-mode)
  1020. ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
  1021. ;; so it's not set by `c-font-lock-init'.
  1022. (make-local-variable 'font-lock-syntactic-keywords)
  1023. (setq font-lock-syntactic-keywords
  1024. '((c-awk-set-syntax-table-properties
  1025. 0 (0) ; Everything on this line is a dummy.
  1026. nil t)))
  1027. (c-awk-unstick-NL-prop)
  1028. (add-hook 'before-change-functions 'c-awk-before-change nil t)
  1029. (add-hook 'after-change-functions 'c-awk-after-change nil t)
  1030. (c-save-buffer-state nil
  1031. (save-restriction
  1032. (widen)
  1033. (c-awk-clear-NL-props (point-min) (point-max))
  1034. (c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
  1035. ;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
  1036. ;; in cc-engine.el, just before (defun c-fast-in-literal ...
  1037. (defalias 'c-in-literal 'c-slow-in-literal)
  1038. (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
  1039. (c-update-modeline))
  1040. ;; bug reporting
  1041. (defconst c-mode-help-address
  1042. "bug-cc-mode@gnu.org"
  1043. "Address(es) for CC Mode bug reports.")
  1044. (defun c-version ()
  1045. "Echo the current version of CC Mode in the minibuffer."
  1046. (interactive)
  1047. (message "Using CC Mode version %s" c-version)
  1048. (c-keep-region-active))
  1049. (defvar c-prepare-bug-report-hooks nil)
  1050. ;; Dynamic variables used by reporter.
  1051. (defvar reporter-prompt-for-summary-p)
  1052. (defvar reporter-dont-compact-list)
  1053. (defun c-submit-bug-report ()
  1054. "Submit via mail a bug report on CC Mode."
  1055. (interactive)
  1056. (require 'reporter)
  1057. ;; load in reporter
  1058. (let ((reporter-prompt-for-summary-p t)
  1059. (reporter-dont-compact-list '(c-offsets-alist))
  1060. (style c-indentation-style)
  1061. (c-features c-emacs-features))
  1062. (and
  1063. (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
  1064. t (message "") nil)
  1065. (reporter-submit-bug-report
  1066. c-mode-help-address
  1067. (concat "CC Mode " c-version " (" mode-name ")")
  1068. (let ((vars (append
  1069. c-style-variables
  1070. '(c-buffer-is-cc-mode
  1071. c-tab-always-indent
  1072. c-syntactic-indentation
  1073. c-syntactic-indentation-in-macros
  1074. c-ignore-auto-fill
  1075. c-auto-align-backslashes
  1076. c-backspace-function
  1077. c-delete-function
  1078. c-electric-pound-behavior
  1079. c-default-style
  1080. c-enable-xemacs-performance-kludge-p
  1081. c-old-style-variable-behavior
  1082. defun-prompt-regexp
  1083. tab-width
  1084. comment-column
  1085. parse-sexp-ignore-comments
  1086. parse-sexp-lookup-properties
  1087. lookup-syntax-properties
  1088. ;; A brain-damaged XEmacs only variable that, if
  1089. ;; set to nil can cause all kinds of chaos.
  1090. signal-error-on-buffer-boundary
  1091. ;; Variables that affect line breaking and comments.
  1092. auto-fill-mode
  1093. auto-fill-function
  1094. filladapt-mode
  1095. comment-multi-line
  1096. comment-start-skip
  1097. fill-prefix
  1098. fill-column
  1099. paragraph-start
  1100. adaptive-fill-mode
  1101. adaptive-fill-regexp)
  1102. nil)))
  1103. (mapcar (lambda (var) (unless (boundp var)
  1104. (setq vars (delq var vars))))
  1105. '(signal-error-on-buffer-boundary
  1106. filladapt-mode
  1107. defun-prompt-regexp
  1108. font-lock-mode
  1109. font-lock-maximum-decoration
  1110. parse-sexp-lookup-properties
  1111. lookup-syntax-properties))
  1112. vars)
  1113. (lambda ()
  1114. (run-hooks 'c-prepare-bug-report-hooks)
  1115. (i

Large files files are truncated, but you can click here to view the full file