Advanced tip on using mozrepl to automatically refresh browser

  |   Source

Here is the setup on Emacswiki.

I find it annoying instead of helpful in real world usage.

The mozrepl trick basically will refresh the current active page in Firefox. It's not smart enough. When developing a web application, I will open many stackoverflow pages to look for technical solution. I don't like my stackoverflow page being refreshed when I'm saving the HTML code for some web application.

So here is my improved solution:

(defun my-moz-refresh-browser-condition (current-file)
  "Should return a boolean javascript expression or nil"
  (let (rlt)
     ((string-match "\\(beeta\\|cb_tutorial\\)" current-file)
      (setq rlt "content.document.location.href.indexOf(':8001')!==-1"))
      (setq rlt nil)))

;; {{ mozrepl auto-refresh browser
(defun moz-reload-browser ()
  (let (js-cond cmd)
    (if (fboundp 'my-moz-refresh-browser-condition)
        (setq js-cond (funcall 'my-moz-refresh-browser-condition (buffer-file-name))))
      (setq cmd (concat "if(" js-cond "){setTimeout(function(){content.document.location.reload(true);}, '500');}")))
      (setq cmd "setTimeout(function(){content.document.location.reload(true);}, '500');")))
    (comint-send-string (inferior-moz-process) cmd)

(defun moz-after-save ()
  (when (memq major-mode '(web-mode html-mode nxml-mode nxhml-mode php-mode))

(add-hook 'after-save-hook
              'append 'local)
;; }}
Comments powered by Disqus