Skip to content.

Sections
Personal tools
You are here: Home » コミュニティ » masarl memorial » homepage3.nifty.com » masarl » article » js-oop » javascript-mode.el

javascript-mode.el

Document Actions

;=================================================================== ; javascript-mode.el ;=================================================================== ;

(define-derived-mode javascript-mode java-mode "JavaScript" "JavaScript mode" (progn (define-key javascript-mode-map "\C-cc" 'javascript-class) (define-key javascript-mode-map "\C-ci" 'javascript-instance-method) (define-key javascript-mode-map "\C-cs" 'javascript-class-method) (font-lock-mode t)))

(add-hook 'font-lock-mode-hook (function (lambda () (if (eq major-mode 'javascript-mode) (setq font-lock-keywords java-font-lock-keywords)))))

(setq auto-mode-alist (append '( ("\\.js$" . javascript-mode)) auto-mode-alist))

;------------------------------------------------------------------- ; javascript-comment-header ;------------------------------------------------------------------- ; (defun javascript-comment-header (horizontal-line-str) "見出しを挿入します.

horizontal-line-str - 行を区切る文字列" (let ((head-line-str comment-start)) (if (not (stringp head-line-str)) (setq head-line-str "")) (insert head-line-str horizontal-line-str "\n") (insert head-line-str " ") (save-excursion (insert "\n" head-line-str horizontal-line-str "\n" head-line-str "\n"))))

;------------------------------------------------------------------- ; javascript-comment-class ;------------------------------------------------------------------- ; (defun javascript-comment-class () "クラス用の見出しを挿入します." (javascript-comment-header "==================================================================="))

;------------------------------------------------------------------- ; javascript-comment-function ;------------------------------------------------------------------- ; (defun javascript-comment-function () "関数用の見出しを挿入します." (javascript-comment-header "-------------------------------------------------------------------"))

;------------------------------------------------------------------- ; javascript-class ;------------------------------------------------------------------- ; (defun javascript-class (class-name super-class-name) "JavaScriptクラスのスケルトンを挿入します" (interactive "sClass: \nsSuperClass: ") (save-excursion (javascript-comment-class) (insert class-name) (next-line 2) (let ((super-constructor "")) (if (not (string= super-class-name "")) (setq super-constructor (format " this.temp = %s; this.temp(); " super-class-name))) (insert (format "

function %s() {%s

}" class-name super-constructor)) (if (not (string= super-class-name "")) (insert (format " inherit(%s, %s); " class-name super-class-name))))) (next-line 5))

;------------------------------------------------------------------- ; javascript-instance-method ;------------------------------------------------------------------- ; (defun javascript-instance-method (class-name method-name) "JavaScriptインスタンスメソッドのスケルトンを挿入します" (interactive "sClass: \nsInstance Method: ") (save-excursion (javascript-comment-function) (insert (format "%s.%s" class-name method-name)) (next-line 2) (let ((func-name (format "_%s_%s" class-name method-name))) (insert (format "

function %s() {

} %s.prototype.%s = %s; " func-name class-name method-name func-name)))) (next-line 5))

;------------------------------------------------------------------- ; javascript-class-method ;------------------------------------------------------------------- ; (defun javascript-class-method (class-name method-name) "JavaScriptクラスメソッドのスケルトンを挿入します" (interactive "sClass: \nsClass Method: ") (save-excursion (javascript-comment-function) (insert (format "%s.%s" class-name method-name)) (next-line 2) (let ((func-name (format "_%s_%s" class-name method-name))) (insert (format "

function %s() {

} %s.%s = %s; " func-name class-name method-name func-name)))) (next-line 5))