Last active
December 16, 2015 19:38
-
-
Save h2oota/5486037 to your computer and use it in GitHub Desktop.
cli-mode.el -- Microsoft C++/CLI mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; cli-mode.el -- Microsoft C++/CLI mode | |
;; | |
;; This mode is derived from C++ mode. | |
;; | |
(require 'cc-mode) | |
(eval-when-compile | |
(require 'cc-langs) | |
(require 'cc-fonts)) | |
(eval-and-compile | |
;; Make our mode known to the language constant system. Use Java | |
;; mode as the fallback for the constants we don't change here. | |
;; This needs to be done also at compile time since the language | |
;; constants are evaluated then. | |
(c-add-language 'cli-mode 'c++-mode)) | |
(c-lang-defconst c-block-stmt-2-kwds | |
cli (append '("for\\(?:[[:space:]\n]+each\\)?") | |
(remove "for" | |
(c-lang-const c-block-stmt-2-kwds c++)))) | |
(c-lang-defconst c-block-decls-with-vars | |
cli (append '("\\(?:\\(?:value\\|ref\\)[[:space:]\n]+\\)?class") | |
(remove "class" | |
(c-lang-const c-block-decls-with-vars c++)))) | |
(defcustom cli-font-lock-extra-types nil | |
"*List of extra types (aside from the type keywords) to recognize in C++/CLI mode. | |
Each list item should be a regexp matching a single identifier.") | |
(defconst cli-font-lock-keywords-1 (c-lang-const c-matchers-1 cli) | |
"Minimal highlighting for C++/CLI mode.") | |
(defconst cli-font-lock-keywords-2 (c-lang-const c-matchers-2 cli) | |
"Fast normal highlighting for C++/CLI mode.") | |
(defconst cli-font-lock-keywords-3 (c-lang-const c-matchers-3 cli) | |
"Accurate normal highlighting for C++/CLI mode.") | |
(defvar cli-font-lock-keywords cli-font-lock-keywords-3 | |
"Default expressions to highlight in C++/CLI mode.") | |
(defvar cli-mode-syntax-table nil | |
"Syntax table used in c++/cli-mode buffers.") | |
(or cli-mode-syntax-table | |
(setq cli-mode-syntax-table | |
(funcall (c-lang-const c-make-mode-syntax-table cli)))) | |
(defvar cli-mode-abbrev-table nil | |
"Abbreviation table used in c++/cli-mode buffers.") | |
(defvar cli-mode-map (let ((map (c-make-inherited-keymap))) | |
;; Add bindings which are only useful for C++/CLI | |
map) | |
"Keymap used in c++/cli-mode buffers.") | |
(easy-menu-define cli-menu cli-mode-map "C++/CLI Mode Commands" | |
;; Can use `c++/cli' as the language for `c-mode-menu' | |
;; since its definition covers any language. In | |
;; this case the language is used to adapt to the | |
;; nonexistence of a cpp pass and thus removing some | |
;; irrelevant menu alternatives. | |
(cons "C++/CLI" (c-lang-const c-mode-menu cli))) | |
(defun cli-mode () | |
"Major mode for editing C++/CLI code. | |
This is a simple example of a separate mode derived from CC Mode to | |
support a language with syntax similar to C/C++/ObjC/Java/IDL/Pike. | |
The hook `c-mode-common-hook' is run with no args at mode | |
initialization, then `c++/cli-mode-hook'. | |
Key bindings: | |
\\{c++/cli-mode-map}" | |
(interactive) | |
(kill-all-local-variables) | |
(c-initialize-cc-mode t) | |
(set-syntax-table cli-mode-syntax-table) | |
(setq major-mode 'cli-mode | |
mode-name "C++/CLI" | |
local-abbrev-table cli-mode-abbrev-table | |
abbrev-mode t) | |
(use-local-map cli-mode-map) | |
;; `c-init-language-vars' is a macro that is expanded at compile | |
;; time to a large `setq' with all the language variables and their | |
;; customized values for our language. | |
(c-init-language-vars cli-mode) | |
;; `c-common-init' initializes most of the components of a CC Mode | |
;; buffer, including setup of the mode menu, font-lock, etc. | |
;; There's also a lower level routine `c-basic-common-init' that | |
;; only makes the necessary initialization to get the syntactic | |
;; analysis and similar things working. | |
(c-common-init 'cli-mode) | |
(easy-menu-add cli-menu) | |
(run-hooks 'c-mode-common-hook) | |
(run-hooks 'cli-mode-hook) | |
(c-update-modeline)) | |
(provide 'cli-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment