Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove duplication in javascript initialization

  • Loading branch information...
commit 28f94647bf0078e809b7d4d2710edc808fdcd570 1 parent f0c1316
@stesla authored
Showing with 23 additions and 35 deletions.
  1. +23 −35 starter-kit-js.el
View
58 starter-kit-js.el
@@ -2,44 +2,28 @@
;;
;; Part of the Emacs Starter Kit
-
;; NB: js-mode is part of Emacs since version 23.2 (with an alias
;; javascript-mode). It is derived and updated from Espresso mode.
-(if (< (string-to-number emacs-version) 23.2)
- (progn
- (autoload 'espresso-mode "espresso" "Start espresso-mode" t)
- (add-to-list 'auto-mode-alist '("\\.js$" . espresso-mode))
- (add-to-list 'auto-mode-alist '("\\.json$" . espresso-mode))
- (add-hook 'espresso-mode-hook 'moz-minor-mode)
- (add-hook 'espresso-mode-hook 'esk-paredit-nonlisp)
- (add-hook 'espresso-mode-hook 'run-coding-hook)
- (setq espresso-indent-level 2)
-
- ;; If you prefer js2-mode, use this instead:
- ;; (add-to-list 'auto-mode-alist '("\\.js$" . espresso-mode))
-
- (eval-after-load 'espresso
- '(progn (define-key espresso-mode-map "{" 'paredit-open-curly)
- (define-key espresso-mode-map "}" 'paredit-close-curly-and-newline)
- ;; fixes problem with pretty function font-lock
- (define-key espresso-mode-map (kbd ",") 'self-insert-command)))
- (add-hook 'espresso-mode-hook 'pretty-functions))
-
- (autoload 'js-mode "js" "Start js-mode" t)
- (add-to-list 'auto-mode-alist '("\\.js$" . js-mode))
- (add-to-list 'auto-mode-alist '("\\.json$" . js-mode))
- (add-hook 'js-mode-hook 'moz-minor-mode)
- (add-hook 'js-mode-hook 'esk-paredit-nonlisp)
- (add-hook 'js-mode-hook 'run-coding-hook)
- (setq js-indent-level 2)
-
- (eval-after-load 'js
- '(progn (define-key js-mode-map "{" 'paredit-open-curly)
- (define-key js-mode-map "}" 'paredit-close-curly-and-newline)
- ;; fixes problem with pretty function font-lock
- (define-key js-mode-map (kbd ",") 'self-insert-command)))
- (add-hook 'js-mode-hook 'pretty-functions))
+(defmacro esk-configure-javascript (name)
+ (let ((sym (intern name))
+ (mode (intern (concat name "-mode")))
+ (hook (intern (concat name "-mode-hook")))
+ (keymap (intern (concat name "-mode-map")))
+ (indent (intern (concat name "-indent-level"))))
+ `(progn
+ (autoload ',mode ,name ,(concat "Start " name "-mode") t)
+ (add-to-list 'auto-mode-alist '("\\.js$" . ,mode))
+ (add-to-list 'auto-mode-alist '("\\.json$" . ,mode))
+ (add-hook ',hook 'moz-minor-mode)
+ (add-hook ',hook 'esk-paredit-nonlisp)
+ (add-hook ',hook 'run-coding-hook)
+ (add-hook ',hook 'pretty-functions) (setq ,indent 2)
+
+ (eval-after-load ',sym
+ '(progn (define-key ,keymap "{" 'paredit-open-curly)
+ (define-key ,keymap "}" 'paredit-close-curly-and-newline)
+ (define-key ,keymap (kbd ",") 'self-insert-command))))))
(defun pretty-functions ()
(font-lock-add-keywords
@@ -48,5 +32,9 @@
(match-end 1) "ƒ")
nil))))))
+(if (< (string-to-number emacs-version) 23.2)
+ (esk-configure-javascript "espresso")
+ (esk-configure-javascript "js"))
+
(provide 'starter-kit-js)
;;; starter-kit-js.el ends here
Please sign in to comment.
Something went wrong with that request. Please try again.