[BACK]Return to asir-mode.el CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / windows / post-msg-asirgui

Annotation of OpenXM_contrib2/windows/post-msg-asirgui/asir-mode.el, Revision 1.12

1.1       takayama    1: ;; -*- mode: emacs-lisp  -*-
                      2: ;;
                      3: ;; asir-mode.el -- asir mode
                      4: ;;
1.12    ! ohara       5: ;; $OpenXM: OpenXM_contrib2/windows/post-msg-asirgui/asir-mode.el,v 1.11 2013/11/27 04:40:41 takayama Exp $
1.10      takayama    6:
1.1       takayama    7: ;; This program is free software: you can redistribute it and/or modify
                      8: ;; it under the terms of the GNU General Public License as published by
                      9: ;; the Free Software Foundation, either version 3 of the License, or
                     10: ;; (at your option) any later version.
1.12    ! ohara      11:
1.10      takayama   12: ;; 1. Install
                     13: ;;
                     14: ;; **(for Windows) Write the following configuration to your .emacs file.
                     15: ;;
                     16: ;; (setq load-path (append load-path '((concat (getenv "ASIR_ROOTDIR") "/share/editor"))))
                     17: ;; (setq auto-mode-alist (cons '("\\.rr$" . asir-mode) auto-mode-alist))
                     18: ;; (autoload 'asir-mode "asir-mode" "Asir mode" t)
                     19: ;;
                     20: ;; **(for unix) Copy this file to your emacs site-lisp folder and
                     21: ;;              write the following configuration to your .emacs file.
                     22: ;;
                     23: ;; (setq auto-mode-alist (cons '("\\.rr$" . asir-mode) auto-mode-alist))
                     24: ;; (autoload 'asir-mode "asir-mode" "Asir mode" t)
                     25: ;;
                     26: ;; Please run byte-compile for speed up.
                     27: ;;
                     28: ;; 2. Use
                     29: ;;
                     30: ;; If you open Risa/Asir source file (*.rr) by emacs, then asir-mode starts up automatically.
                     31: ;; The following key binding can be used:
                     32: ;; C-c s     Asir starts up in another window.
                     33: ;; C-c t     Asir terminates.
                     34: ;; C-c l     The current buffer is loaded to Asir as a file.
                     35: ;; C-c r     Selected region is loaded to Asir as a file.
                     36: ;; C-c p     Selected region is pasted to Asir.
                     37:
                     38: (require 'shell)
1.1       takayama   39:
1.9       takayama   40: ;;;; AsirGUI for Windows
1.10      takayama   41: (defvar asir-exec-path '("~/Desktop/asir/bin" "c:/Program Files/asir/bin" "c:/Program Files (x64)/asir/bin" "c:/asir/bin")
                     42:   "Default search path for asir binary in Windows")
1.1       takayama   43:
1.10      takayama   44: (defun asir-effective-exec-path ()
1.1       takayama   45:   "Search path for command"
                     46:   (let* ((dir (getenv "ASIR_ROOTDIR"))
1.10      takayama   47:          (path (append asir-exec-path exec-path)))
                     48:     (if dir (cons (concat dir "/bin") path) path)))
1.1       takayama   49:
1.10      takayama   50: (defun asir-executable-find (command)
1.1       takayama   51:   "Search for command"
                     52:   (let* ((exec-path (asir-effective-exec-path)))
1.10      takayama   53:     (executable-find command)))
                     54:
                     55: ;;;; Asir for UNIX
                     56: (defvar asir-cmd-buffer-name "*asir-cmd*")
                     57:
                     58: (defun asir-cmd-load (filename)
                     59:   "Send `load' command to running asir process"
                     60:   (if (eq system-type 'windows-nt)
                     61:       (let ((exec-path (asir-effective-exec-path)))
                     62:         (start-process "asir-proc-cmdasir" nil "cmdasir" filename))
                     63:     (save-excursion
                     64:       (if (get-buffer asir-cmd-buffer-name)
                     65:           (progn
                     66:             (set-buffer asir-cmd-buffer-name)
                     67:             (goto-char (point-max))
                     68:             (insert (format "load(\"%s\");" filename))
                     69:             (comint-send-input))))))
                     70:
                     71: (defun asir-start ()
                     72:   "Start asir process"
                     73:   (interactive)
                     74:   (if (eq system-type 'windows-nt)
                     75:     ;; for Windows
                     76:       (let ((exec-path (asir-effective-exec-path)))
                     77:         (start-process "asir-proc-asirgui" nil "asirgui"))
                     78:     ;; for UNIX
                     79:     (save-excursion
                     80:       (if (not (get-buffer asir-cmd-buffer-name))
                     81:           (let ((current-frame (selected-frame)))
                     82:             (if window-system
                     83:                 (progn
                     84:                   (select-frame (make-frame))
                     85:                   (shell (get-buffer-create asir-cmd-buffer-name)) ;; Switch to new buffer automatically
                     86:                   (delete-other-windows))
                     87:               (if (>= emacs-major-version 24)
                     88:                   (progn
                     89:                     (split-window)
                     90:                     (other-window -1)))
                     91:               (shell (get-buffer-create asir-cmd-buffer-name)))
                     92:             (sleep-for 1)
                     93:             (goto-char (point-max))
                     94:             (insert "asir")
                     95:             (comint-send-input)
                     96:             (select-frame current-frame))))))
1.1       takayama   97:
1.10      takayama   98: (defun asir-terminate ()
                     99:   "Terminate asir process"
1.1       takayama  100:   (interactive)
1.10      takayama  101:   (if (eq system-type 'windows-nt)
                    102:     ;; for Windows
                    103:       (let ((exec-path (asir-effective-exec-path)))
                    104:         (start-process "asir-proc-cmdasir" nil "cmdasir" "--quit"))
                    105:     ;; for UNIX
                    106:     (if (get-buffer asir-cmd-buffer-name)
                    107:         (if (not window-system)
                    108:             (let ((asir-cmd-window (get-buffer-window asir-cmd-buffer-name)))
                    109:               (and (kill-buffer asir-cmd-buffer-name)
                    110:                    (or (not asir-cmd-window) (delete-window asir-cmd-window))))
                    111:           (let ((asir-cmd-frame (window-frame (get-buffer-window asir-cmd-buffer-name 0))))
                    112:             (and (kill-buffer asir-cmd-buffer-name)
                    113:                  (delete-frame asir-cmd-frame)))))))
1.1       takayama  114:
1.10      takayama  115: (defun asir-execute-current-buffer ()
                    116:   "Execute current buffer on asir"
1.1       takayama  117:   (interactive)
1.9       takayama  118:   (let ((exec-path (asir-effective-exec-path)))
1.10      takayama  119:     (asir-cmd-load (buffer-file-name))))
1.1       takayama  120:
1.10      takayama  121: (defun asir-execute-region ()
                    122:   "Execute region on asir"
1.1       takayama  123:   (interactive)
1.10      takayama  124:   (if mark-active
                    125:       (save-excursion
                    126:         (let ((temp-file (make-temp-file (format "%s/cmdasir-" (or (getenv "TEMP") "/var/tmp"))))
                    127:               (temp-buffer (generate-new-buffer " *asir-temp*")))
                    128:           (write-region (region-beginning) (region-end) temp-file)
                    129:           (set-buffer temp-buffer)
                    130:           (insert " end$")
                    131:           (write-region (point-min) (point-max) temp-file t) ;; append
                    132:           (kill-buffer temp-buffer)
                    133:           (asir-cmd-load temp-file)))))
1.1       takayama  134:
1.10      takayama  135: (defun asir-paste-region ()
                    136:   "Paste region to asir"
1.1       takayama  137:   (interactive)
1.10      takayama  138:   (if mark-active
                    139:       (if (eq system-type 'windows-nt)
                    140:           (let ((temp-file (make-temp-file (format "%s/cmdasir-" (getenv "TEMP"))))
                    141:                 (exec-path (asir-effective-exec-path)))
                    142:             (write-region (region-beginning) (region-end) temp-file)
                    143:             (start-process "asir-proc-cmdasir" nil "cmdasir" "--paste-contents" temp-file))
                    144:         (save-excursion
                    145:           (let ((buffer (current-buffer))
                    146:                 (start (region-beginning))
                    147:                 (end (region-end)))
                    148:             (set-buffer asir-cmd-buffer-name)
                    149:             (goto-char (point-max))
                    150:             (insert-buffer-substring buffer start end)
                    151:             (comint-send-input))))))
1.4       ohara     152:
1.1       takayama  153: ;;;; Extension for CC-mode.
                    154:
                    155: (require 'cc-mode)
                    156:
                    157: (eval-when-compile
                    158:   (require 'cc-langs)
                    159:   (require 'cc-engine)
                    160:   (require 'cc-fonts))
                    161:
                    162: (eval-and-compile
                    163:   ;; Make our mode known to the language constant system.  Use Java
                    164:   ;; mode as the fallback for the constants we don't change here.
                    165:   ;; This needs to be done also at compile time since the language
                    166:   ;; constants are evaluated then.
                    167:   (c-add-language 'asir-mode 'c++-mode))
                    168:
                    169: (c-lang-defconst c-stmt-delim-chars asir "^;${}?:")
                    170: (c-lang-defconst c-stmt-delim-chars-with-comma asir "^;$,{}?:")
                    171: (c-lang-defconst c-other-op-syntax-tokens
                    172:   asir (cons "$" (c-lang-const c-other-op-syntax-tokens c)))
                    173: (c-lang-defconst c-identifier-syntax-modifications
                    174:   asir (remove '(?$ . "w") (c-lang-const c-identifier-syntax-modifications c)))
                    175: (c-lang-defconst c-symbol-chars asir (concat c-alnum "_"))
                    176:
                    177: (c-lang-defconst c-primitive-type-kwds asir '("def" "extern" "static" "localf" "function"))
                    178: (c-lang-defconst c-primitive-type-prefix-kwds asir nil)
                    179: (c-lang-defconst c-type-list-kwds asir nil)
                    180: (c-lang-defconst c-class-decl-kwds asir '("module"))
                    181: (c-lang-defconst c-othe-decl-kwds  asir '("endmodule" "end"))
                    182: (c-lang-defconst c-type-modifier-kwds asir nil)
                    183: (c-lang-defconst c-modifier-kwds asir nil)
                    184:
                    185: (c-lang-defconst c-mode-menu
                    186:   asir
                    187:   (append (c-lang-const c-mode-menu c)
                    188:                  '("----"
1.10      takayama  189:                        ["Start Asir" asir-start t]
                    190:                        ["Terminate Asir" asir-terminate t]
                    191:                        ["Execute Current Buffer on Asir" asir-execute-current-buffer (buffer-file-name)]
                    192:                        ["Execute Region on Asir" asir-execute-region mark-active]
                    193:                        ["Paste Region to Asir" asir-paste-region mark-active]
1.1       takayama  194:                        )))
                    195:
                    196: (defvar asir-font-lock-extra-types nil
                    197:   "*List of extra types (aside from the type keywords) to recognize in asir mode.
                    198: Each list item should be a regexp matching a single identifier.")
                    199:
                    200: (defconst asir-font-lock-keywords-1 (c-lang-const c-matchers-1 asir)
                    201:   "Minimal highlighting for asir mode.")
                    202:
                    203: (defconst asir-font-lock-keywords-2 (c-lang-const c-matchers-2 asir)
                    204:   "Fast normal highlighting for asir mode.")
                    205:
                    206: (defconst asir-font-lock-keywords-3 (c-lang-const c-matchers-3 asir)
                    207:   "Accurate normal highlighting for asir mode.")
                    208:
                    209: (defvar asir-font-lock-keywords asir-font-lock-keywords-3
                    210:   "Default expressions to highlight in asir mode.")
                    211:
                    212: (defvar asir-mode-syntax-table nil
                    213:   "Syntax table used in asir-mode buffers.")
                    214: (or asir-mode-syntax-table
                    215:     (setq asir-mode-syntax-table
                    216:          (funcall (c-lang-const c-make-mode-syntax-table asir))))
                    217:
                    218: (defvar asir-mode-abbrev-table nil
                    219:   "Abbreviation table used in asir-mode buffers.")
                    220:
                    221: (defvar asir-mode-map (let ((map (c-make-inherited-keymap)))
                    222:                      ;; Add bindings which are only useful for asir
                    223:                      map)
                    224:   "Keymap used in asir-mode buffers.")
                    225:
1.10      takayama  226: ;; Key binding for asir-mode
                    227: (define-key asir-mode-map (kbd "C-c s") 'asir-start)
                    228: (define-key asir-mode-map (kbd "C-c t") 'asir-terminate)
                    229: (define-key asir-mode-map (kbd "C-c l") 'asir-execute-current-buffer)
                    230: (define-key asir-mode-map (kbd "C-c r") 'asir-execute-region)
                    231: (define-key asir-mode-map (kbd "C-c p") 'asir-paste-region)
                    232:
1.1       takayama  233: (easy-menu-define asir-menu asir-mode-map "asir Mode Commands"
                    234:                  ;; Can use `asir' as the language for `c-mode-menu'
                    235:                  ;; since its definition covers any language.  In
                    236:                  ;; this case the language is used to adapt to the
                    237:                  ;; nonexistence of a cpp pass and thus removing some
                    238:                  ;; irrelevant menu alternatives.
                    239:                  (cons "Asir" (c-lang-const c-mode-menu asir)))
                    240:
                    241: (defun asir-mode ()
                    242:   "Major mode for editing asir code.
                    243: This is a simple example of a separate mode derived from CC Mode to
                    244: support a language with syntax similar to C/C++/ObjC/Java/IDL/Pike.
                    245:
                    246: The hook `c-mode-common-hook' is run with no args at mode
                    247: initialization, then `asir-mode-hook'.
                    248:
                    249: Key bindings:
                    250: \\{asir-mode-map}"
                    251:   (interactive)
                    252:   (kill-all-local-variables)
                    253:   (c-initialize-cc-mode t)
                    254:   (set-syntax-table asir-mode-syntax-table)
                    255:   (setq major-mode 'asir-mode
                    256:        mode-name "asir"
                    257:        local-abbrev-table asir-mode-abbrev-table
                    258:        abbrev-mode t)
                    259:   (use-local-map asir-mode-map)
                    260:   ;; `c-init-language-vars' is a macro that is expanded at compile
                    261:   ;; time to a large `setq' with all the language variables and their
                    262:   ;; customized values for our language.
                    263:   (c-init-language-vars asir-mode)
                    264:   ;; `c-common-init' initializes most of the components of a CC Mode
                    265:   ;; buffer, including setup of the mode menu, font-lock, etc.
                    266:   ;; There's also a lower level routine `c-basic-common-init' that
                    267:   ;; only makes the necessary initialization to get the syntactic
                    268:   ;; analysis and similar things working.
                    269:   (c-common-init 'asir-mode)
                    270: ;;(easy-menu-add asir-menu)
                    271:   (run-hooks 'c-mode-common-hook)
                    272:   (run-hooks 'asir-mode-hook)
                    273:   (c-update-modeline))
                    274:
                    275: (if (fboundp 'asir-backup:c-guess-basic-syntax)
                    276:        nil
                    277:   (fset 'asir-backup:c-guess-basic-syntax (symbol-function 'c-guess-basic-syntax))
                    278:   (defun c-guess-basic-syntax ()
                    279:        "A modified c-guess-basic-syntax for asir-mode"
                    280:        (if (eq major-mode 'asir-mode)
                    281:                (asir-c-guess-basic-syntax)
                    282:          (asir-backup:c-guess-basic-syntax))))
                    283:
                    284: ;; Meadow 3 does not have `c-brace-anchor-point'
                    285: ;; This function was copied from cc-engine.el of Emacs 23.4
                    286: (if (and (featurep 'meadow) (not (fboundp 'c-brace-anchor-point)))
                    287:     (defun c-brace-anchor-point (bracepos)
                    288:       ;; BRACEPOS is the position of a brace in a construct like "namespace
                    289:       ;; Bar {".  Return the anchor point in this construct; this is the
                    290:       ;; earliest symbol on the brace's line which isn't earlier than
                    291:       ;; "namespace".
                    292:       ;;
                    293:       ;; Currently (2007-08-17), "like namespace" means "matches
                    294:       ;; c-other-block-decl-kwds".  It doesn't work with "class" or "struct"
                    295:       ;; or anything like that.
                    296:       (save-excursion
                    297:         (let ((boi (c-point 'boi bracepos)))
                    298:           (goto-char bracepos)
                    299:           (while (and (> (point) boi)
                    300:                       (not (looking-at c-other-decl-block-key)))
                    301:             (c-backward-token-2))
                    302:           (if (> (point) boi) (point) boi))))
                    303:   )
                    304:
                    305: ;; The function `c-guess-basic-syntax' was copied from cc-engine.el of Emacs 23.4 and
                    306: ;; was modified for Risa/Asir.
                    307: ;; CASE 5D, 5J, 18 are corrected.
                    308:
                    309: ;;;; Beginning of `asir-c-guess-basic-syntax'
                    310: (defun asir-c-guess-basic-syntax ()
                    311:   "Return the syntactic context of the current line."
                    312:   (save-excursion
                    313:       (beginning-of-line)
                    314:       (c-save-buffer-state
                    315:          ((indent-point (point))
                    316:           (case-fold-search nil)
                    317:           ;; A whole ugly bunch of various temporary variables.  Have
                    318:           ;; to declare them here since it's not possible to declare
                    319:           ;; a variable with only the scope of a cond test and the
                    320:           ;; following result clauses, and most of this function is a
                    321:           ;; single gigantic cond. :P
                    322:           literal char-before-ip before-ws-ip char-after-ip macro-start
                    323:           in-macro-expr c-syntactic-context placeholder c-in-literal-cache
                    324:           step-type tmpsymbol keyword injava-inher special-brace-list tmp-pos
                    325:           containing-<
                    326:           ;; The following record some positions for the containing
                    327:           ;; declaration block if we're directly within one:
                    328:           ;; `containing-decl-open' is the position of the open
                    329:           ;; brace.  `containing-decl-start' is the start of the
                    330:           ;; declaration.  `containing-decl-kwd' is the keyword
                    331:           ;; symbol of the keyword that tells what kind of block it
                    332:           ;; is.
                    333:           containing-decl-open
                    334:           containing-decl-start
                    335:           containing-decl-kwd
                    336:           ;; The open paren of the closest surrounding sexp or nil if
                    337:           ;; there is none.
                    338:           containing-sexp
                    339:           ;; The position after the closest preceding brace sexp
                    340:           ;; (nested sexps are ignored), or the position after
                    341:           ;; `containing-sexp' if there is none, or (point-min) if
                    342:           ;; `containing-sexp' is nil.
                    343:           lim
                    344:           ;; The paren state outside `containing-sexp', or at
                    345:           ;; `indent-point' if `containing-sexp' is nil.
                    346:           (paren-state (c-parse-state))
                    347:           ;; There's always at most one syntactic element which got
                    348:           ;; an anchor pos.  It's stored in syntactic-relpos.
                    349:           syntactic-relpos
                    350:           (c-stmt-delim-chars c-stmt-delim-chars))
                    351:
                    352:        ;; Check if we're directly inside an enclosing declaration
                    353:        ;; level block.
                    354:        (when (and (setq containing-sexp
                    355:                         (c-most-enclosing-brace paren-state))
                    356:                   (progn
                    357:                     (goto-char containing-sexp)
                    358:                     (eq (char-after) ?{))
                    359:                   (setq placeholder
                    360:                         (c-looking-at-decl-block
                    361:                          (c-most-enclosing-brace paren-state
                    362:                                                  containing-sexp)
                    363:                          t)))
                    364:          (setq containing-decl-open containing-sexp
                    365:                containing-decl-start (point)
                    366:                containing-sexp nil)
                    367:          (goto-char placeholder)
                    368:          (setq containing-decl-kwd (and (looking-at c-keywords-regexp)
                    369:                                         (c-keyword-sym (match-string 1)))))
                    370:
                    371:        ;; Init some position variables.
                    372:        (if c-state-cache
                    373:            (progn
                    374:              (setq containing-sexp (car paren-state)
                    375:                    paren-state (cdr paren-state))
                    376:              (if (consp containing-sexp)
                    377:                  (progn
                    378:                    (setq lim (cdr containing-sexp))
                    379:                    (if (cdr c-state-cache)
                    380:                        ;; Ignore balanced paren.  The next entry
                    381:                        ;; can't be another one.
                    382:                        (setq containing-sexp (car (cdr c-state-cache))
                    383:                              paren-state (cdr paren-state))
                    384:                      ;; If there is no surrounding open paren then
                    385:                      ;; put the last balanced pair back on paren-state.
                    386:                      (setq paren-state (cons containing-sexp paren-state)
                    387:                            containing-sexp nil)))
                    388:                (setq lim (1+ containing-sexp))))
                    389:          (setq lim (point-min)))
                    390:
                    391:        ;; If we're in a parenthesis list then ',' delimits the
                    392:        ;; "statements" rather than being an operator (with the
                    393:        ;; exception of the "for" clause).  This difference is
                    394:        ;; typically only noticeable when statements are used in macro
                    395:        ;; arglists.
                    396:        (when (and containing-sexp
                    397:                   (eq (char-after containing-sexp) ?\())
                    398:          (setq c-stmt-delim-chars c-stmt-delim-chars-with-comma))
                    399:
                    400:        ;; cache char before and after indent point, and move point to
                    401:        ;; the most likely position to perform the majority of tests
                    402:        (goto-char indent-point)
                    403:        (c-backward-syntactic-ws lim)
                    404:        (setq before-ws-ip (point)
                    405:              char-before-ip (char-before))
                    406:        (goto-char indent-point)
                    407:        (skip-chars-forward " \t")
                    408:        (setq char-after-ip (char-after))
                    409:
                    410:        ;; are we in a literal?
                    411:        (setq literal (c-in-literal lim))
                    412:
                    413:        ;; now figure out syntactic qualities of the current line
                    414:        (cond
                    415:
                    416:         ;; CASE 1: in a string.
                    417:         ((eq literal 'string)
                    418:          (c-add-syntax 'string (c-point 'bopl)))
                    419:
                    420:         ;; CASE 2: in a C or C++ style comment.
                    421:         ((and (memq literal '(c c++))
                    422:               ;; This is a kludge for XEmacs where we use
                    423:               ;; `buffer-syntactic-context', which doesn't correctly
                    424:               ;; recognize "\*/" to end a block comment.
                    425:               ;; `parse-partial-sexp' which is used by
                    426:               ;; `c-literal-limits' will however do that in most
                    427:               ;; versions, which results in that we get nil from
                    428:               ;; `c-literal-limits' even when `c-in-literal' claims
                    429:               ;; we're inside a comment.
                    430:               (setq placeholder (c-literal-limits lim)))
                    431:          (c-add-syntax literal (car placeholder)))
                    432:
                    433:         ;; CASE 3: in a cpp preprocessor macro continuation.
                    434:         ((and (save-excursion
                    435:                 (when (c-beginning-of-macro)
                    436:                   (setq macro-start (point))))
                    437:               (/= macro-start (c-point 'boi))
                    438:               (progn
                    439:                 (setq tmpsymbol 'cpp-macro-cont)
                    440:                 (or (not c-syntactic-indentation-in-macros)
                    441:                     (save-excursion
                    442:                       (goto-char macro-start)
                    443:                       ;; If at the beginning of the body of a #define
                    444:                       ;; directive then analyze as cpp-define-intro
                    445:                       ;; only.  Go on with the syntactic analysis
                    446:                       ;; otherwise.  in-macro-expr is set if we're in a
                    447:                       ;; cpp expression, i.e. before the #define body
                    448:                       ;; or anywhere in a non-#define directive.
                    449:                       (if (c-forward-to-cpp-define-body)
                    450:                           (let ((indent-boi (c-point 'boi indent-point)))
                    451:                             (setq in-macro-expr (> (point) indent-boi)
                    452:                                   tmpsymbol 'cpp-define-intro)
                    453:                             (= (point) indent-boi))
                    454:                         (setq in-macro-expr t)
                    455:                         nil)))))
                    456:          (c-add-syntax tmpsymbol macro-start)
                    457:          (setq macro-start nil))
                    458:
                    459:         ;; CASE 11: an else clause?
                    460:         ((looking-at "else\\>[^_]")
                    461:          (c-beginning-of-statement-1 containing-sexp)
                    462:          (c-add-stmt-syntax 'else-clause nil t
                    463:                             containing-sexp paren-state))
                    464:
                    465:         ;; CASE 12: while closure of a do/while construct?
                    466:         ((and (looking-at "while\\>[^_]")
                    467:               (save-excursion
                    468:                 (prog1 (eq (c-beginning-of-statement-1 containing-sexp)
                    469:                            'beginning)
                    470:                   (setq placeholder (point)))))
                    471:          (goto-char placeholder)
                    472:          (c-add-stmt-syntax 'do-while-closure nil t
                    473:                             containing-sexp paren-state))
                    474:
                    475:         ;; CASE 13: A catch or finally clause?  This case is simpler
                    476:         ;; than if-else and do-while, because a block is required
                    477:         ;; after every try, catch and finally.
                    478:         ((save-excursion
                    479:            (and (cond ((c-major-mode-is 'c++-mode)
                    480:                        (looking-at "catch\\>[^_]"))
                    481:                       ((c-major-mode-is 'java-mode)
                    482:                        (looking-at "\\(catch\\|finally\\)\\>[^_]")))
                    483:                 (and (c-safe (c-backward-syntactic-ws)
                    484:                              (c-backward-sexp)
                    485:                              t)
                    486:                      (eq (char-after) ?{)
                    487:                      (c-safe (c-backward-syntactic-ws)
                    488:                              (c-backward-sexp)
                    489:                              t)
                    490:                      (if (eq (char-after) ?\()
                    491:                          (c-safe (c-backward-sexp) t)
                    492:                        t))
                    493:                 (looking-at "\\(try\\|catch\\)\\>[^_]")
                    494:                 (setq placeholder (point))))
                    495:          (goto-char placeholder)
                    496:          (c-add-stmt-syntax 'catch-clause nil t
                    497:                             containing-sexp paren-state))
                    498:
                    499:         ;; CASE 18: A substatement we can recognize by keyword.
                    500:         ((save-excursion
                    501:            (and c-opt-block-stmt-key
                    502:                 (not (eq char-before-ip ?\;))
                    503:                 (not (c-at-vsemi-p before-ws-ip))
                    504:                 (not (memq char-after-ip '(?\) ?\] ?,)))
                    505:                 (or (not (eq char-before-ip ?}))
                    506:                     (c-looking-at-inexpr-block-backward c-state-cache))
                    507:                 (> (point)
                    508:                    (progn
                    509:                      ;; Ought to cache the result from the
                    510:                      ;; c-beginning-of-statement-1 calls here.
                    511:                      (setq placeholder (point))
                    512:                      (while (eq (setq step-type
                    513:                                       (c-beginning-of-statement-1 lim))
                    514:                                 'label))
                    515:                      (if (eq step-type 'previous)
                    516:                          (goto-char placeholder)
                    517:                        (setq placeholder (point))
                    518:                        (if (and (eq step-type 'same)
                    519:                                 (not (looking-at c-opt-block-stmt-key)))
                    520:                            ;; Step up to the containing statement if we
                    521:                            ;; stayed in the same one.
                    522:                            (let (step)
                    523:                              (while (eq
                    524:                                      (setq step
                    525:                                            (c-beginning-of-statement-1 lim))
                    526:                                      'label))
                    527:                              (if (eq step 'up)
                    528:                                  (setq placeholder (point))
                    529:                                ;; There was no containing statement after all.
                    530:                                (goto-char placeholder)))))
                    531:                      placeholder))
                    532:                 (if (looking-at c-block-stmt-2-key)
                    533:                     ;; Require a parenthesis after these keywords.
                    534:                     ;; Necessary to catch e.g. synchronized in Java,
                    535:                     ;; which can be used both as statement and
                    536:                     ;; modifier.
                    537:                     (and (zerop (c-forward-token-2 1 nil))
                    538:                          (eq (char-after) ?\())
                    539:                   (looking-at c-opt-block-stmt-key))))
                    540:
                    541:          (if (eq step-type 'up)
                    542:              ;; CASE 18A: Simple substatement.
                    543:              (progn
                    544:                (goto-char placeholder)
                    545:                (cond
                    546:                 ((eq char-after-ip ?{)
                    547:                  (c-add-stmt-syntax 'substatement-open nil nil
                    548:                                     containing-sexp paren-state))
                    549:                 ((save-excursion
                    550:                    (goto-char indent-point)
                    551:                    (back-to-indentation)
                    552:                    (c-forward-label))
                    553:                  (c-add-stmt-syntax 'substatement-label nil nil
                    554:                                     containing-sexp paren-state))
                    555:                 (t
                    556:                  (c-add-stmt-syntax 'substatement nil nil
                    557:                                     containing-sexp paren-state))))
                    558:
                    559:            ;; CASE 18B: Some other substatement.  This is shared
                    560:            ;; with case 10.
                    561:            (c-guess-continued-construct indent-point
                    562:                                         char-after-ip
                    563:                                         placeholder
                    564:                                         lim
                    565:                                         paren-state)))
                    566:
                    567:         ;; CASE 14: A case or default label
                    568:         ((looking-at c-label-kwds-regexp)
                    569:          (if containing-sexp
                    570:              (progn
                    571:                (goto-char containing-sexp)
                    572:                (setq lim (c-most-enclosing-brace c-state-cache
                    573:                                                  containing-sexp))
                    574:                (c-backward-to-block-anchor lim)
                    575:                (c-add-stmt-syntax 'case-label nil t lim paren-state))
                    576:            ;; Got a bogus label at the top level.  In lack of better
                    577:            ;; alternatives, anchor it on (point-min).
                    578:            (c-add-syntax 'case-label (point-min))))
                    579:
                    580:         ;; CASE 15: any other label
                    581:         ((save-excursion
                    582:            (back-to-indentation)
                    583:            (and (not (looking-at c-syntactic-ws-start))
                    584:                 (c-forward-label)))
                    585:          (cond (containing-decl-open
                    586:                 (setq placeholder (c-add-class-syntax 'inclass
                    587:                                                       containing-decl-open
                    588:                                                       containing-decl-start
                    589:                                                       containing-decl-kwd
                    590:                                                       paren-state))
                    591:                 ;; Append access-label with the same anchor point as
                    592:                 ;; inclass gets.
                    593:                 (c-append-syntax 'access-label placeholder))
                    594:
                    595:                (containing-sexp
                    596:                 (goto-char containing-sexp)
                    597:                 (setq lim (c-most-enclosing-brace c-state-cache
                    598:                                                   containing-sexp))
                    599:                 (save-excursion
                    600:                   (setq tmpsymbol
                    601:                         (if (and (eq (c-beginning-of-statement-1 lim) 'up)
                    602:                                  (looking-at "switch\\>[^_]"))
                    603:                             ;; If the surrounding statement is a switch then
                    604:                             ;; let's analyze all labels as switch labels, so
                    605:                             ;; that they get lined up consistently.
                    606:                             'case-label
                    607:                           'label)))
                    608:                 (c-backward-to-block-anchor lim)
                    609:                 (c-add-stmt-syntax tmpsymbol nil t lim paren-state))
                    610:
                    611:                (t
                    612:                 ;; A label on the top level.  Treat it as a class
                    613:                 ;; context.  (point-min) is the closest we get to the
                    614:                 ;; class open brace.
                    615:                 (c-add-syntax 'access-label (point-min)))))
                    616:
                    617:         ;; CASE 4: In-expression statement.  C.f. cases 7B, 16A and
                    618:         ;; 17E.
                    619:         ((setq placeholder (c-looking-at-inexpr-block
                    620:                             (c-safe-position containing-sexp paren-state)
                    621:                             containing-sexp
                    622:                             ;; Have to turn on the heuristics after
                    623:                             ;; the point even though it doesn't work
                    624:                             ;; very well.  C.f. test case class-16.pike.
                    625:                             t))
                    626:          (setq tmpsymbol (assq (car placeholder)
                    627:                                '((inexpr-class . class-open)
                    628:                                  (inexpr-statement . block-open))))
                    629:          (if tmpsymbol
                    630:              ;; It's a statement block or an anonymous class.
                    631:              (setq tmpsymbol (cdr tmpsymbol))
                    632:            ;; It's a Pike lambda.  Check whether we are between the
                    633:            ;; lambda keyword and the argument list or at the defun
                    634:            ;; opener.
                    635:            (setq tmpsymbol (if (eq char-after-ip ?{)
                    636:                                'inline-open
                    637:                              'lambda-intro-cont)))
                    638:          (goto-char (cdr placeholder))
                    639:          (back-to-indentation)
                    640:          (c-add-stmt-syntax tmpsymbol nil t
                    641:                             (c-most-enclosing-brace c-state-cache (point))
                    642:                             paren-state)
                    643:          (unless (eq (point) (cdr placeholder))
                    644:            (c-add-syntax (car placeholder))))
                    645:
                    646:         ;; CASE 5: Line is inside a declaration level block or at top level.
                    647:         ((or containing-decl-open (null containing-sexp))
                    648:          (cond
                    649:
                    650:           ;; CASE 5A: we are looking at a defun, brace list, class,
                    651:           ;; or inline-inclass method opening brace
                    652:           ((setq special-brace-list
                    653:                  (or (and c-special-brace-lists
                    654:                           (c-looking-at-special-brace-list))
                    655:                      (eq char-after-ip ?{)))
                    656:            (cond
                    657:
                    658:             ;; CASE 5A.1: Non-class declaration block open.
                    659:             ((save-excursion
                    660:                (let (tmp)
                    661:                  (and (eq char-after-ip ?{)
                    662:                       (setq tmp (c-looking-at-decl-block containing-sexp t))
                    663:                       (progn
                    664:                         (setq placeholder (point))
                    665:                         (goto-char tmp)
                    666:                         (looking-at c-symbol-key))
                    667:                       (c-keyword-member
                    668:                        (c-keyword-sym (setq keyword (match-string 0)))
                    669:                        'c-other-block-decl-kwds))))
                    670:              (goto-char placeholder)
                    671:              (c-add-stmt-syntax
                    672:               (if (string-equal keyword "extern")
                    673:                   ;; Special case for extern-lang-open.
                    674:                   'extern-lang-open
                    675:                 (intern (concat keyword "-open")))
                    676:               nil t containing-sexp paren-state))
                    677:
                    678:             ;; CASE 5A.2: we are looking at a class opening brace
                    679:             ((save-excursion
                    680:                (goto-char indent-point)
                    681:                (skip-chars-forward " \t")
                    682:                (and (eq (char-after) ?{)
                    683:                     (c-looking-at-decl-block containing-sexp t)
                    684:                     (setq placeholder (point))))
                    685:              (c-add-syntax 'class-open placeholder))
                    686:
                    687:             ;; CASE 5A.3: brace list open
                    688:             ((save-excursion
                    689:                (c-beginning-of-decl-1 lim)
                    690:                (while (looking-at c-specifier-key)
                    691:                  (goto-char (match-end 1))
                    692:                  (c-forward-syntactic-ws indent-point))
                    693:                (setq placeholder (c-point 'boi))
                    694:                (or (consp special-brace-list)
                    695:                    (and (or (save-excursion
                    696:                               (goto-char indent-point)
                    697:                               (setq tmpsymbol nil)
                    698:                               (while (and (> (point) placeholder)
                    699:                                           (zerop (c-backward-token-2 1 t))
                    700:                                           (/= (char-after) ?=))
                    701:                                 (and c-opt-inexpr-brace-list-key
                    702:                                      (not tmpsymbol)
                    703:                                      (looking-at c-opt-inexpr-brace-list-key)
                    704:                                      (setq tmpsymbol 'topmost-intro-cont)))
                    705:                               (eq (char-after) ?=))
                    706:                             (looking-at c-brace-list-key))
                    707:                         (save-excursion
                    708:                           (while (and (< (point) indent-point)
                    709:                                       (zerop (c-forward-token-2 1 t))
                    710:                                       (not (memq (char-after) '(?\; ?\()))))
                    711:                           (not (memq (char-after) '(?\; ?\()))
                    712:                           ))))
                    713:              (if (and (not c-auto-newline-analysis)
                    714:                       (c-major-mode-is 'java-mode)
                    715:                       (eq tmpsymbol 'topmost-intro-cont))
                    716:                  ;; We're in Java and have found that the open brace
                    717:                  ;; belongs to a "new Foo[]" initialization list,
                    718:                  ;; which means the brace list is part of an
                    719:                  ;; expression and not a top level definition.  We
                    720:                  ;; therefore treat it as any topmost continuation
                    721:                  ;; even though the semantically correct symbol still
                    722:                  ;; is brace-list-open, on the same grounds as in
                    723:                  ;; case B.2.
                    724:                  (progn
                    725:                    (c-beginning-of-statement-1 lim)
                    726:                    (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
                    727:                (c-add-syntax 'brace-list-open placeholder)))
                    728:
                    729:             ;; CASE 5A.4: inline defun open
                    730:             ((and containing-decl-open
                    731:                   (not (c-keyword-member containing-decl-kwd
                    732:                                          'c-other-block-decl-kwds)))
                    733:              (c-add-syntax 'inline-open)
                    734:              (c-add-class-syntax 'inclass
                    735:                                  containing-decl-open
                    736:                                  containing-decl-start
                    737:                                  containing-decl-kwd
                    738:                                  paren-state))
                    739:
                    740:             ;; CASE 5A.5: ordinary defun open
                    741:             (t
                    742:              (save-excursion
                    743:                (c-beginning-of-decl-1 lim)
                    744:                (while (looking-at c-specifier-key)
                    745:                  (goto-char (match-end 1))
                    746:                  (c-forward-syntactic-ws indent-point))
                    747:                (c-add-syntax 'defun-open (c-point 'boi))
                    748:                ;; Bogus to use bol here, but it's the legacy.  (Resolved,
                    749:                ;; 2007-11-09)
                    750:                ))))
                    751:
                    752:           ;; CASE 5B: After a function header but before the body (or
                    753:           ;; the ending semicolon if there's no body).
                    754:           ((save-excursion
                    755:              (when (setq placeholder (c-just-after-func-arglist-p lim))
                    756:                (setq tmp-pos (point))))
                    757:            (cond
                    758:
                    759:             ;; CASE 5B.1: Member init list.
                    760:             ((eq (char-after tmp-pos) ?:)
                    761:              (if (or (> tmp-pos indent-point)
                    762:                      (= (c-point 'bosws) (1+ tmp-pos)))
                    763:                  (progn
                    764:                    ;; There is no preceding member init clause.
                    765:                    ;; Indent relative to the beginning of indentation
                    766:                    ;; for the topmost-intro line that contains the
                    767:                    ;; prototype's open paren.
                    768:                    (goto-char placeholder)
                    769:                    (c-add-syntax 'member-init-intro (c-point 'boi)))
                    770:                ;; Indent relative to the first member init clause.
                    771:                (goto-char (1+ tmp-pos))
                    772:                (c-forward-syntactic-ws)
                    773:                (c-add-syntax 'member-init-cont (point))))
                    774:
                    775:             ;; CASE 5B.2: K&R arg decl intro
                    776:             ((and c-recognize-knr-p
                    777:                   (c-in-knr-argdecl lim))
                    778:              (c-beginning-of-statement-1 lim)
                    779:              (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
                    780:              (if containing-decl-open
                    781:                  (c-add-class-syntax 'inclass
                    782:                                      containing-decl-open
                    783:                                      containing-decl-start
                    784:                                      containing-decl-kwd
                    785:                                      paren-state)))
                    786:
                    787:             ;; CASE 5B.4: Nether region after a C++ or Java func
                    788:             ;; decl, which could include a `throws' declaration.
                    789:             (t
                    790:              (c-beginning-of-statement-1 lim)
                    791:              (c-add-syntax 'func-decl-cont (c-point 'boi))
                    792:              )))
                    793:
                    794:           ;; CASE 5C: inheritance line. could be first inheritance
                    795:           ;; line, or continuation of a multiple inheritance
                    796:           ((or (and (c-major-mode-is 'c++-mode)
                    797:                     (progn
                    798:                       (when (eq char-after-ip ?,)
                    799:                         (skip-chars-forward " \t")
                    800:                         (forward-char))
                    801:                       (looking-at c-opt-postfix-decl-spec-key)))
                    802:                (and (or (eq char-before-ip ?:)
                    803:                         ;; watch out for scope operator
                    804:                         (save-excursion
                    805:                           (and (eq char-after-ip ?:)
                    806:                                (c-safe (forward-char 1) t)
                    807:                                (not (eq (char-after) ?:))
                    808:                                )))
                    809:                     (save-excursion
                    810:                       (c-backward-syntactic-ws lim)
                    811:                       (if (eq char-before-ip ?:)
                    812:                           (progn
                    813:                             (forward-char -1)
                    814:                             (c-backward-syntactic-ws lim)))
                    815:                       (back-to-indentation)
                    816:                       (looking-at c-class-key)))
                    817:                ;; for Java
                    818:                (and (c-major-mode-is 'java-mode)
                    819:                     (let ((fence (save-excursion
                    820:                                    (c-beginning-of-statement-1 lim)
                    821:                                    (point)))
                    822:                           cont done)
                    823:                       (save-excursion
                    824:                         (while (not done)
                    825:                           (cond ((looking-at c-opt-postfix-decl-spec-key)
                    826:                                  (setq injava-inher (cons cont (point))
                    827:                                        done t))
                    828:                                 ((or (not (c-safe (c-forward-sexp -1) t))
                    829:                                      (<= (point) fence))
                    830:                                  (setq done t))
                    831:                                 )
                    832:                           (setq cont t)))
                    833:                       injava-inher)
                    834:                     (not (c-crosses-statement-barrier-p (cdr injava-inher)
                    835:                                                         (point)))
                    836:                     ))
                    837:            (cond
                    838:
                    839:             ;; CASE 5C.1: non-hanging colon on an inher intro
                    840:             ((eq char-after-ip ?:)
                    841:              (c-beginning-of-statement-1 lim)
                    842:              (c-add-syntax 'inher-intro (c-point 'boi))
                    843:              ;; don't add inclass symbol since relative point already
                    844:              ;; contains any class offset
                    845:              )
                    846:
                    847:             ;; CASE 5C.2: hanging colon on an inher intro
                    848:             ((eq char-before-ip ?:)
                    849:              (c-beginning-of-statement-1 lim)
                    850:              (c-add-syntax 'inher-intro (c-point 'boi))
                    851:              (if containing-decl-open
                    852:                  (c-add-class-syntax 'inclass
                    853:                                      containing-decl-open
                    854:                                      containing-decl-start
                    855:                                      containing-decl-kwd
                    856:                                      paren-state)))
                    857:
                    858:             ;; CASE 5C.3: in a Java implements/extends
                    859:             (injava-inher
                    860:              (let ((where (cdr injava-inher))
                    861:                    (cont (car injava-inher)))
                    862:                (goto-char where)
                    863:                (cond ((looking-at "throws\\>[^_]")
                    864:                       (c-add-syntax 'func-decl-cont
                    865:                                     (progn (c-beginning-of-statement-1 lim)
                    866:                                            (c-point 'boi))))
                    867:                      (cont (c-add-syntax 'inher-cont where))
                    868:                      (t (c-add-syntax 'inher-intro
                    869:                                       (progn (goto-char (cdr injava-inher))
                    870:                                              (c-beginning-of-statement-1 lim)
                    871:                                              (point))))
                    872:                      )))
                    873:
                    874:             ;; CASE 5C.4: a continued inheritance line
                    875:             (t
                    876:              (c-beginning-of-inheritance-list lim)
                    877:              (c-add-syntax 'inher-cont (point))
                    878:              ;; don't add inclass symbol since relative point already
                    879:              ;; contains any class offset
                    880:              )))
                    881:
                    882:           ;; CASE 5D: this could be a top-level initialization, a
                    883:           ;; member init list continuation, or a template argument
                    884:           ;; list continuation.
                    885:           ((save-excursion
                    886:              ;; Note: We use the fact that lim is always after any
                    887:              ;; preceding brace sexp.
                    888:              (if c-recognize-<>-arglists
                    889:                  (while (and
                    890:                          (progn
                    891:                            (c-syntactic-skip-backward "^;$,=<>" lim t)
                    892:                            (> (point) lim))
                    893:                          (or
                    894:                           (when c-overloadable-operators-regexp
                    895:                             (when (setq placeholder (c-after-special-operator-id lim))
                    896:                               (goto-char placeholder)
                    897:                               t))
                    898:                           (cond
                    899:                            ((eq (char-before) ?>)
                    900:                             (or (c-backward-<>-arglist nil lim)
                    901:                                 (backward-char))
                    902:                             t)
                    903:                            ((eq (char-before) ?<)
                    904:                             (backward-char)
                    905:                             (if (save-excursion
                    906:                                   (c-forward-<>-arglist nil))
                    907:                                 (progn (forward-char)
                    908:                                        nil)
                    909:                               t))
                    910:                            (t nil)))))
                    911:                ;; NB: No c-after-special-operator-id stuff in this
                    912:                ;; clause - we assume only C++ needs it.
                    913:                (c-syntactic-skip-backward "^;$,=" lim t))
                    914:              (memq (char-before) '(?, ?= ?<)))
                    915:            (cond
                    916:
                    917:             ;; CASE 5D.3: perhaps a template list continuation?
                    918:             ((and (c-major-mode-is 'c++-mode)
                    919:                   (save-excursion
                    920:                     (save-restriction
                    921:                       (c-with-syntax-table c++-template-syntax-table
                    922:                         (goto-char indent-point)
                    923:                         (setq placeholder (c-up-list-backward))
                    924:                         (and placeholder
                    925:                              (eq (char-after placeholder) ?<))))))
                    926:              (c-with-syntax-table c++-template-syntax-table
                    927:                (goto-char placeholder)
                    928:                (c-beginning-of-statement-1 lim t)
                    929:                (if (save-excursion
                    930:                      (c-backward-syntactic-ws lim)
                    931:                      (eq (char-before) ?<))
                    932:                    ;; In a nested template arglist.
                    933:                    (progn
                    934:                      (goto-char placeholder)
                    935:                      (c-syntactic-skip-backward "^,;" lim t)
                    936:                      (c-forward-syntactic-ws))
                    937:                  (back-to-indentation)))
                    938:              ;; FIXME: Should use c-add-stmt-syntax, but it's not yet
                    939:              ;; template aware.
                    940:              (c-add-syntax 'template-args-cont (point) placeholder))
                    941:
                    942:             ;; CASE 5D.4: perhaps a multiple inheritance line?
                    943:             ((and (c-major-mode-is 'c++-mode)
                    944:                   (save-excursion
                    945:                     (c-beginning-of-statement-1 lim)
                    946:                     (setq placeholder (point))
                    947:                     (if (looking-at "static\\>[^_]")
                    948:                         (c-forward-token-2 1 nil indent-point))
                    949:                     (and (looking-at c-class-key)
                    950:                          (zerop (c-forward-token-2 2 nil indent-point))
                    951:                          (if (eq (char-after) ?<)
                    952:                              (c-with-syntax-table c++-template-syntax-table
                    953:                                (zerop (c-forward-token-2 1 t indent-point)))
                    954:                            t)
                    955:                          (eq (char-after) ?:))))
                    956:              (goto-char placeholder)
                    957:              (c-add-syntax 'inher-cont (c-point 'boi)))
                    958:
                    959:             ;; CASE 5D.5: Continuation of the "expression part" of a
                    960:             ;; top level construct.  Or, perhaps, an unrecognized construct.
                    961:             (t
                    962:              (while (and (setq placeholder (point))
                    963:                          (eq (car (c-beginning-of-decl-1 containing-sexp))
                    964:                              'same)
                    965:                          (save-excursion
                    966:                            (c-backward-syntactic-ws)
                    967:                            (eq (char-before) ?}))
                    968:                          (< (point) placeholder)))
                    969:              (c-add-stmt-syntax
                    970:               (cond
                    971:                ((eq (point) placeholder) 'statement) ; unrecognized construct
                    972:                   ;; A preceding comma at the top level means that a
                    973:                   ;; new variable declaration starts here.  Use
                    974:                   ;; topmost-intro-cont for it, for consistency with
                    975:                   ;; the first variable declaration.  C.f. case 5N.
                    976:                ((eq char-before-ip ?,) 'topmost-intro-cont)
                    977:                (t 'statement-cont))
                    978:               nil nil containing-sexp paren-state))
                    979:             ))
                    980:
                    981:           ;; CASE 5F: Close of a non-class declaration level block.
                    982:           ((and (eq char-after-ip ?})
                    983:                 (c-keyword-member containing-decl-kwd
                    984:                                   'c-other-block-decl-kwds))
                    985:            ;; This is inconsistent: Should use `containing-decl-open'
                    986:            ;; here if it's at boi, like in case 5J.
                    987:            (goto-char containing-decl-start)
                    988:            (c-add-stmt-syntax
                    989:              (if (string-equal (symbol-name containing-decl-kwd) "extern")
                    990:                  ;; Special case for compatibility with the
                    991:                  ;; extern-lang syntactic symbols.
                    992:                  'extern-lang-close
                    993:                (intern (concat (symbol-name containing-decl-kwd)
                    994:                                "-close")))
                    995:              nil t
                    996:              (c-most-enclosing-brace paren-state (point))
                    997:              paren-state))
                    998:
                    999:           ;; CASE 5G: we are looking at the brace which closes the
                   1000:           ;; enclosing nested class decl
                   1001:           ((and containing-sexp
                   1002:                 (eq char-after-ip ?})
                   1003:                 (eq containing-decl-open containing-sexp))
                   1004:            (c-add-class-syntax 'class-close
                   1005:                                containing-decl-open
                   1006:                                containing-decl-start
                   1007:                                containing-decl-kwd
                   1008:                                paren-state))
                   1009:
                   1010:           ;; CASE 5H: we could be looking at subsequent knr-argdecls
                   1011:           ((and c-recognize-knr-p
                   1012:                 (not containing-sexp)  ; can't be knr inside braces.
                   1013:                 (not (eq char-before-ip ?}))
                   1014:                 (save-excursion
                   1015:                   (setq placeholder (cdr (c-beginning-of-decl-1 lim)))
                   1016:                   (and placeholder
                   1017:                        ;; Do an extra check to avoid tripping up on
                   1018:                        ;; statements that occur in invalid contexts
                   1019:                        ;; (e.g. in macro bodies where we don't really
                   1020:                        ;; know the context of what we're looking at).
                   1021:                        (not (and c-opt-block-stmt-key
                   1022:                                  (looking-at c-opt-block-stmt-key)))))
                   1023:                 (< placeholder indent-point))
                   1024:            (goto-char placeholder)
                   1025:            (c-add-syntax 'knr-argdecl (point)))
                   1026:
                   1027:           ;; CASE 5I: ObjC method definition.
                   1028:           ((and c-opt-method-key
                   1029:                 (looking-at c-opt-method-key))
                   1030:            (c-beginning-of-statement-1 nil t)
                   1031:            (if (= (point) indent-point)
                   1032:                ;; Handle the case when it's the first (non-comment)
                   1033:                ;; thing in the buffer.  Can't look for a 'same return
                   1034:                ;; value from cbos1 since ObjC directives currently
                   1035:                ;; aren't recognized fully, so that we get 'same
                   1036:                ;; instead of 'previous if it moved over a preceding
                   1037:                ;; directive.
                   1038:                (goto-char (point-min)))
                   1039:            (c-add-syntax 'objc-method-intro (c-point 'boi)))
                   1040:
                   1041:            ;; CASE 5P: AWK pattern or function or continuation
                   1042:            ;; thereof.
                   1043:            ((c-major-mode-is 'awk-mode)
                   1044:             (setq placeholder (point))
                   1045:             (c-add-stmt-syntax
                   1046:              (if (and (eq (c-beginning-of-statement-1) 'same)
                   1047:                       (/= (point) placeholder))
                   1048:                  'topmost-intro-cont
                   1049:                'topmost-intro)
                   1050:              nil nil
                   1051:              containing-sexp paren-state))
                   1052:
                   1053:           ;; CASE 5N: At a variable declaration that follows a class
                   1054:           ;; definition or some other block declaration that doesn't
                   1055:           ;; end at the closing '}'.  C.f. case 5D.5.
                   1056:           ((progn
                   1057:              (c-backward-syntactic-ws lim)
                   1058:              (and (eq (char-before) ?})
                   1059:                   (save-excursion
                   1060:                     (let ((start (point)))
                   1061:                       (if (and c-state-cache
                   1062:                                (consp (car c-state-cache))
                   1063:                                (eq (cdar c-state-cache) (point)))
                   1064:                           ;; Speed up the backward search a bit.
                   1065:                           (goto-char (caar c-state-cache)))
                   1066:                       (c-beginning-of-decl-1 containing-sexp)
                   1067:                       (setq placeholder (point))
                   1068:                       (if (= start (point))
                   1069:                           ;; The '}' is unbalanced.
                   1070:                           nil
                   1071:                         (c-end-of-decl-1)
                   1072:                         (>= (point) indent-point))))))
                   1073:            (goto-char placeholder)
                   1074:            (c-add-stmt-syntax 'topmost-intro-cont nil nil
                   1075:                               containing-sexp paren-state))
                   1076:
                   1077:           ;; NOTE: The point is at the end of the previous token here.
                   1078:
                   1079:           ;; CASE 5J: we are at the topmost level, make
                   1080:           ;; sure we skip back past any access specifiers
                   1081:           ((and
                   1082:             ;; A macro continuation line is never at top level.
                   1083:             (not (and macro-start
                   1084:                       (> indent-point macro-start)))
                   1085:             (save-excursion
                   1086:               (setq placeholder (point))
                   1087:               (or (memq char-before-ip '(?\; ?$ ?{ ?} nil))
                   1088:                   (c-at-vsemi-p before-ws-ip)
                   1089:                   (when (and (eq char-before-ip ?:)
                   1090:                              (eq (c-beginning-of-statement-1 lim)
                   1091:                                  'label))
                   1092:                     (c-backward-syntactic-ws lim)
                   1093:                     (setq placeholder (point)))
                   1094:                   (and (c-major-mode-is 'objc-mode)
                   1095:                        (catch 'not-in-directive
                   1096:                          (c-beginning-of-statement-1 lim)
                   1097:                          (setq placeholder (point))
                   1098:                          (while (and (c-forward-objc-directive)
                   1099:                                      (< (point) indent-point))
                   1100:                            (c-forward-syntactic-ws)
                   1101:                            (if (>= (point) indent-point)
                   1102:                                (throw 'not-in-directive t))
                   1103:                            (setq placeholder (point)))
                   1104:                          nil)))))
                   1105:            ;; For historic reasons we anchor at bol of the last
                   1106:            ;; line of the previous declaration.  That's clearly
                   1107:            ;; highly bogus and useless, and it makes our lives hard
                   1108:            ;; to remain compatible.  :P
                   1109:            (goto-char placeholder)
                   1110:            (c-add-syntax 'topmost-intro (c-point 'bol))
                   1111:            (if containing-decl-open
                   1112:                (if (c-keyword-member containing-decl-kwd
                   1113:                                      'c-other-block-decl-kwds)
                   1114:                    (progn
                   1115:                      (goto-char (c-brace-anchor-point containing-decl-open))
                   1116:                      (c-add-stmt-syntax
                   1117:                       (if (string-equal (symbol-name containing-decl-kwd)
                   1118:                                         "extern")
                   1119:                           ;; Special case for compatibility with the
                   1120:                           ;; extern-lang syntactic symbols.
                   1121:                           'inextern-lang
                   1122:                         (intern (concat "in"
                   1123:                                         (symbol-name containing-decl-kwd))))
                   1124:                       nil t
                   1125:                       (c-most-enclosing-brace paren-state (point))
                   1126:                       paren-state))
                   1127:                  (c-add-class-syntax 'inclass
                   1128:                                      containing-decl-open
                   1129:                                      containing-decl-start
                   1130:                                      containing-decl-kwd
                   1131:                                      paren-state)))
                   1132:            (when (and c-syntactic-indentation-in-macros
                   1133:                       macro-start
                   1134:                       (/= macro-start (c-point 'boi indent-point)))
                   1135:              (c-add-syntax 'cpp-define-intro)
                   1136:              (setq macro-start nil)))
                   1137:
                   1138:           ;; CASE 5K: we are at an ObjC method definition
                   1139:           ;; continuation line.
                   1140:           ((and c-opt-method-key
                   1141:                 (save-excursion
                   1142:                   (c-beginning-of-statement-1 lim)
                   1143:                   (beginning-of-line)
                   1144:                   (when (looking-at c-opt-method-key)
                   1145:                     (setq placeholder (point)))))
                   1146:            (c-add-syntax 'objc-method-args-cont placeholder))
                   1147:
                   1148:           ;; CASE 5L: we are at the first argument of a template
                   1149:           ;; arglist that begins on the previous line.
                   1150:           ((and c-recognize-<>-arglists
                   1151:                 (eq (char-before) ?<)
                   1152:                 (setq placeholder (1- (point)))
                   1153:                 (not (and c-overloadable-operators-regexp
                   1154:                           (c-after-special-operator-id lim))))
                   1155:            (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
                   1156:            (c-add-syntax 'template-args-cont (c-point 'boi) placeholder))
                   1157:
                   1158:           ;; CASE 5Q: we are at a statement within a macro.
                   1159:           (macro-start
                   1160:            (c-beginning-of-statement-1 containing-sexp)
                   1161:            (c-add-stmt-syntax 'statement nil t containing-sexp paren-state))
                   1162:
                   1163:           ;; CASE 5M: we are at a topmost continuation line
                   1164:           (t
                   1165:            (c-beginning-of-statement-1 (c-safe-position (point) paren-state))
                   1166:            (when (c-major-mode-is 'objc-mode)
                   1167:              (setq placeholder (point))
                   1168:              (while (and (c-forward-objc-directive)
                   1169:                          (< (point) indent-point))
                   1170:                (c-forward-syntactic-ws)
                   1171:                (setq placeholder (point)))
                   1172:              (goto-char placeholder))
                   1173:            (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
                   1174:           ))
                   1175:
                   1176:         ;; (CASE 6 has been removed.)
                   1177:
                   1178:         ;; CASE 19: line is an expression, not a statement, and is directly
                   1179:         ;; contained by a template delimiter.  Most likely, we are in a
                   1180:         ;; template arglist within a statement.  This case is based on CASE
                   1181:         ;; 7.  At some point in the future, we may wish to create more
                   1182:         ;; syntactic symbols such as `template-intro',
                   1183:         ;; `template-cont-nonempty', etc., and distinguish between them as we
                   1184:         ;; do for `arglist-intro' etc. (2009-12-07).
                   1185:         ((and c-recognize-<>-arglists
                   1186:               (setq containing-< (c-up-list-backward indent-point containing-sexp))
                   1187:               (eq (char-after containing-<) ?\<))
                   1188:          (setq placeholder (c-point 'boi containing-<))
                   1189:          (goto-char containing-sexp)   ; Most nested Lbrace/Lparen (but not
                   1190:                                        ; '<') before indent-point.
                   1191:          (if (>= (point) placeholder)
                   1192:              (progn
                   1193:                (forward-char)
                   1194:                (skip-chars-forward " \t"))
                   1195:            (goto-char placeholder))
                   1196:          (c-add-stmt-syntax 'template-args-cont (list containing-<) t
                   1197:                             (c-most-enclosing-brace c-state-cache (point))
                   1198:                             paren-state))
                   1199:
                   1200:
                   1201:         ;; CASE 7: line is an expression, not a statement.  Most
                   1202:         ;; likely we are either in a function prototype or a function
                   1203:         ;; call argument list, or a template argument list.
                   1204:         ((not (or (and c-special-brace-lists
                   1205:                        (save-excursion
                   1206:                          (goto-char containing-sexp)
                   1207:                          (c-looking-at-special-brace-list)))
                   1208:                   (eq (char-after containing-sexp) ?{)
                   1209:                   (eq (char-after containing-sexp) ?<)))
                   1210:          (cond
                   1211:
                   1212:           ;; CASE 7A: we are looking at the arglist closing paren.
                   1213:           ;; C.f. case 7F.
                   1214:           ((memq char-after-ip '(?\) ?\]))
                   1215:            (goto-char containing-sexp)
                   1216:            (setq placeholder (c-point 'boi))
                   1217:            (if (and (c-safe (backward-up-list 1) t)
                   1218:                     (>= (point) placeholder))
                   1219:                (progn
                   1220:                  (forward-char)
                   1221:                  (skip-chars-forward " \t"))
                   1222:              (goto-char placeholder))
                   1223:            (c-add-stmt-syntax 'arglist-close (list containing-sexp) t
                   1224:                               (c-most-enclosing-brace paren-state (point))
                   1225:                               paren-state))
                   1226:
                   1227:           ;; CASE 7B: Looking at the opening brace of an
                   1228:           ;; in-expression block or brace list.  C.f. cases 4, 16A
                   1229:           ;; and 17E.
                   1230:           ((and (eq char-after-ip ?{)
                   1231:                 (progn
                   1232:                   (setq placeholder (c-inside-bracelist-p (point)
                   1233:                                                           paren-state))
                   1234:                   (if placeholder
                   1235:                       (setq tmpsymbol '(brace-list-open . inexpr-class))
                   1236:                     (setq tmpsymbol '(block-open . inexpr-statement)
                   1237:                           placeholder
                   1238:                           (cdr-safe (c-looking-at-inexpr-block
                   1239:                                      (c-safe-position containing-sexp
                   1240:                                                       paren-state)
                   1241:                                      containing-sexp)))
                   1242:                     ;; placeholder is nil if it's a block directly in
                   1243:                     ;; a function arglist.  That makes us skip out of
                   1244:                     ;; this case.
                   1245:                     )))
                   1246:            (goto-char placeholder)
                   1247:            (back-to-indentation)
                   1248:            (c-add-stmt-syntax (car tmpsymbol) nil t
                   1249:                               (c-most-enclosing-brace paren-state (point))
                   1250:                               paren-state)
                   1251:            (if (/= (point) placeholder)
                   1252:                (c-add-syntax (cdr tmpsymbol))))
                   1253:
                   1254:           ;; CASE 7C: we are looking at the first argument in an empty
                   1255:           ;; argument list. Use arglist-close if we're actually
                   1256:           ;; looking at a close paren or bracket.
                   1257:           ((memq char-before-ip '(?\( ?\[))
                   1258:            (goto-char containing-sexp)
                   1259:            (setq placeholder (c-point 'boi))
                   1260:            (if (and (c-safe (backward-up-list 1) t)
                   1261:                     (>= (point) placeholder))
                   1262:                (progn
                   1263:                  (forward-char)
                   1264:                  (skip-chars-forward " \t"))
                   1265:              (goto-char placeholder))
                   1266:            (c-add-stmt-syntax 'arglist-intro (list containing-sexp) t
                   1267:                               (c-most-enclosing-brace paren-state (point))
                   1268:                               paren-state))
                   1269:
                   1270:           ;; CASE 7D: we are inside a conditional test clause. treat
                   1271:           ;; these things as statements
                   1272:           ((progn
                   1273:              (goto-char containing-sexp)
                   1274:              (and (c-safe (c-forward-sexp -1) t)
                   1275:                   (looking-at "\\<for\\>[^_]")))
                   1276:            (goto-char (1+ containing-sexp))
                   1277:            (c-forward-syntactic-ws indent-point)
                   1278:            (if (eq char-before-ip ?\;)
                   1279:                (c-add-syntax 'statement (point))
                   1280:              (c-add-syntax 'statement-cont (point))
                   1281:              ))
                   1282:
                   1283:           ;; CASE 7E: maybe a continued ObjC method call. This is the
                   1284:           ;; case when we are inside a [] bracketed exp, and what
                   1285:           ;; precede the opening bracket is not an identifier.
                   1286:           ((and c-opt-method-key
                   1287:                 (eq (char-after containing-sexp) ?\[)
                   1288:                 (progn
                   1289:                   (goto-char (1- containing-sexp))
                   1290:                   (c-backward-syntactic-ws (c-point 'bod))
                   1291:                   (if (not (looking-at c-symbol-key))
                   1292:                       (c-add-syntax 'objc-method-call-cont containing-sexp))
                   1293:                   )))
                   1294:
                   1295:           ;; CASE 7F: we are looking at an arglist continuation line,
                   1296:           ;; but the preceding argument is on the same line as the
                   1297:           ;; opening paren.  This case includes multi-line
                   1298:           ;; mathematical paren groupings, but we could be on a
                   1299:           ;; for-list continuation line.  C.f. case 7A.
                   1300:           ((progn
                   1301:              (goto-char (1+ containing-sexp))
                   1302:              (< (save-excursion
                   1303:                   (c-forward-syntactic-ws)
                   1304:                   (point))
                   1305:                 (c-point 'bonl)))
                   1306:            (goto-char containing-sexp) ; paren opening the arglist
                   1307:            (setq placeholder (c-point 'boi))
                   1308:            (if (and (c-safe (backward-up-list 1) t)
                   1309:                     (>= (point) placeholder))
                   1310:                (progn
                   1311:                  (forward-char)
                   1312:                  (skip-chars-forward " \t"))
                   1313:              (goto-char placeholder))
                   1314:            (c-add-stmt-syntax 'arglist-cont-nonempty (list containing-sexp) t
                   1315:                               (c-most-enclosing-brace c-state-cache (point))
                   1316:                               paren-state))
                   1317:
                   1318:           ;; CASE 7G: we are looking at just a normal arglist
                   1319:           ;; continuation line
                   1320:           (t (c-forward-syntactic-ws indent-point)
                   1321:              (c-add-syntax 'arglist-cont (c-point 'boi)))
                   1322:           ))
                   1323:
                   1324:         ;; CASE 8: func-local multi-inheritance line
                   1325:         ((and (c-major-mode-is 'c++-mode)
                   1326:               (save-excursion
                   1327:                 (goto-char indent-point)
                   1328:                 (skip-chars-forward " \t")
                   1329:                 (looking-at c-opt-postfix-decl-spec-key)))
                   1330:          (goto-char indent-point)
                   1331:          (skip-chars-forward " \t")
                   1332:          (cond
                   1333:
                   1334:           ;; CASE 8A: non-hanging colon on an inher intro
                   1335:           ((eq char-after-ip ?:)
                   1336:            (c-backward-syntactic-ws lim)
                   1337:            (c-add-syntax 'inher-intro (c-point 'boi)))
                   1338:
                   1339:           ;; CASE 8B: hanging colon on an inher intro
                   1340:           ((eq char-before-ip ?:)
                   1341:            (c-add-syntax 'inher-intro (c-point 'boi)))
                   1342:
                   1343:           ;; CASE 8C: a continued inheritance line
                   1344:           (t
                   1345:            (c-beginning-of-inheritance-list lim)
                   1346:            (c-add-syntax 'inher-cont (point))
                   1347:            )))
                   1348:
                   1349:         ;; CASE 9: we are inside a brace-list
                   1350:         ((and (not (c-major-mode-is 'awk-mode))  ; Maybe this isn't needed (ACM, 2002/3/29)
                   1351:                (setq special-brace-list
                   1352:                      (or (and c-special-brace-lists ;;;; ALWAYS NIL FOR AWK!!
                   1353:                               (save-excursion
                   1354:                                 (goto-char containing-sexp)
                   1355:                                 (c-looking-at-special-brace-list)))
                   1356:                          (c-inside-bracelist-p containing-sexp paren-state))))
                   1357:          (cond
                   1358:
                   1359:           ;; CASE 9A: In the middle of a special brace list opener.
                   1360:           ((and (consp special-brace-list)
                   1361:                 (save-excursion
                   1362:                   (goto-char containing-sexp)
                   1363:                   (eq (char-after) ?\())
                   1364:                 (eq char-after-ip (car (cdr special-brace-list))))
                   1365:            (goto-char (car (car special-brace-list)))
                   1366:            (skip-chars-backward " \t")
                   1367:            (if (and (bolp)
                   1368:                     (assoc 'statement-cont
                   1369:                            (setq placeholder (c-guess-basic-syntax))))
                   1370:                (setq c-syntactic-context placeholder)
                   1371:              (c-beginning-of-statement-1
                   1372:               (c-safe-position (1- containing-sexp) paren-state))
                   1373:              (c-forward-token-2 0)
                   1374:              (while (looking-at c-specifier-key)
                   1375:                (goto-char (match-end 1))
                   1376:                (c-forward-syntactic-ws))
                   1377:              (c-add-syntax 'brace-list-open (c-point 'boi))))
                   1378:
                   1379:           ;; CASE 9B: brace-list-close brace
                   1380:           ((if (consp special-brace-list)
                   1381:                ;; Check special brace list closer.
                   1382:                (progn
                   1383:                  (goto-char (car (car special-brace-list)))
                   1384:                  (save-excursion
                   1385:                    (goto-char indent-point)
                   1386:                    (back-to-indentation)
                   1387:                    (or
                   1388:                     ;; We were between the special close char and the `)'.
                   1389:                     (and (eq (char-after) ?\))
                   1390:                          (eq (1+ (point)) (cdr (car special-brace-list))))
                   1391:                     ;; We were before the special close char.
                   1392:                     (and (eq (char-after) (cdr (cdr special-brace-list)))
                   1393:                          (zerop (c-forward-token-2))
                   1394:                          (eq (1+ (point)) (cdr (car special-brace-list)))))))
                   1395:              ;; Normal brace list check.
                   1396:              (and (eq char-after-ip ?})
                   1397:                   (c-safe (goto-char (c-up-list-backward (point))) t)
                   1398:                   (= (point) containing-sexp)))
                   1399:            (if (eq (point) (c-point 'boi))
                   1400:                (c-add-syntax 'brace-list-close (point))
                   1401:              (setq lim (c-most-enclosing-brace c-state-cache (point)))
                   1402:              (c-beginning-of-statement-1 lim)
                   1403:              (c-add-stmt-syntax 'brace-list-close nil t lim paren-state)))
                   1404:
                   1405:           (t
                   1406:            ;; Prepare for the rest of the cases below by going to the
                   1407:            ;; token following the opening brace
                   1408:            (if (consp special-brace-list)
                   1409:                (progn
                   1410:                  (goto-char (car (car special-brace-list)))
                   1411:                  (c-forward-token-2 1 nil indent-point))
                   1412:              (goto-char containing-sexp))
                   1413:            (forward-char)
                   1414:            (let ((start (point)))
                   1415:              (c-forward-syntactic-ws indent-point)
                   1416:              (goto-char (max start (c-point 'bol))))
                   1417:            (c-skip-ws-forward indent-point)
                   1418:            (cond
                   1419:
                   1420:             ;; CASE 9C: we're looking at the first line in a brace-list
                   1421:             ((= (point) indent-point)
                   1422:              (if (consp special-brace-list)
                   1423:                  (goto-char (car (car special-brace-list)))
                   1424:                (goto-char containing-sexp))
                   1425:              (if (eq (point) (c-point 'boi))
                   1426:                  (c-add-syntax 'brace-list-intro (point))
                   1427:                (setq lim (c-most-enclosing-brace c-state-cache (point)))
                   1428:                (c-beginning-of-statement-1 lim)
                   1429:                (c-add-stmt-syntax 'brace-list-intro nil t lim paren-state)))
                   1430:
                   1431:             ;; CASE 9D: this is just a later brace-list-entry or
                   1432:             ;; brace-entry-open
                   1433:             (t (if (or (eq char-after-ip ?{)
                   1434:                        (and c-special-brace-lists
                   1435:                             (save-excursion
                   1436:                               (goto-char indent-point)
                   1437:                               (c-forward-syntactic-ws (c-point 'eol))
                   1438:                               (c-looking-at-special-brace-list (point)))))
                   1439:                    (c-add-syntax 'brace-entry-open (point))
                   1440:                  (c-add-syntax 'brace-list-entry (point))
                   1441:                  ))
                   1442:             ))))
                   1443:
                   1444:         ;; CASE 10: A continued statement or top level construct.
                   1445:         ((and (not (memq char-before-ip '(?\; ?:)))
                   1446:               (not (c-at-vsemi-p before-ws-ip))
                   1447:               (or (not (eq char-before-ip ?}))
                   1448:                   (c-looking-at-inexpr-block-backward c-state-cache))
                   1449:               (> (point)
                   1450:                  (save-excursion
                   1451:                    (c-beginning-of-statement-1 containing-sexp)
                   1452:                    (setq placeholder (point))))
                   1453:               (/= placeholder containing-sexp))
                   1454:          ;; This is shared with case 18.
                   1455:          (c-guess-continued-construct indent-point
                   1456:                                       char-after-ip
                   1457:                                       placeholder
                   1458:                                       containing-sexp
                   1459:                                       paren-state))
                   1460:
                   1461:         ;; CASE 16: block close brace, possibly closing the defun or
                   1462:         ;; the class
                   1463:         ((eq char-after-ip ?})
                   1464:          ;; From here on we have the next containing sexp in lim.
                   1465:          (setq lim (c-most-enclosing-brace paren-state))
                   1466:          (goto-char containing-sexp)
                   1467:            (cond
                   1468:
                   1469:             ;; CASE 16E: Closing a statement block?  This catches
                   1470:             ;; cases where it's preceded by a statement keyword,
                   1471:             ;; which works even when used in an "invalid" context,
                   1472:             ;; e.g. a macro argument.
                   1473:             ((c-after-conditional)
                   1474:              (c-backward-to-block-anchor lim)
                   1475:              (c-add-stmt-syntax 'block-close nil t lim paren-state))
                   1476:
                   1477:             ;; CASE 16A: closing a lambda defun or an in-expression
                   1478:             ;; block?  C.f. cases 4, 7B and 17E.
                   1479:             ((setq placeholder (c-looking-at-inexpr-block
                   1480:                                 (c-safe-position containing-sexp paren-state)
                   1481:                                 nil))
                   1482:              (setq tmpsymbol (if (eq (car placeholder) 'inlambda)
                   1483:                                  'inline-close
                   1484:                                'block-close))
                   1485:              (goto-char containing-sexp)
                   1486:              (back-to-indentation)
                   1487:              (if (= containing-sexp (point))
                   1488:                  (c-add-syntax tmpsymbol (point))
                   1489:                (goto-char (cdr placeholder))
                   1490:                (back-to-indentation)
                   1491:                (c-add-stmt-syntax tmpsymbol nil t
                   1492:                                   (c-most-enclosing-brace paren-state (point))
                   1493:                                   paren-state)
                   1494:                (if (/= (point) (cdr placeholder))
                   1495:                    (c-add-syntax (car placeholder)))))
                   1496:
                   1497:             ;; CASE 16B: does this close an inline or a function in
                   1498:             ;; a non-class declaration level block?
                   1499:             ((save-excursion
                   1500:                (and lim
                   1501:                     (progn
                   1502:                       (goto-char lim)
                   1503:                       (c-looking-at-decl-block
                   1504:                        (c-most-enclosing-brace paren-state lim)
                   1505:                        nil))
                   1506:                     (setq placeholder (point))))
                   1507:              (c-backward-to-decl-anchor lim)
                   1508:              (back-to-indentation)
                   1509:              (if (save-excursion
                   1510:                    (goto-char placeholder)
                   1511:                    (looking-at c-other-decl-block-key))
                   1512:                  (c-add-syntax 'defun-close (point))
                   1513:                (c-add-syntax 'inline-close (point))))
                   1514:
                   1515:             ;; CASE 16F: Can be a defun-close of a function declared
                   1516:             ;; in a statement block, e.g. in Pike or when using gcc
                   1517:             ;; extensions, but watch out for macros followed by
                   1518:             ;; blocks.  Let it through to be handled below.
                   1519:             ;; C.f. cases B.3 and 17G.
                   1520:             ((save-excursion
                   1521:                (and (not (c-at-statement-start-p))
                   1522:                     (eq (c-beginning-of-statement-1 lim nil nil t) 'same)
                   1523:                     (setq placeholder (point))
                   1524:                     (let ((c-recognize-typeless-decls nil))
                   1525:                       ;; Turn off recognition of constructs that
                   1526:                       ;; lacks a type in this case, since that's more
                   1527:                       ;; likely to be a macro followed by a block.
                   1528:                       (c-forward-decl-or-cast-1 (c-point 'bosws) nil nil))))
                   1529:              (back-to-indentation)
                   1530:              (if (/= (point) containing-sexp)
                   1531:                  (goto-char placeholder))
                   1532:              (c-add-stmt-syntax 'defun-close nil t lim paren-state))
                   1533:
                   1534:             ;; CASE 16C: If there is an enclosing brace then this is
                   1535:             ;; a block close since defun closes inside declaration
                   1536:             ;; level blocks have been handled above.
                   1537:             (lim
                   1538:              ;; If the block is preceded by a case/switch label on
                   1539:              ;; the same line, we anchor at the first preceding label
                   1540:              ;; at boi.  The default handling in c-add-stmt-syntax
                   1541:              ;; really fixes it better, but we do like this to keep
                   1542:              ;; the indentation compatible with version 5.28 and
                   1543:              ;; earlier.  C.f. case 17H.
                   1544:              (while (and (/= (setq placeholder (point)) (c-point 'boi))
                   1545:                          (eq (c-beginning-of-statement-1 lim) 'label)))
                   1546:              (goto-char placeholder)
                   1547:              (if (looking-at c-label-kwds-regexp)
                   1548:                  (c-add-syntax 'block-close (point))
                   1549:                (goto-char containing-sexp)
                   1550:                ;; c-backward-to-block-anchor not necessary here; those
                   1551:                ;; situations are handled in case 16E above.
                   1552:                (c-add-stmt-syntax 'block-close nil t lim paren-state)))
                   1553:
                   1554:             ;; CASE 16D: Only top level defun close left.
                   1555:             (t
                   1556:              (goto-char containing-sexp)
                   1557:              (c-backward-to-decl-anchor lim)
                   1558:              (c-add-stmt-syntax 'defun-close nil nil
                   1559:                                 (c-most-enclosing-brace paren-state)
                   1560:                                 paren-state))
                   1561:             ))
                   1562:
                   1563:         ;; CASE 17: Statement or defun catchall.
                   1564:         (t
                   1565:          (goto-char indent-point)
                   1566:          ;; Back up statements until we find one that starts at boi.
                   1567:          (while (let* ((prev-point (point))
                   1568:                        (last-step-type (c-beginning-of-statement-1
                   1569:                                         containing-sexp)))
                   1570:                   (if (= (point) prev-point)
                   1571:                       (progn
                   1572:                         (setq step-type (or step-type last-step-type))
                   1573:                         nil)
                   1574:                     (setq step-type last-step-type)
                   1575:                     (/= (point) (c-point 'boi)))))
                   1576:          (cond
                   1577:
                   1578:           ;; CASE 17B: continued statement
                   1579:           ((and (eq step-type 'same)
                   1580:                 (/= (point) indent-point))
                   1581:            (c-add-stmt-syntax 'statement-cont nil nil
                   1582:                               containing-sexp paren-state))
                   1583:
                   1584:           ;; CASE 17A: After a case/default label?
                   1585:           ((progn
                   1586:              (while (and (eq step-type 'label)
                   1587:                          (not (looking-at c-label-kwds-regexp)))
                   1588:                (setq step-type
                   1589:                      (c-beginning-of-statement-1 containing-sexp)))
                   1590:              (eq step-type 'label))
                   1591:            (c-add-stmt-syntax (if (eq char-after-ip ?{)
                   1592:                                   'statement-case-open
                   1593:                                 'statement-case-intro)
                   1594:                               nil t containing-sexp paren-state))
                   1595:
                   1596:           ;; CASE 17D: any old statement
                   1597:           ((progn
                   1598:              (while (eq step-type 'label)
                   1599:                (setq step-type
                   1600:                      (c-beginning-of-statement-1 containing-sexp)))
                   1601:              (eq step-type 'previous))
                   1602:            (c-add-stmt-syntax 'statement nil t
                   1603:                               containing-sexp paren-state)
                   1604:            (if (eq char-after-ip ?{)
                   1605:                (c-add-syntax 'block-open)))
                   1606:
                   1607:           ;; CASE 17I: Inside a substatement block.
                   1608:           ((progn
                   1609:              ;; The following tests are all based on containing-sexp.
                   1610:              (goto-char containing-sexp)
                   1611:              ;; From here on we have the next containing sexp in lim.
                   1612:              (setq lim (c-most-enclosing-brace paren-state containing-sexp))
                   1613:              (c-after-conditional))
                   1614:            (c-backward-to-block-anchor lim)
                   1615:            (c-add-stmt-syntax 'statement-block-intro nil t
                   1616:                               lim paren-state)
                   1617:            (if (eq char-after-ip ?{)
                   1618:                (c-add-syntax 'block-open)))
                   1619:
                   1620:           ;; CASE 17E: first statement in an in-expression block.
                   1621:           ;; C.f. cases 4, 7B and 16A.
                   1622:           ((setq placeholder (c-looking-at-inexpr-block
                   1623:                               (c-safe-position containing-sexp paren-state)
                   1624:                               nil))
                   1625:            (setq tmpsymbol (if (eq (car placeholder) 'inlambda)
                   1626:                                'defun-block-intro
                   1627:                              'statement-block-intro))
                   1628:            (back-to-indentation)
                   1629:            (if (= containing-sexp (point))
                   1630:                (c-add-syntax tmpsymbol (point))
                   1631:              (goto-char (cdr placeholder))
                   1632:              (back-to-indentation)
                   1633:              (c-add-stmt-syntax tmpsymbol nil t
                   1634:                                 (c-most-enclosing-brace c-state-cache (point))
                   1635:                                 paren-state)
                   1636:              (if (/= (point) (cdr placeholder))
                   1637:                  (c-add-syntax (car placeholder))))
                   1638:            (if (eq char-after-ip ?{)
                   1639:                (c-add-syntax 'block-open)))
                   1640:
                   1641:           ;; CASE 17F: first statement in an inline, or first
                   1642:           ;; statement in a top-level defun. we can tell this is it
                   1643:           ;; if there are no enclosing braces that haven't been
                   1644:           ;; narrowed out by a class (i.e. don't use bod here).
                   1645:           ((save-excursion
                   1646:              (or (not (setq placeholder (c-most-enclosing-brace
                   1647:                                          paren-state)))
                   1648:                  (and (progn
                   1649:                         (goto-char placeholder)
                   1650:                         (eq (char-after) ?{))
                   1651:                       (c-looking-at-decl-block (c-most-enclosing-brace
                   1652:                                                 paren-state (point))
                   1653:                                                nil))))
                   1654:            (c-backward-to-decl-anchor lim)
                   1655:            (back-to-indentation)
                   1656:            (c-add-syntax 'defun-block-intro (point)))
                   1657:
                   1658:           ;; CASE 17G: First statement in a function declared inside
                   1659:           ;; a normal block.  This can occur in Pike and with
                   1660:           ;; e.g. the gcc extensions, but watch out for macros
                   1661:           ;; followed by blocks.  C.f. cases B.3 and 16F.
                   1662:           ((save-excursion
                   1663:              (and (not (c-at-statement-start-p))
                   1664:                   (eq (c-beginning-of-statement-1 lim nil nil t) 'same)
                   1665:                   (setq placeholder (point))
                   1666:                   (let ((c-recognize-typeless-decls nil))
                   1667:                     ;; Turn off recognition of constructs that lacks
                   1668:                     ;; a type in this case, since that's more likely
                   1669:                     ;; to be a macro followed by a block.
                   1670:                     (c-forward-decl-or-cast-1 (c-point 'bosws) nil nil))))
                   1671:            (back-to-indentation)
                   1672:            (if (/= (point) containing-sexp)
                   1673:                (goto-char placeholder))
                   1674:            (c-add-stmt-syntax 'defun-block-intro nil t
                   1675:                               lim paren-state))
                   1676:
                   1677:           ;; CASE 17H: First statement in a block.
                   1678:           (t
                   1679:            ;; If the block is preceded by a case/switch label on the
                   1680:            ;; same line, we anchor at the first preceding label at
                   1681:            ;; boi.  The default handling in c-add-stmt-syntax is
                   1682:            ;; really fixes it better, but we do like this to keep the
                   1683:            ;; indentation compatible with version 5.28 and earlier.
                   1684:            ;; C.f. case 16C.
                   1685:            (while (and (/= (setq placeholder (point)) (c-point 'boi))
                   1686:                        (eq (c-beginning-of-statement-1 lim) 'label)))
                   1687:            (goto-char placeholder)
                   1688:            (if (looking-at c-label-kwds-regexp)
                   1689:                (c-add-syntax 'statement-block-intro (point))
                   1690:              (goto-char containing-sexp)
                   1691:              ;; c-backward-to-block-anchor not necessary here; those
                   1692:              ;; situations are handled in case 17I above.
                   1693:              (c-add-stmt-syntax 'statement-block-intro nil t
                   1694:                                 lim paren-state))
                   1695:            (if (eq char-after-ip ?{)
                   1696:                (c-add-syntax 'block-open)))
                   1697:           ))
                   1698:         )
                   1699:
                   1700:        ;; now we need to look at any modifiers
                   1701:        (goto-char indent-point)
                   1702:        (skip-chars-forward " \t")
                   1703:
                   1704:        ;; are we looking at a comment only line?
                   1705:        (when (and (looking-at c-comment-start-regexp)
                   1706:                   (/= (c-forward-token-2 0 nil (c-point 'eol)) 0))
                   1707:          (c-append-syntax 'comment-intro))
                   1708:
                   1709:        ;; we might want to give additional offset to friends (in C++).
                   1710:        (when (and c-opt-friend-key
                   1711:                   (looking-at c-opt-friend-key))
                   1712:          (c-append-syntax 'friend))
                   1713:
                   1714:        ;; Set syntactic-relpos.
                   1715:        (let ((p c-syntactic-context))
                   1716:          (while (and p
                   1717:                      (if (integerp (c-langelem-pos (car p)))
                   1718:                          (progn
                   1719:                            (setq syntactic-relpos (c-langelem-pos (car p)))
                   1720:                            nil)
                   1721:                        t))
                   1722:            (setq p (cdr p))))
                   1723:
                   1724:        ;; Start of or a continuation of a preprocessor directive?
                   1725:        (if (and macro-start
                   1726:                 (eq macro-start (c-point 'boi))
                   1727:                 (not (and (c-major-mode-is 'pike-mode)
                   1728:                           (eq (char-after (1+ macro-start)) ?\"))))
                   1729:            (c-append-syntax 'cpp-macro)
                   1730:          (when (and c-syntactic-indentation-in-macros macro-start)
                   1731:            (if in-macro-expr
                   1732:                (when (or
                   1733:                       (< syntactic-relpos macro-start)
                   1734:                       (not (or
                   1735:                             (assq 'arglist-intro c-syntactic-context)
                   1736:                             (assq 'arglist-cont c-syntactic-context)
                   1737:                             (assq 'arglist-cont-nonempty c-syntactic-context)
                   1738:                             (assq 'arglist-close c-syntactic-context))))
                   1739:                  ;; If inside a cpp expression, i.e. anywhere in a
                   1740:                  ;; cpp directive except a #define body, we only let
                   1741:                  ;; through the syntactic analysis that is internal
                   1742:                  ;; in the expression.  That means the arglist
                   1743:                  ;; elements, if they are anchored inside the cpp
                   1744:                  ;; expression.
                   1745:                  (setq c-syntactic-context nil)
                   1746:                  (c-add-syntax 'cpp-macro-cont macro-start))
                   1747:              (when (and (eq macro-start syntactic-relpos)
                   1748:                         (not (assq 'cpp-define-intro c-syntactic-context))
                   1749:                         (save-excursion
                   1750:                           (goto-char macro-start)
                   1751:                           (or (not (c-forward-to-cpp-define-body))
                   1752:                               (<= (point) (c-point 'boi indent-point)))))
                   1753:                ;; Inside a #define body and the syntactic analysis is
                   1754:                ;; anchored on the start of the #define.  In this case
                   1755:                ;; we add cpp-define-intro to get the extra
                   1756:                ;; indentation of the #define body.
                   1757:                (c-add-syntax 'cpp-define-intro)))))
                   1758:
                   1759:        ;; return the syntax
                   1760:        c-syntactic-context)))
                   1761:
                   1762: ;;;; End of `asir-c-guess-basic-syntax'
                   1763:
                   1764: (provide 'asir-mode)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>