[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.15

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

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