bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

browse-url.el extras


From: Denis Howe
Subject: browse-url.el extras
Date: Thu, 15 Sep 2005 00:30:54 +0100

From: Eric Moss <address@hidden>
To: address@hidden
Subject: browse-url.el extras
Date: Wed, 31 Aug 2005 22:27:31 -0500 (CDT)

I wrote some patches (actually just additions) that get it working
with the latest Firefox, and Mozilla (at least 1.2.1).

For reasons I don't understand (I'm not a great emacs hacker), it's
not finding firefox, even though I put the install directory in my
PATH.  It works just fine when I specify the entire path explicitly.

I hope this is of use.

Eric

;;; additional functions to put in browse-url.el to help with mozilla
;;; and firefox.  I'm not sure why I ahve to put entire path in for
;;; firefox, but don't have to for Mozilla 1.2.x and newer.  


;;; Create this function as per /usr/share/emacs/21.2/lisp/net/browse-url.el
;;; so that we open an existing Mozilla window (NOT like with gnome-moz), and
;;; open a new tab inside.
;;; 
;;; Load this file AFTER loading/require-ing browse-url.el!

(defcustom browse-url-new-mozilla-program "mozilla"
  ;; Info about netscape-remote from Karl Berry.
  "The name by which to invoke Mozilla."
  :type 'string
  :group 'browse-url)


(defcustom browse-url-new-mozilla-arguments nil
  "A list of strings to pass to Mozilla as arguments."
  :type '(repeat (string :tag "Argument"))
  :group 'browse-url)


(defcustom browse-url-new-mozilla-startup-arguments 
browse-url-new-mozilla-arguments
  "A list of strings to pass to Mozilla when it starts up.
Defaults to the value of `browse-url-new-mozilla-arguments' at the time
`browse-url' is loaded."
  :type '(repeat (string :tag "Argument"))
  :group 'browse-url)


(defun browse-url-new-mozilla-sentinel (process url)
  "Handle a change to the process communicating with Mozilla."
  (or (eq (process-exit-status process) 0)
      (let* ((process-environment (browse-url-process-environment)))
        ;; Mozilla not running - start it
        (message "Starting Mozilla...")
        (apply 'start-process (concat "mozilla" url) nil
               browse-url-new-mozilla-program
               (append browse-url-new-mozilla-startup-arguments (list url))))))


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

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

When called non-interactively, optional second argument NEW-WINDOW is
used instead of `browse-url-new-window-flag'."
  (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))
         (process (apply 'start-process
                         (concat "mozilla " url) nil
                         "mozilla"
                         (append
                          browse-url-new-mozilla-arguments
                          (if (eq window-system 'w32)
                              (list url)
                            (append
                             (if new-window '("-noraise"))
                             (list "-remote"
                                   (concat "openURL(" url
                                           (if (browse-url-maybe-new-window
                                                new-window)
                                               ",new-window"
                                             ",new-tab")
                                           ")"))))))))
    (set-process-sentinel process
                          `(lambda (process change)
                             (browse-url-new-mozilla-sentinel process ,url)))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Now for Firefox

(defcustom browse-url-firefox-program "mozilla-xremote-client -a firefox"
  "The name by which to invoke Firefox."
  :type 'string
  :group 'browse-url)


(defcustom browse-url-firefox-arguments nil
  "A list of strings to pass to Firefox as arguments."
  :type '(repeat (string :tag "Argument"))
  :group 'browse-url)


(defcustom browse-url-firefox-startup-arguments browse-url-firefox-arguments
  "A list of strings to pass to Firefox when it starts up.
Defaults to the value of `browse-url-firefox-arguments' at the time
`browse-url' is loaded."
  :type '(repeat (string :tag "Argument"))
  :group 'browse-url)


(defun browse-url-firefox-sentinel (process url)
  "Handle a change to the process communicating with Firefox."
  (or (eq (process-exit-status process) 0)
      (let* ((process-environment (browse-url-process-environment)))
        ;; Firefox not running - start it
        (message "Starting Firefox...")
        (apply 'start-process (concat "firefox" url) nil
               browse-url-firefox-program
               (append browse-url-firefox-startup-arguments (list 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 Firefox.

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 `browse-url-new-window-flag'.

When called non-interactively, optional second argument NEW-WINDOW is
used instead of `browse-url-new-window-flag'."
  (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))
         (process (apply 'start-process
                         (concat "firefox " url) nil
                         "firefox"
                         (append
                          browse-url-firefox-arguments
                          (if (eq window-system 'w32)
                              (list url)
                            (append
                             (if new-window '("-noraise"))
                             (list "-remote"
                                   (concat "openURL(" url
                                           (if (browse-url-maybe-new-window
                                                new-window)
                                               ",new-window"
                                             ",new-tab")
                                           ")"))))))))
    (set-process-sentinel process
                          `(lambda (process change)
                             (browse-url-firefox-sentinel process ,url)))))
------- End of forwarded message -------




reply via email to

[Prev in Thread] Current Thread [Next in Thread]