;;; jscript-mode for xyzzy. ;; ;; $Id: jscript-mode.l 214 2006-01-14 12:59:51Z kia $ ;; ;;; 特徴 ;; ;; xyzzyのJScript書き用でっちあげメジャーモードです。 ;; キーワードに色付けができたりします。 ;; インデントなど重要な部分はc-modeに依存しています。 ;; ;; ;;; インストール ;; ;; (1)ファイルの配置 ;; ;; `JScript'ファイルを~xyzzy/etcディレクトリに入れます。 ;; `jscript-mode.l'ファイルを~xyzzy/site-lispディレクトリに入れます。 ;; ;; (2)jscript-mode.lの読みこみ設定 ;; ;; ~/.xyzzyファイルに次の設定します。 ;; ;; (require "jscript-mode") ;; ;; autoloadを使いたいときは代わりに次のように記述してください。 ;; ;; (export '(ed::*jscript-mode-map* ;; ed::*jscript-mode-hook* ;; ed::*jscript-indent-tabs-mode* ;; ed::*jscript-comment-column* ;; ed::*jscript-mode-script-host* ;; ed::jscript-mode ;; ed::jscript-comment-indent ;; ed::jscript-mode-execute ;; ed::jscript-mode-toggle-script-host) "ed") ;; (autoload 'jscript-mode "jscript-mode" t) ;; ;; (3)各種設定 ;; ;; 各変数の意味は大体次のとおり。 ;; ;; *jscript-mode-map* ;; jscript-modeのキーマップ。 ;; *jscript-mode-hook* ;; jscript-modeへ入ったときに実行されるフック。 ;; *jscript-indent-tabs-mode* ;; インデント時にタブを使用するかどうかを決めます。 ;; nilでタブを使いません。tでタブを使います。 ;; *jscript-comment-column* ;; たぶんindent-for-comment(M-;)でコメントを入れるときの位置を決めます。 ;; jscript-comment-indent ;; たぶん複数行にわたるコメントでのインデント具合を調節します。 ;; *jscript-mode-script-host* ;; jscript-mode-execute コマンド実行時のスクリプト実行ホストの種類を保持します。 ;; 値は 'editor::CScript もしくは 'editor::WScript のどちらか。 ;; jscript-mode-toggle-script-host コマンドで変更することもできます。 ;; ;; インデントの量を調節したいときはc-indent-levelを変更してください。 ;; ただしjscript-modeだけでなく他へも影響するので注意。 ;; ;; 拡張子が*.jsのファイルを読みこむ際に自動的にjscript-modeになるようにするには、 ;; *auto-mode-alist*に次のように設定を追加します。 ;; ;; (push '("\\.js$" . jscript-mode) *auto-mode-alist*) ;; ;; ;;; 使い方 ;; ;; jscript-modeコマンドでjscript-modeに移行します。 ;; list-functionコマンドで「関数(だいたい)一覧」が見れます。 ;; indent-for-commentコマンド(M-;)が使えるかも。 ;; jscript-mode-executeコマンド(C-c x)でプログラム実行のダイアログが開きます。 ;; jscript-mode-toggle-script-hostコマンド(C-c c)で、jscript-mode-executeコマンド実行時の ;; スクリプトホストを CScript.exe もしくは WScript.exe に変更することができます。 ; ;; ;;; 注意 ;; ;; このスクリプトを使用したことで発生した損害に対する責任は負いかねます。 ;; このスクリプトを使用する前には、必ずファイルのバックアップを取るなど、 ;; 原状を回復する手段を確保した上で各自の責任において使用してください。 ;; ;; ;;; アドレス ;; ;; kia ;; mailto:meshinsha@yahoo.co.jp ;; http://www.geocities.jp/kiaswebsite/ (provide "jscript-mode") (in-package "editor") (export '(*jscript-mode-map* *jscript-mode-hook* *jscript-indent-tabs-mode* *jscript-comment-column* *jscript-mode-script-host* jscript-mode jscript-comment-indent jscript-mode-execute jscript-mode-toggle-script-host)) (require "c-mode") (unless (boundp 'jscript-comment-indent) (setq jscript-comment-indent 2)) (defvar *jscript-mode-hook* nil) (defvar *jscript-indent-tabs-mode* nil) (defvar *jscript-comment-column* nil) (defvar *jscript-keyword-hash-table* nil) (defvar *jscript-keyword-file* "JScript") (defvar *jscript-mode-abbrev-table* nil) (unless *jscript-mode-abbrev-table* (define-abbrev-table '*jscript-mode-abbrev-table*)) (defvar *jscript-mode-script-host* 'CScript) (defvar *jscript-mode-syntax-table* nil) (unless *jscript-mode-syntax-table* (setq *jscript-mode-syntax-table* (make-syntax-table)) (do ((x #x21 (1+ x))) ((>= x #x7f)) (let ((c (code-char x))) (unless (alphanumericp c) (set-syntax-punctuation *jscript-mode-syntax-table* c)))) (set-syntax-string *jscript-mode-syntax-table* #\") (set-syntax-string *jscript-mode-syntax-table* #\') (set-syntax-escape *jscript-mode-syntax-table* #\\) (set-syntax-symbol *jscript-mode-syntax-table* #\_) (set-syntax-match *jscript-mode-syntax-table* #\( #\)) (set-syntax-match *jscript-mode-syntax-table* #\{ #\}) (set-syntax-match *jscript-mode-syntax-table* #\[ #\]) (set-syntax-start-multi-comment *jscript-mode-syntax-table* "/*") (set-syntax-end-multi-comment *jscript-mode-syntax-table* "*/") (set-syntax-start-c++-comment *jscript-mode-syntax-table* #\/) (set-syntax-end-c++-comment *jscript-mode-syntax-table* #\LFD)) (defvar *jscript-mode-map* nil) (unless *jscript-mode-map* (setq *jscript-mode-map* (make-sparse-keymap)) (define-key *jscript-mode-map* #\{ 'c-electric-insert) (define-key *jscript-mode-map* #\} 'c-electric-close) (define-key *jscript-mode-map* #\C-h 'backward-delete-char-untabify-or-selection) (define-key *jscript-mode-map* #\TAB 'c-indent-line) (define-key *jscript-mode-map* #\C-M-q 'indent-sexp) (define-key *jscript-mode-map* #\RET 'c-newline-and-indent) (define-key *jscript-mode-map* '(#\C-c #\x) 'jscript-mode-execute) (define-key *jscript-mode-map* '(#\C-c #\c) 'jscript-mode-toggle-script-host)) (defun jscript-build-summary-of-functions () (let ((result nil)) (save-excursion (goto-char (point-min)) (while (scan-buffer "^[ \t]*\\(function[ \t]+\\([_A-Za-z0-9]+*\\)[ \t(]\\)\\|\\(\\([_A-Za-z0-9\\.]+\\)[ \t]*=[ \t]*function[ \t]\\)" :regexp t :tail t) (push (list (current-line-number) (or (match-string 2) (match-string 4))) result))) (nreverse result))) (defun jscript-mode-toggle-script-host () (interactive) (if (eq *jscript-mode-script-host* 'CScript) (setq *jscript-mode-script-host* 'WScript) (setq *jscript-mode-script-host* 'CScript)) (message "スクリプトホストを ~A に設定しました" *jscript-mode-script-host*) *jscript-mode-script-host*) ; 現在のバッファがヴィジットしているスクリプトを実行するためにダイアログを開きます。 ; *jscript-mode-script-host* の設定によってダイアログを使い分けます。。 ; バッファがファイルをヴィジットしていなければ何もしません。 (defun jscript-mode-execute () (interactive) (let ((fname (get-buffer-file-name))) (when fname (let* ((fname (map-slash-to-backslash fname)) (host (format nil "^~A" (symbol-name *jscript-mode-script-host*))) (lst (remove-if-not #'(lambda (x) (string-matchp host x)) *minibuffer-execute-history*)) (history (find fname lst :test #'(lambda (x y) (string-match (regexp-quote x) y))))) (if (eq *jscript-mode-script-host* 'WScript) (launch-application-dialog (or history (format nil "wscript \"~A\"" fname))) (pipe-command-dialog (or history (format nil "cscript \"~A\"" fname)))))))) (defun jscript-mode () (interactive) (kill-all-local-variables) (setq mode-name "JScript") (setq buffer-mode 'jscript-mode) (use-keymap *jscript-mode-map*) (use-syntax-table *jscript-mode-syntax-table*) (make-local-variable 'mode-specific-indent-command) (setq mode-specific-indent-command 'c-indent-line) (make-local-variable 'c-comment-indent-variable) (setq c-comment-indent-variable 'jscript-comment-indent) (make-local-variable 'paragraph-start) (setq paragraph-start "^$\\|\f") (make-local-variable 'paragraph-separate) (setq paragraph-separate paragraph-start) (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode *jscript-indent-tabs-mode*) (make-local-variable 'build-summary-function) (setq build-summary-function 'jscript-build-summary-of-functions) (and *jscript-keyword-file* (null *jscript-keyword-hash-table*) (setq *jscript-keyword-hash-table* (load-keyword-file *jscript-keyword-file*))) (when *jscript-keyword-hash-table* (make-local-variable 'keyword-hash-table) (setq keyword-hash-table *jscript-keyword-hash-table*)) (setq comment-start "// ") (setq comment-end "") (setq comment-start-skip "/\\(\\*+\\|/\\)[ \t]*") (setq comment-indent-function 'c-comment-indent) (if *jscript-comment-column* (setq comment-column *jscript-comment-column*)) (setq *local-abbrev-table* *jscript-mode-abbrev-table*) (run-hooks '*jscript-mode-hook*)) ;; jscript-mode.l ends here.