Emacs の browse-url と firefox 1.5

firefox 1.5 が出た

リリース・ノートによると -remote オプションの代わりに -new-tab (-new-window) オプションが用意された。

firefox -remote (mozilla-xremote-client) はカンマを含む URL では機能しなくなり、廃止される予定です。firefox -new-window /url/ で新しいウィンドウに URL を開き、firefox -new-tab /url/ で新しいタブに URL を開きます。


firefox -remote openURL(http://www.google.co.jp,new-tab)


firefox -new-tab http://www.google.co.jp


Emacs の browse-url

この変更のおかげで、browse-url.el が動かなくなってしまった。当然、Emacs-w3m のように外部ブラウザーの起動に browse-url を使ってるコードも (該当部分が) 動かない。

とりあえず、開発版の browse-url.el への対策は以下の通り。

(eval-after-load "browse-url"
(defun browse-url-firefox (url &optional new-window)
  "Ask the Firefox WWW browser to load URL.
Default to the URL around or before point.  The strings in
variable `browse-url-firefox-arguments' are also passed to

When called interactively, if variable
`browse-url-new-window-flag' is non-nil, load the document in a
new Firefox window, otherwise use a random existing one.  A
non-nil interactive prefix argument reverses the effect of

If `browse-url-firefox-new-window-is-tab' is non-nil, then
whenever a document would otherwise be loaded in a new window, it
is loaded in a new tab in an existing window instead.

When called non-interactively, optional second argument
NEW-WINDOW is used instead of `browse-url-new-window-flag'.

On MS-Windows systems the optional `new-window' parameter is
ignored.  Firefox for Windows does not support the \"-remote\"
command line parameter.  Therefore, the
`browse-url-new-window-flag' and `browse-url-firefox-new-window-is-tab'
are ignored as well.  Firefox on Windows will always open the requested
URL in a new window."
  (interactive (browse-url-interactive-arg "URL: "))
  ;; URL encode any `confusing' characters in the URL.  This needs to
  ;; include at least commas; presumably also close parens.
  (while (string-match "[,)]" url)
    (setq url (replace-match
        (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
  (let* ((process-environment (browse-url-process-environment))
   (apply 'start-process
   (concat "firefox " url) nil
    (if (or (featurep 'dos-w32)
     (string-match "win32" system-configuration))
        (list url)
      (list (if (browse-url-maybe-new-window
         (if browse-url-firefox-new-window-is-tab
     url ))))))
    (set-process-sentinel process
     `(lambda (process change)
        (browse-url-firefox-sentinel process ,url)))))

ちゃんとやろうとしたら、firefox のバージョンを確かめて、1.0.X なら -remote を、1.5+ なら -new-tab を使うように設定すべき。


No comments:

Post a Comment