Skip to content
This repository

put pretty function code into a hook function #85

Merged
merged 4 commits into from almost 3 years ago

2 participants

Samuel Tesla Phil Hagelberg
Samuel Tesla
stesla commented

I don't like the unicode replacements, and it feels cleaner to remove a function from a hook than to remove a font-lock keyword.

There is probably a good deal more duplication removal that could be done here, as the setups are essentially identical.

stesla added some commits
Samuel Tesla stesla put pretty function code into a hook function
I don't like the unicode replacements, and it feels cleaner to remove a function from a hook than to remove a font-lock keyword.

There is probably a good deal more duplication removal that could be done here, as the setups are essentially identical.
f0c1316
Samuel Tesla stesla remove duplication in javascript initialization 28f9464
Samuel Tesla stesla add js-mode to esk-space-for-delimiter? b7bce7b
Samuel Tesla

I finished the extraction of the duplication, and also added a fix for some broken paredit behavior in js-mode.

Phil Hagelberg technomancy merged commit 6ae4749 into from
Phil Hagelberg

Thanks! Could you also submit this as a patch to the v2 branch?

Samuel Tesla

I'd love to submit this to the v2 branch. What is the recommended way of developing/testing against the v2 branch, since it's now designed to be a package?

Phil Hagelberg

You should be able to just use M-x package-install-file to test changes to starter-kit-js provided you have the main starter-kit package installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 2 authors.

Jul 27, 2011
Samuel Tesla stesla put pretty function code into a hook function
I don't like the unicode replacements, and it feels cleaner to remove a function from a hook than to remove a font-lock keyword.

There is probably a good deal more duplication removal that could be done here, as the setups are essentially identical.
f0c1316
Aug 25, 2011
Samuel Tesla stesla remove duplication in javascript initialization 28f9464
Samuel Tesla stesla add js-mode to esk-space-for-delimiter? b7bce7b
Aug 26, 2011
Samuel Tesla stesla make a single hook that gets run from whichever javascript mode is used 05390ef
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 36 additions and 44 deletions. Show diff stats Hide diff stats

  1. +1 1  starter-kit-defuns.el
  2. +35 43 starter-kit-js.el
2  starter-kit-defuns.el
@@ -218,7 +218,7 @@ Symbols matching the text at point are put first in the completion list."
218 218 (paredit-mode 1))
219 219
220 220 (defun esk-space-for-delimiter? (endp delimiter)
221   - (not (member major-mode '(ruby-mode espresso-mode js2-mode))))
  221 + (not (member major-mode '(ruby-mode espresso-mode js-mode js2-mode))))
222 222
223 223 (eval-after-load 'paredit
224 224 '(add-to-list 'paredit-space-for-delimiter-predicates
78 starter-kit-js.el
@@ -2,53 +2,45 @@
2 2 ;;
3 3 ;; Part of the Emacs Starter Kit
4 4
5   -
6 5 ;; NB: js-mode is part of Emacs since version 23.2 (with an alias
7 6 ;; javascript-mode). It is derived and updated from Espresso mode.
8 7
9   -(if (< (string-to-number emacs-version) 23.2)
10   - (progn
11   - (autoload 'espresso-mode "espresso" "Start espresso-mode" t)
12   - (add-to-list 'auto-mode-alist '("\\.js$" . espresso-mode))
13   - (add-to-list 'auto-mode-alist '("\\.json$" . espresso-mode))
14   - (add-hook 'espresso-mode-hook 'moz-minor-mode)
15   - (add-hook 'espresso-mode-hook 'esk-paredit-nonlisp)
16   - (add-hook 'espresso-mode-hook 'run-coding-hook)
17   - (setq espresso-indent-level 2)
18   -
19   - ;; If you prefer js2-mode, use this instead:
20   - ;; (add-to-list 'auto-mode-alist '("\\.js$" . espresso-mode))
  8 +(defvar esk-js-mode-hook nil)
  9 +(defun run-esk-js-mode-hook ()
  10 + (run-hooks 'esk-js-mode-hook))
  11 +
  12 +(defmacro esk-configure-javascript (name)
  13 + (let ((sym (intern name))
  14 + (mode (intern (concat name "-mode")))
  15 + (hook (intern (concat name "-mode-hook")))
  16 + (keymap (intern (concat name "-mode-map")))
  17 + (indent (intern (concat name "-indent-level"))))
  18 + `(progn
  19 + (autoload ',mode ,name ,(concat "Start " name "-mode") t)
  20 + (add-to-list 'auto-mode-alist '("\\.js$" . ,mode))
  21 + (add-to-list 'auto-mode-alist '("\\.json$" . ,mode))
  22 + (add-hook ',hook 'moz-minor-mode)
  23 + (add-hook ',hook 'esk-paredit-nonlisp)
  24 + (add-hook ',hook 'run-coding-hook)
  25 + (add-hook ',hook 'run-esk-js-mode-hook)
  26 + (setq ,indent 2)
  27 +
  28 + (eval-after-load ',sym
  29 + '(progn (define-key ,keymap "{" 'paredit-open-curly)
  30 + (define-key ,keymap "}" 'paredit-close-curly-and-newline)
  31 + (define-key ,keymap (kbd ",") 'self-insert-command))))))
  32 +
  33 +(defun pretty-functions ()
  34 + (font-lock-add-keywords
  35 + nil `(("\\(function *\\)("
  36 + (0 (progn (compose-region (match-beginning 1)
  37 + (match-end 1) "ƒ")
  38 + nil))))))
  39 +(add-hook 'esk-js-mode-hook 'pretty-functions)
21 40
22   - (eval-after-load 'espresso
23   - '(progn (define-key espresso-mode-map "{" 'paredit-open-curly)
24   - (define-key espresso-mode-map "}" 'paredit-close-curly-and-newline)
25   - ;; fixes problem with pretty function font-lock
26   - (define-key espresso-mode-map (kbd ",") 'self-insert-command)
27   - (font-lock-add-keywords
28   - 'espresso-mode `(("\\(function *\\)("
29   - (0 (progn (compose-region (match-beginning 1)
30   - (match-end 1) "ƒ")
31   - nil)))))))
32   - )
33   -
34   - (autoload 'js-mode "js" "Start js-mode" t)
35   - (add-to-list 'auto-mode-alist '("\\.js$" . js-mode))
36   - (add-to-list 'auto-mode-alist '("\\.json$" . js-mode))
37   - (add-hook 'js-mode-hook 'moz-minor-mode)
38   - (add-hook 'js-mode-hook 'esk-paredit-nonlisp)
39   - (add-hook 'js-mode-hook 'run-coding-hook)
40   - (setq js-indent-level 2)
41   -
42   - (eval-after-load 'js
43   - '(progn (define-key js-mode-map "{" 'paredit-open-curly)
44   - (define-key js-mode-map "}" 'paredit-close-curly-and-newline)
45   - ;; fixes problem with pretty function font-lock
46   - (define-key js-mode-map (kbd ",") 'self-insert-command)
47   - (font-lock-add-keywords
48   - 'js-mode `(("\\(function *\\)("
49   - (0 (progn (compose-region (match-beginning 1)
50   - (match-end 1) "ƒ")
51   - nil))))))))
  41 +(if (< (string-to-number emacs-version) 23.2)
  42 + (esk-configure-javascript "espresso")
  43 + (esk-configure-javascript "js"))
52 44
53 45 (provide 'starter-kit-js)
54 46 ;;; starter-kit-js.el ends here

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.