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

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

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