7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Emacsで保存時にFirefoxのタブを探してリロード

7
Posted at

Emacs+Firefox+MozReplでファイルセーブと同時にリロードの改良です。

EmacsでHTMLやCSSファイルなどを編集、保存した際に、Firefoxのドメイン名がlocalhostなタブを探し、切り替えてリロードしてくれます。

以下、適用方法です。

  • FirefoxにMozReplをインストールします。

  • メニューバー→ツール→MozRepl→Activate on startupをチェックしてFirefoxの起動と同時にMozReplを有効にするか、

  • メニューバー→ツール→MozRepl→StartでMozReplを有効にします。

  • moz.el~/.emacs.d/あたりに保存します。

  • 以下のコードをinit.elに貼り付けます。

(require 'moz)

(defun auto-reload-firefox-on-after-save-hook ()
  (add-hook 'after-save-hook
            '(lambda ()
               (interactive)
               (comint-send-string (inferior-moz-process) "
function reload(){
  var i;
  for(i=0;i<gBrowser.browsers.length;++i){
    var host=gBrowser.getBrowserAtIndex(i).currentURI.host;
    if(host=='localhost')break;
  }
  if(i>=gBrowser.browsers.length)return;
  gBrowser.selectedTab=gBrowser.tabContainer.childNodes[i];
  BrowserReload();
}
reload();
"))))

(add-hook 'php-mode-hook 'auto-reload-firefox-on-after-save-hook)
(add-hook 'html-mode-hook 'auto-reload-firefox-on-after-save-hook)
(add-hook 'css-mode-hook 'auto-reload-firefox-on-after-save-hook)

php-modehtml-modecss-modeのときに保存するとオートリロードしてくれますので適宜書き換えてください。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?