home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-18.59-bin.lha / lib / emacs / 18.59 / lisp / c-mode.elc < prev    next >
Text File  |  1992-10-23  |  12KB  |  175 lines

  1.  
  2. (defvar c-mode-abbrev-table nil "\
  3. Abbrev table in use in C-mode buffers.")
  4.  
  5. (define-abbrev-table (quote c-mode-abbrev-table) nil)
  6.  
  7. (defvar c-mode-map nil "\
  8. Keymap used in C mode.")
  9.  
  10. (if c-mode-map nil (setq c-mode-map (make-sparse-keymap)) (define-key c-mode-map "{" (quote electric-c-brace)) (define-key c-mode-map "}" (quote electric-c-brace)) (define-key c-mode-map ";" (quote electric-c-semi)) (define-key c-mode-map ":" (quote electric-c-terminator)) (define-key c-mode-map "" (quote mark-c-function)) (define-key c-mode-map "" (quote indent-c-exp)) (define-key c-mode-map "" (quote backward-delete-char-untabify)) (define-key c-mode-map "    " (quote c-indent-command)))
  11.  
  12. (autoload (quote c-macro-expand) "cmacexp" "\
  13. Display the result of expanding all C macros occurring in the region.
  14. The expansion is entirely correct because it uses the C preprocessor." t)
  15.  
  16. (defvar c-mode-syntax-table nil "\
  17. Syntax table in use in C-mode buffers.")
  18.  
  19. (if c-mode-syntax-table nil (setq c-mode-syntax-table (make-syntax-table)) (modify-syntax-entry 92 "\\" c-mode-syntax-table) (modify-syntax-entry 47 ". 14" c-mode-syntax-table) (modify-syntax-entry 42 ". 23" c-mode-syntax-table) (modify-syntax-entry 43 "." c-mode-syntax-table) (modify-syntax-entry 45 "." c-mode-syntax-table) (modify-syntax-entry 61 "." c-mode-syntax-table) (modify-syntax-entry 37 "." c-mode-syntax-table) (modify-syntax-entry 60 "." c-mode-syntax-table) (modify-syntax-entry 62 "." c-mode-syntax-table) (modify-syntax-entry 38 "." c-mode-syntax-table) (modify-syntax-entry 124 "." c-mode-syntax-table) (modify-syntax-entry 39 "\"" c-mode-syntax-table))
  20.  
  21. (defconst c-indent-level 2 "\
  22. *Indentation of C statements with respect to containing block.")
  23.  
  24. (defconst c-brace-imaginary-offset 0 "\
  25. *Imagined indentation of a C open brace that actually follows a statement.")
  26.  
  27. (defconst c-brace-offset 0 "\
  28. *Extra indentation for braces, compared with other text in same context.")
  29.  
  30. (defconst c-argdecl-indent 5 "\
  31. *Indentation level of declarations of C function arguments.")
  32.  
  33. (defconst c-label-offset -2 "\
  34. *Offset of C label lines and case statements relative to usual indentation.")
  35.  
  36. (defconst c-continued-statement-offset 2 "\
  37. *Extra indent for lines not starting new statements.")
  38.  
  39. (defconst c-continued-brace-offset 0 "\
  40. *Extra indent for substatements that start with open-braces.
  41. This is in addition to c-continued-statement-offset.")
  42.  
  43. (defconst c-auto-newline nil "\
  44. *Non-nil means automatically newline before and after braces,
  45. and after colons and semicolons, inserted in C code.")
  46.  
  47. (defconst c-tab-always-indent t "\
  48. *Non-nil means TAB in C mode should always reindent the current line,
  49. regardless of where in the line point is when the TAB command is used.")
  50.  
  51. (defun c-mode nil "\
  52. Major mode for editing C code.
  53. Expression and list commands understand all C brackets.
  54. Tab indents for C code.
  55. Comments are delimited with /* ... */.
  56. Paragraphs are separated by blank lines only.
  57. Delete converts tabs to spaces as it moves back.
  58. \\{c-mode-map}
  59. Variables controlling indentation style:
  60.  c-tab-always-indent
  61.     Non-nil means TAB in C mode should always reindent the current line,
  62.     regardless of where in the line point is when the TAB command is used.
  63.  c-auto-newline
  64.     Non-nil means automatically newline before and after braces,
  65.     and after colons and semicolons, inserted in C code.
  66.  c-indent-level
  67.     Indentation of C statements within surrounding block.
  68.     The surrounding block's indentation is the indentation
  69.     of the line on which the open-brace appears.
  70.  c-continued-statement-offset
  71.     Extra indentation given to a substatement, such as the
  72.     then-clause of an if or body of a while.
  73.  c-continued-brace-offset
  74.     Extra indentation given to a brace that starts a substatement.
  75.     This is in addition to c-continued-statement-offset.
  76.  c-brace-offset
  77.     Extra indentation for line if it starts with an open brace.
  78.  c-brace-imaginary-offset
  79.     An open brace following other text is treated as if it were
  80.     this far to the right of the start of its line.
  81.  c-argdecl-indent
  82.     Indentation level of declarations of C function arguments.
  83.  c-label-offset
  84.     Extra indentation for line that is a label, or case or default.
  85.  
  86. Settings for K&R and BSD indentation styles are
  87.   c-indent-level                5    8
  88.   c-continued-statement-offset  5    8
  89.   c-brace-offset               -5   -8
  90.   c-argdecl-indent              0    8
  91.   c-label-offset               -5   -8
  92.  
  93. Turning on C mode calls the value of the variable c-mode-hook with no args,
  94. if that value is non-nil." (interactive) (byte-code "ӈԠˆÕ!ˆÖ‰ˆ×‰ˆ ‰ˆØ!ˆÙÆ!ˆÚP‰ˆÙÈ!ˆ‰ˆÙÉ!ˆÊ‰    ˆÙË!ˆÛ‰ ˆÙÌ!ˆÊ‰ ˆÙÍ!ˆÜ‰ˆÙÎ!ˆÝ‰ˆÙÏ!ˆÞ‰ˆÙÐ!ˆß‰ˆÙÑ!ˆà‰ˆÙÒ!ˆÊ‰ˆáâ!‡" [c-mode-map major-mode mode-name local-abbrev-table c-mode-abbrev-table c-mode-syntax-table paragraph-start page-delimiter paragraph-separate paragraph-ignore-fill-prefix t indent-line-function require-final-newline comment-start comment-end comment-column comment-start-skip comment-indent-hook parse-sexp-ignore-comments nil kill-all-local-variables use-local-map c-mode "C" set-syntax-table make-local-variable "^$\\|" c-indent-line "/* " " */" 32 "/\\*+ *" c-comment-indent run-hooks c-mode-hook] 16))
  95.  
  96. (defun c-comment-indent nil (byte-code "ÁÂ!ƒ
  97. ŠÄÅ!ˆiT])‡" [comment-column looking-at "^/\\*" 0 skip-chars-backward "     "] 4))
  98.  
  99. (defun electric-c-brace (arg) "\
  100. Insert character and correct line's indentation." (interactive "P") (byte-code "ĈÄ    ?…&l…&ŠÆÇ!ˆn)†&
  101. ƒ%È ˆÉ ˆÃ‚&ąLcˆÈ ˆ
  102. …>É ˆ`ÊZ‰ˆÈ ˆŠ…GTbˆËÌ!)ˆƒ^ŠbˆÍΠ   !!)‚cÍΠ   !!)‡" [insertpos arg c-auto-newline t nil last-command-char skip-chars-backward "     " c-indent-line newline 2 delete-char -1 self-insert-command prefix-numeric-value] 12))
  103.  
  104. (defun electric-c-semi (arg) "\
  105. Insert character and correct line's indentation." (interactive "P") (byte-code "ˆƒ à   !‚ÄÅ    !!‡" [c-auto-newline arg nil electric-c-terminator self-insert-command prefix-numeric-value] 4))
  106.  
  107. (defun electric-c-terminator (arg) "\
  108. Insert character and correct line's indentation." (interactive "P") (byte-code "ƈÆ`
  109. ?…Tl…TŠÇ ˆÈÉ!ˆgÊU†R Ë=…7ÌÍ!?…7ŠÎÏ!ˆÈÉ!ˆ`    W)†RРˆÑ`    \"Ò 8†QÓ 8†QÔ 8))?…€ cˆÕ ˆ…rÖ ?…r× ˆ`ØZ‰ˆÕ ˆŠ…{TbˆÙÚ!)ˆƒ’ŠbˆÛÜ
  110. !!)‚—ÛÜ
  111. !!*‡" [insertpos end arg last-command-char pps c-auto-newline nil beginning-of-line skip-chars-forward "     " 35 58 looking-at "case[     ]" forward-word 1 beginning-of-defun parse-partial-sexp 3 4 5 c-indent-line c-inside-parens-p newline 2 delete-char -1 self-insert-command prefix-numeric-value] 17))
  112.  
  113. (defun c-inside-parens-p nil (byte-code "ÀÁ‡" [nil (byte-code "ŠŒÀ`Á ˆ`\"ˆdbˆÂ`ÃÄ#†efÅU))‡" [narrow-to-region beginning-of-defun scan-lists -1 1 40] 6) ((error (byte-code "À‡" [nil] 1)))] 3))
  114.  
  115. (defun c-indent-command (&optional whole-exp) "\
  116. Indent current line as C code, or in some cases insert a tab character.
  117. If c-tab-always-indent is non-nil (the default), always indent current line.
  118. Otherwise, indent the current line only if point is at the left margin
  119. or in the line's indentation; otherwise insert a tab.
  120.  
  121. A numeric argument, regardless of its value,
  122. means indent rigidly all the lines of the expression starting after point
  123. so that this line becomes properly indented.
  124. The relative indentation among the lines of the expression are preserved." (interactive "P") (byte-code "ňƒ=Æ ÅÅŠ …Ç ˆ`‰ˆÈÉ!ˆ`‰ˆ
  125. bˆÊÉ!ˆ`‰)ˆ
  126. V…9Ë
  127.     Ì$+‚T ?…JŠÍÎ!ˆn?)ƒRÏ ‚TÆ ‡" [whole-exp shift-amt beg end c-tab-always-indent nil c-indent-line beginning-of-line forward-sexp 1 forward-line indent-code-rigidly "#" skip-chars-backward "     " insert-tab] 9))
  128.  
  129. (defun c-indent-line nil "\
  130. Indent current line as C code.
  131. Return the amount the indentation changed by." (byte-code "ÊÁ!ÁÁÁd`ZË ˆ`‰ˆÁ=ƒ\"Ì ‰‚ Æ=ƒ/Í ‰‚ ÎÏ!ƒ;Љ‚ ÑÒ!ˆ<…H@‰ˆÎÓ!†^ÎÔ!…^ŠÕÖ!ˆÎ×!)ƒlÖ\\]‰‚ ÎØ!…vÎÙ!?ƒ…ŠÚ ˆÌ )‰‚ gÛUƒ”Z‰‚ gÜU…     \\‰ˆÑÒ!ˆiZ‰ˆÝ !ƒÀdZ`V…½dZb‚ÔÞ
  132. `\"ˆjˆdZ`V…ÔdZbˆ -‡" [indent nil beg shift-amt case-fold-search pos t c-label-offset c-indent-level c-brace-offset calculate-c-indent beginning-of-line current-indentation calculate-c-indent-within-comment looking-at "[     ]*#" 0 skip-chars-forward "     " "case[     ]" "[A-Za-z]" forward-sexp 1 ":" "else\\b" "else\\s_" c-backward-to-start-of-if 125 123 zerop delete-region] 19))
  133.  
  134. (defun calculate-c-indent (&optional parse-start) "\
  135. Return appropriate indentation for current line as C code.
  136. In usual case returns an integer: the column to indent to.
  137. Returns nil if line starts inside a string, t if in a comment." (byte-code "ŠÐ ˆ`ƒb‚Ñ ˆ`W…3`‰ˆÒ`Ó#‰ˆ A@‰ˆ‚ˆÔ 8†=Õ 8ƒFÕ 8‚À ?ƒ®bˆÖ×!ˆgØUƒ\\ӂ«Ù†be!ˆŠÚÛÂÜ#ˆÝÞ!…‹Ýß!…‹àÓ!Sbˆáâ!ˆ`W…‹gã>?ƒ“‚”Ó)o† hä>ƒ§Ó‚©\\)‚Àå fØ\"ƒ¾ Tbˆi‚ÀbˆÙ !ˆhæ=†âhç=…â`èZfé=†âê`èZf!ë>…ùhæ=…îì !ˆÐ ˆÙ !ˆ‚ňhí>?ƒ\"ì !ˆîiŠbˆÖ×!ˆgØ=)ƒ
  138. ‚Ó#‚À bˆŠïâ!ˆÓ Öð!ˆÝñ!…fgòUƒCóâ!‚bgôUƒUïè!ˆõöÂÜ#‚bŠ÷ ˆ`‰ )ˆõø!ˆ‚-ˆ`W…Š `Vƒ|ù  Z‚}igØUƒˆ‚‰ÓZ))†Àîn…˜ú!ƒ£\\‚¥û×!ˆnƒ±ӂ³hü=…¼áý!ˆù #,)‡" [indent-point case-fold-search nil state containing-sexp parse-start basic-indent c-argdecl-indent c-continued-statement-offset t c-continued-brace-offset colon-line-end c-label-offset c-brace-offset c-indent-level c-brace-imaginary-offset beginning-of-line beginning-of-defun parse-partial-sexp 0 3 4 skip-chars-forward "     " 123 c-backward-to-noncomment re-search-backward "^[^      
  139. #]" move looking-at "\\sw\\|\\s_" "[^\"
  140. =(]*(" match-end forward-sexp 1 (44 59) (41 59 125) /= 44 58 2 39 char-syntax (119 95) c-backward-to-start-of-continued-exp (nil 44 59 125 123) + forward-char "     
  141. " "#\\|/\\*\\|case[     
  142. ].*:\\|[a-zA-Z0-9_$]*:" 35 forward-line 47 search-forward "*/" end-of-line ":" current-indentation zerop skip-chars-backward 41 -1] 36))
  143.  
  144. (defun calculate-c-indent-within-comment nil "\
  145. Return the indentation amount for line, assuming that
  146. the current line is to be regarded as part of a block comment." (byte-code "ÃÊĠˆÅÆ!ˆgÇU‰ˆÈÉ!ˆ`‰ˆÄ ˆÅÆ!ˆÊËÂ#…2    …2ÌÍ!Tbˆi)*‡" [end star-start t nil beginning-of-line skip-chars-forward "     " 42 skip-chars-backward "     
  147. " re-search-forward "/\\*[     ]*" match-beginning 0] 9))
  148.  
  149. (defun c-backward-to-noncomment (lim) (byte-code "Ãà   ?…NÄÅ
  150. \"ˆ`‰ˆ`Æ
  151. \\Y…#ŠÇÈ!ˆÉÊ!)ƒ.ËÌ
  152. Í#‚J`
  153. X†AŠÎ ˆÏÐ!ˆÉÑ!?)‰ˆ    †JЈ‚*‡" [opoint stop lim nil skip-chars-backward "     
  154. " 2 forward-char -2 looking-at "\\*/" search-backward "/*" move beginning-of-line skip-chars-forward "     " "#"] 10))
  155.  
  156. (defun c-backward-to-start-of-continued-exp (lim) (byte-code "hÁU…    ÂÃ!ˆÄ ˆ`X…TbˆÅÆ!‡" [lim 41 forward-sexp -1 beginning-of-line skip-chars-forward "     "] 4))
  157.  
  158. (defun c-backward-to-start-of-if (&optional limit) "\
  159. Move to the start of the last ``unbalanced'' if." (byte-code "† ŠÄ ˆ`)‰ˆÅÃÆ    !?…FÇÅ!ˆÈÉ!ƒ)    T‰‚BÈÊ!ƒ6    S‰‚B`W…Bˉˆbˆ‚*‡" [limit if-level case-fold-search nil beginning-of-defun 1 zerop backward-sexp looking-at "else\\b" "if\\b" 0] 8))
  160.  
  161. (defun mark-c-function nil "\
  162. Put mark at end of C function, point at beginning." (interactive) (byte-code "ÀˆÁ`!ˆÂ ˆÁ`!ˆÃ ˆÄ ‡" [nil push-mark end-of-defun beginning-of-defun backward-paragraph] 6))
  163.  
  164. (defun indent-c-exp nil "\
  165. Indent each line of the C grouping following point." (interactive) (byte-code "ÁˆÁC`CÁÁÁÁÁÁÁÁÁÁ`Ø  
  166.     ŠÙÚ!)ˆŠÁ‰ˆm?…;?…,‰ˆÁ‰ˆ?…Wm…VЉ?…°‰ˆÛ`Ü ˆ`ÁÁ%‰ˆ@‰ˆAA@……AA@ØY…AA@‰
  167. ˆÝ8…šÞ ˆß8ƒ¨àÚ!‚¬Ð‰ˆ‚IˆØX…»Ð‰ˆƒÄÁ‚(á8V…ÞA
  168. AS‰ˆ‚Ĉâ\"…ìÁ‰
  169. ˆW…ÁBÁ
  170. BT‰ˆ‚íˆ
  171. @?…ã
  172. A@†ŠÙä!ˆ`)\"ˆàÚ!ˆåæ!ˆlƒ0Á‚(@…9@ØYƒžâ
  173. @fç\"ƒM@‰    ‚›Šèé!‰ ˆgçU‰ ˆê!ˆhë>?ƒƒì
  174. @!ˆíi ƒ{‚|Ø#‰    ‚š ƒ•î!ˆï ‰    ‚š@‰    )‚³ð@…§@[!㉠   \")ˆèñ!†Éèò!…ÉŠÙÚ!ˆèó!)…ÖÚ    \\]‰    ˆgôU…å    Z‰    ˆgçU…ô    \\‰    ˆi    U†gõU†ö`÷ ˆ`\"ˆ    jˆè!†(øŠÜ ˆ`)Ð#…(ù ˆ÷ ˆ‚4).‡" [indent-stack nil contain-stack case-fold-search restart outer-loop-done inner-loop-done state ostate this-indent last-sexp at-else at-brace opoint next-depth last-depth t c-continued-statement-offset c-continued-brace-offset val c-label-offset c-indent-level c-brace-offset comment-start-skip 0 forward-sexp 1 parse-partial-sexp end-of-line 4 c-indent-line 3 forward-line 6 /= setcar -1 skip-chars-forward "     " 123 looking-at "else\\W" c-backward-to-noncomment (nil 44 59 125 58 123) c-backward-to-start-of-continued-exp + c-backward-to-start-of-if current-indentation calculate-c-indent "case[     ]" "[A-Za-z]" ":" 125 35 delete-region beginning-of-line re-search-forward indent-for-comment] 32))
  175.