;;; $Id$ ;; This is based on cc-mode by Barry A. Warsaw. (require 'cc-mode) (defvar v-mode-hook nil "*Hook called by `v-mode'.") ;; constant regular expressions for looking at various constructs (defconst c-V-conditional-key "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\)\\b[^_]" "Regexp describing a conditional control.") ;; V mode should really be defined this way: ;(define-derived-mode v-mode c++-mode "V" ; "Major mode for editing V, the AVS/Express extension language. ;\\{v-mode-map}" ; ;;; ... code to execute for v-mode should go here ; ;;; anything that's different from C++ mode needs to be initialized ; ) ;; main entry points for the modes ;;;###autoload (defun v-mode () "Major mode for editing V (AVS/Express extension language) code. V is a lot like C++. This is derived from cc-mode Revision: 4.35 The hook variable `v-mode-hook' is run with no args, if that value is bound and has a non-nil value. Also the common hook c-mode-common-hook is run first. Key bindings: \\{c++-mode-map}" (interactive) (kill-all-local-variables) (set-syntax-table c++-mode-syntax-table) (setq major-mode 'v-mode mode-name "V" local-abbrev-table c++-mode-abbrev-table) (use-local-map c++-mode-map) (c-common-init) (setq comment-start "// " comment-end "" c-conditional-key c-V-conditional-key c-comment-start-regexp "//\\|/\\*") (run-hooks 'v-mode-hook)) ;; Font lock keywords for V mode (let* ( (vtoken "[a-zA-Z_#][a-zA-Z0-9_#]*") ;; this has two open parens. Don't change unless you fix the ;; refs to it. (builtin-attr (concat "\\(\\+\\(" "notify\\(_inst\\|_val\\|_del\\)?\\|" "nonotify\\|read\\|noread\\|write\\|nowrite\\|" "opt\\|req\\|" "nosave\\|buffered\\|global\\|" "[IO]?Port[0-9]?\\|" "[IO]param\\|" "virtual\\|trace\\|nres\\)\\)" )) ; builtin attribute ;; this has one open paren. (attr (concat "\\(\\+" vtoken "\\)")) ; general attribute ;; this also has one open paren. (type (concat "\\(byte\\|char\\|double\\|float\\|int\\|prim\\|" "ptr\\|short\\|string\\|" ; primitives "group\\|macro\\|" ; groups "method\\|method_upd\\|cmethod\\|cmethod_upd\\|" ; methods "im?link\\|om?link\\|mlink\\|" ; links "f?library\\|NElink\\|" ; libraries "atts\\|sort" ; misc "\\)" )) (prop (concat "\\(NEheight\\|Newidth\\|NE[xy]\\|" "NEportLevels\\|NEiconName\\|NEdisplayMode\\|" "NEeditable\\|NEvisible\\|NEcolor[0-9]\\|" "NEnumColors\\|build_cmd\\|build_dir\\|" "c_hdr_files\\|c_src_files\\|compile_subs\\|" "cxx_hdr_files\\|cxx_src_files\\|hdr_code\\|" "hdr_dirs\\|\\(pre_\\)?init_code\\|lang\\|libdeps\\|" "libfile\\|src_file\\|inst_func\\|" "link_files\\|need_cxx\\|process\\|" "\\(out_\\)\\(src\\|hdr\\)_file\\)" )) ) (setq v-font-lock-keywords (list ;; ;; Fontify filenames in #include <...> preprocessor directives. '("^[$#][ \t]*include[ \t]+\\(.*\\)$" 1 font-lock-string-face) ;; ;; Fontify function macro names. '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face) ;; ;; Fontify misc. V commands (cmds beginning with $) as keywords '("^[ \t]*\\($[-_A-Za-z0-9#]+\\)" 1 font-lock-keyword-face) ;; Fontify type declarations (list (concat "^[ \t]*$declare_type[ \t]\\(" vtoken "\\)") 1 font-lock-variable-name-face) ;; ;; Fontify otherwise as symbol names, and the preprocessor directive names. '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?" (1 font-lock-reference-face) (2 font-lock-variable-name-face nil t)) ;; fontify the names of objects being defined or modified (list (concat type "[ \t]*" attr "*[ \t]*\\(" vtoken "\\)[ \t]*[\n{<]") 3 'font-lock-function-name-face t) (list (concat "\\(" vtoken "\\)" attr "*[ \t]+" "\\(" vtoken "\\)" "\\(<.*>\\)?[ \t]*{[ \t]*$") 3 'font-lock-function-name-face t) ;; ;; Fontify function name definitions (without type on line). (list (concat "^\\(" vtoken "\\)[ \t]*(") 1 'font-lock-function-name-face) ;; ;; fontify all storage classes and type specifiers (list (concat "\\<\\(" type "*\\)\\>") 1 'font-lock-type-face) (list builtin-attr 1 'font-lock-type-face) (list prop 1 'font-lock-reference-face) ;; ;; fontify all builtin tokens ))) ;;; end of v-mode.el