Skip to content

Commit

Permalink
remove duplication in javascript initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
stesla committed Aug 25, 2011
1 parent f0c1316 commit 28f9464
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions starter-kit-js.el
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 28f9464

Please sign in to comment.