Re: Emacs 22 and Firefox



If i understand you correctly... given this text in buffer

<a href="http://yahoo.com/some.html";>xyz</a>

and your cursor is on the link text xyz. You want to be able to press
a button and visit the link in your browser?

If so, i think the solution is pretty easy. You just need your elisp
to grab the url part then send it to the browser function.

The key is to use search-forward to the "href" then search-backward to
"href="", get the position, then do similar for the "">", so that you
have the beginning and ending position of the url. Then, just feed
that to your browse function.

for example, here's a similar code i happened to just wrote today.

(defun get-html-h1 ()
"Returns the current buffer's first <h1></h1> tag content.

This function is used to get a set of HTML page's <title> tag
content in sync with the <h1> tag content. This function is used
for dired-do-query-replace-regex.

The search regex should be:
<title>\([^<]+\)</title>

The replace string should be:
<title>\,(get-html-h1)</title>"
(interactive)
(let (pos1 pos2)
; move to the beginning
; search for <h1>, get position
; search for </h1>, get position
; get the text between positions
(save-excursion
(goto-char (point-min))
(search-forward "<h1>" nil t)
(setq pos1 (point))
(search-forward "</h1>" nil t)
(search-backward "</h1>" nil t)
(setq pos2 (point))
)
(buffer-substring-no-properties pos1 pos2)
)
)

Xah
xah@xxxxxxxxxx
http://xahlee.org/

--------------------------------
Pierre Crescenzo wrote:

Hello,

I use Emacs 22 (22.1.1) on Linux (Debian GNU/Linux "testing"). With
Emacs 21, I got from the Web an elisp function which allows me to
launch
the URL links in a Firefox tab (Firefox is Iceweasel on Debian) with
a
keyboard shortcut or the mouse.

With Emacs 22, this is not possible because the "w3" mode is not
present.

I already have, in my ".emacs.el", the following lines:
*******
; call Firefox
(setq-default browse-url-browser-function 'browse-url-firefox)
(setq-default browse-url-firefox-new-window-is-tab t)
(global-set-key (kbd "C-c C-L") 'browse-url)
*******

Now, when my mouse cursor is on a text like "http://my.website.fr/";
and
when I use my chosen keyboard shortcut (Ctrl-c Ctrl-L), I can open a
new
tab in Firefox. This is OK.

The next step would be (I made it with "w3" mode but...) that, when
my
mouse cursor is on a text like "this is a link" which hides (because
this text is in HTML) a link to "http://my.website.fr/";, it also open
a
new tab in Firefox. This is a little more difficult for me.

Do you have any solution?

Thank you.

--
Pierre Crescenzo

.