-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathas-js.el
53 lines (41 loc) · 1.77 KB
/
as-js.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(require-try 'js2-mode)
;;other modes set it in the beginning, take them out
;;this is for mozrepl
(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)
(defun mozrepl-custom-setup ()
(moz-minor-mode 1))
;;patch mozrepl into js2-mode
(add-hook 'js2-mode-hook 'mozrepl-custom-setup)
;;live update html in Firefox from buffer
(require 'moz)
(require 'json)
(defun moz-update (&rest ignored)
"Update the remote mozrepl instance"
(interactive)
(comint-send-string (inferior-moz-process)
(concat "content.document.body.innerHTML="
(json-encode (buffer-string)) ";")))
(defun moz-enable-auto-update ()
"Automatically the remote mozrepl when this buffer changes"
(interactive)
(add-hook 'after-change-functions 'moz-update t t))
(defun moz-disable-auto-update ()
"Disable automatic mozrepl updates"
(interactive)
(remove-hook 'after-change-functions 'moz-update t))
(setq auto-mode-alist (remove-file-name-assocs "\\.js\\'"))
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
;;; Used to work for firefox upto 3.0 Stopped with 3.5
(global-set-key (kbd "C-x p")
(lambda ()
(interactive)
(comint-send-string (inferior-moz-process)
"gBrowser.selectedBrowser.reloadWithFlags(gBrowser.selectedBrowser.webNavigation.LOAD_FLAGS_BYPASS_CACHE);")))
(global-set-key (kbd "C-c r")
(lambda ()
(interactive)
(comint-send-string (inferior-moz-process)
"repl.home = function() { return this.enter(content.wrappedJSObject); };")))
(setq mozrepl-enter-content "repl.enter(content.wrappedJSObject)")
(provide 'as-js)