Created
April 1, 2011 07:15
-
-
Save tlync/897852 to your computer and use it in GitHub Desktop.
init-firefox.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t) | |
(defvar moz-enable-auto-reload t) | |
(defvar moz-scroll-ratio "60") | |
(defvar moz-scroll-time "60") | |
(defun moz-send-line (str) | |
(interactive) | |
(comint-send-string (inferior-moz-process) | |
(concat moz-repl-name ".pushenv('printPrompt', 'inputMode'); " | |
moz-repl-name ".setenv('inputMode', 'line'); " | |
moz-repl-name ".setenv('printPrompt', false); undefined; ")) | |
(comint-send-string (inferior-moz-process) | |
(concat str "; " moz-repl-name ".popenv('inputMode', 'printPrompt'); undefined;\n"))) | |
(defun moz-scroll-down () | |
(interactive) | |
(moz-send-line (concat "(function(){var t=" moz-scroll-time ",r=" moz-scroll-ratio " ;var i=0,w =document.documentElement,s=gBrowser.selectedBrowser.contentWindow.scrollY,e=s+w.clientHeight/(100/r),v=(e-s)/t,c=s;for(i;i<t;i++){setTimeout(function(){c+=v;content.scrollTo(0,c);},i+1)}})();"))) | |
(defun moz-scroll-up () | |
(interactive) | |
(moz-send-line (concat "(function(){var t=" moz-scroll-time ",r=" moz-scroll-ratio " ;var i=0,w =document.documentElement,s=gBrowser.selectedBrowser.contentWindow.scrollY,e=s+w.clientHeight/(100/r),v=(e-s)/t,c=s;for(i;i<t;i++){setTimeout(function(){c-=v;content.scrollTo(0,c);},i+1)}})();"))) | |
(defun moz-prev-tab () | |
(interactive) | |
(moz-send-line "gBrowser.mTabContainer.advanceSelectedTab(-1, true)")) | |
(defun moz-next-tab () | |
(interactive) | |
(moz-send-line "gBrowser.mTabContainer.advanceSelectedTab(1, true)")) | |
(defun moz-reload () | |
(interactive) | |
(moz-send-line "content.location.reload()")) | |
(defun reload-moz() | |
(interactive) | |
(if (equal moz-enable-auto-reload t) | |
(unless (condition-case nil | |
(run-mozilla) | |
(error nil)) | |
(if (string-match "\.\\(css\\|js\\|php\\|html\\|htm\\|tpl\\|thtml\\|ctp\\|po\\)$" (buffer-file-name)) | |
(moz-send-reload))))) | |
(add-hook 'after-save-hook 'reload-moz) | |
(global-set-key (kbd "c-x ret c-r") 'moz-reload) ;; C-x C-m C-r | |
(global-set-key (kbd "c-x ret <up>") 'moz-scroll-up) ;; C-x C-m C-p | |
(global-set-key (kbd "c-x ret <down>") 'moz-scroll-down) ;; C-x C-m C-n | |
(global-set-key (kbd "c-x ret del") 'moz-prev-tab) ;; C-x C-m C-h | |
(global-set-key (kbd "c-x ret c-l") 'moz-next-tab) ;; C-x C-m C-l | |
(add-hook 'js2-mode-hook | |
'(lambda () (moz-minor-mode 1))) | |
(add-hook 'html-mode-hook | |
'(lambda () (moz-minor-mode 1))) | |
(add-hook 'html-helper-mode-hook | |
'(lambda () (moz-minor-mode 1))) | |
(add-hook 'css-mode-hook | |
'(lambda () (moz-minor-mode 1))) | |
;; C-c C-s: open a MozRepl interaction buffer and switch to it | |
;; C-c C-l: save the current buffer and load it in MozRepl | |
;; C-M-x: send the current function (as recognized by c-mark-function) to MozRepl | |
;; C-c C-c: send the current function to MozRepl and switch to the interaction buffer | |
;; C-c C-r: send the current region to MozRepl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment