Permalink
Browse files

Merge pull request #85 from stesla/pretty-function

put pretty function code into a hook function
  • Loading branch information...
2 parents cda0de0 + 05390ef commit 6ae47497712420a33d383b2fd8ddf3056dce9d20 @technomancy committed Sep 5, 2011
Showing with 36 additions and 44 deletions.
  1. +1 −1 starter-kit-defuns.el
  2. +35 −43 starter-kit-js.el
View
2 starter-kit-defuns.el
@@ -218,7 +218,7 @@ Symbols matching the text at point are put first in the completion list."
(paredit-mode 1))
(defun esk-space-for-delimiter? (endp delimiter)
- (not (member major-mode '(ruby-mode espresso-mode js2-mode))))
+ (not (member major-mode '(ruby-mode espresso-mode js-mode js2-mode))))
(eval-after-load 'paredit
'(add-to-list 'paredit-space-for-delimiter-predicates
View
78 starter-kit-js.el
@@ -2,53 +2,45 @@
;;
;; 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))
+(defvar esk-js-mode-hook nil)
+(defun run-esk-js-mode-hook ()
+ (run-hooks 'esk-js-mode-hook))
+
+(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 'run-esk-js-mode-hook)
+ (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
+ nil `(("\\(function *\\)("
+ (0 (progn (compose-region (match-beginning 1)
+ (match-end 1) "ƒ")
+ nil))))))
+(add-hook 'esk-js-mode-hook 'pretty-functions)
- (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)
- (font-lock-add-keywords
- 'espresso-mode `(("\\(function *\\)("
- (0 (progn (compose-region (match-beginning 1)
- (match-end 1) "ƒ")
- nil)))))))
- )
-
- (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)
- (font-lock-add-keywords
- 'js-mode `(("\\(function *\\)("
- (0 (progn (compose-region (match-beginning 1)
- (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 6ae4749

Please sign in to comment.