all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp and rewrite url for firefox
@ 2005-04-16 17:28 Hugh Lawson
  0 siblings, 0 replies; only message in thread
From: Hugh Lawson @ 2005-04-16 17:28 UTC (permalink / raw)



What are the functions in elisp that do the below?

change from                   to
-----------             ----------------
ftp.debian.org          ftp://debian.org
www.debian.org          http://www.debian.org

'browse-url-at-point' makes this happen, but the elisp code is too
advanced for me to follow.  I made up my own homemade function to do
this, but I'd like to know if I can just send a string to an already
existing elisp function that would do it for me.  Here's my code:

;; variable url is already set, so it adds "http://" etc
;; as necessary

   (cond ((string-match "http://\\|https://\\|ftp://" url 0) url)
          ((string-match "ftp\\." url 0) (setq url (concat "ftp://"url)) )
          (t(setq url (concat "http://" url))))

To make firefox open an url in a new tab I must send it the full url.

Here is the whole function, which seems to work OK.
 
(defun my-browser (url &optional new-window)
  "Open URL in a new tab in firefox. To use this, set
   browse-url-browser-function to my-browser"
  (interactive (browse-url-interactive-arg "URL: "))
  (cond ((string-match "http://\\|https://\\|ftp://" url 0) url)
	((string-match "ftp\\." url 0) (setq url (concat "ftp://"url)) )
	(t(setq url (concat "http://" url))))
;; 
;; remainder adapted from Xning Lee code
;; see
;; http://lists.gnu.org/archive/html/info-gnus-english/2004-07/msg00193.html
;;
  (when
      (string-match ".*No running window found.*" 
                    (shell-command-to-string 
                     (concat "firefox -remote 'openurl(" url ",new-tab)'")))
    (message "Starting Firefox...")
    (start-process (concat "firefox " url) nil
                   "/bin/sh" "-c" (concat "firefox " url "|| true"))
    (message "Starting Firefox...done")))

;; to make make my-browser default, add the below.
(setq browse-url-browser-function 'my-browser)

-- 
Hugh Lawson
hlawson@triad.rr.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-16 17:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-16 17:28 elisp and rewrite url for firefox Hugh Lawson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.