emacsのsquirrel-modeを作ってみた
squirrelを書こうとしているがどうやらemacsのsquirrel-modeはないみたいだったので自作した。
とは言ってもc++-modeの派生モードとして作っただけ。一応キーワードを色づけしたが正直言って微妙なレベル。しかし自動インデントが使えるのはうれしい。
init.elもしくは.emacsに以下の内容を記述。
;; my-sq-mode.elの遅延読み込み (autoload 'squirrel-mode "squirrel-mode" nil t) ;; .nutファイルが読み込まれたときはmy-sq-modeにする (add-to-list 'auto-mode-alist '("\\.nut$" . squirrel-mode))
以下の内容をsquirrel-mode.elとして保存。
;;squirrel-modeに関する設定 (defvar squirrel-font-lock-defaults (list 'squirrel-font-lock-keywords nil nil )) ;;ハイライトするキーワードの定義 (defconst squirrel-font-lock-keywords '( ("\\<\\(local\\)[ \t]+\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-keyword-face) (2 font-lock-variable-name-face)) ("\\<\\(const\\|static\\)[ \t]+\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-keyword-face) (2 font-lock-constant-face)) ("\\<\\(enum\\)[ \t]+\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-keyword-face) (2 font-lock-constant-face)) ("\\<\\(function\\|class\\)\\>" (1 font-lock-keyword-face)) ("\\<function[ \t]+\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-function-name-face)) ("\\<class[ \t]+\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-type-face)) ("\\<\\(constructor\\)\\>" (0 font-lock-function-name-face)) ("\\<\\(parent\\)\\>" (0 font-lock-function-name-face)) ("\\<\\(extends\\|instanceof\\)[ \t]++\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>" (1 font-lock-keyword-face) (2 font-lock-type-face)) ("\\<\\(try\\|catch\\|throw\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(if\\|else\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(for\\|foreach\\|while\\|do\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(break\\|continue\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(switch\\|case\\|default\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(delegate\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(clone\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(delete\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(yield\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(resume\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(return\\)\\>" (0 font-lock-keyword-face)) ("\\<\\(in\\|typeof\\)\\>" (0 font-lock-keyword-face)) ("\"[^\"]*\"" (0 font-lock-string-face)) ("\'[^\']*\'" (0 font-lock-string-face)) ("\\<\\(this\\)\\>"(0 font-lock-constant-face)) ("\\<\\(null\\)\\>"(0 font-lock-constant-face)) ("\\<\\(true\\|false\\)\\>" (0 font-lock-constant-face)) ) "keyword to highlight in squirrel-mode.") (add-hook 'squirrel-mode-hook (function (lambda () (setq tab-width c-basic-offset) (setq indent-tabs-mode t)))) ;;派生モード squirrel-modeを定義 (define-derived-mode squirrel-mode c++-mode "Squirrel" "edit for squirrel." (setq font-lock-defaults squirrel-font-lock-defaults) ) (provide 'squirrel-mode)
実現できなかった、enum A{AA,AB}と書いた時にAAとABに色を付けるにはどうすればいいんだろう。
参考ページ
GNU Emacs Lispリファレンスマニュアル Derived Modes
http://dl.dropbox.com/u/9975638/kuin/emacs/elisp/20121001/kuin-mode.el
kuin-mode.el (Kuin用 Emacs設定ファイル)