* Re: [Reuben Thomas] browse-url.el Opera support
[not found] <mailman.693.1074172442.928.bug-gnu-emacs@gnu.org>
@ 2004-01-15 13:48 ` Simon Josefsson
2004-01-15 14:12 ` Reuben Thomas
[not found] ` <mailman.716.1074194876.928.bug-gnu-emacs@gnu.org>
0 siblings, 2 replies; 21+ messages in thread
From: Simon Josefsson @ 2004-01-15 13:48 UTC (permalink / raw)
Cc: bug-gnu-emacs, Dave Love
Dave Love <d.love@dl.ac.uk> writes:
> [I removed the attachment of XEmacs code.]
>
> From: Reuben Thomas <rrt@sc3d.org>
> Subject: browse-url.el Opera support
> To: fx@gnu.org
> Date: Tue, 13 Jan 2004 14:20:26 +0100 (CET)
> Reply-To: Reuben Thomas <rrt@mupsych.org>
>
> I'm an Opera user and recently switched from XEmacs to FSF Emacs. The
> XEmacs version of browse-url.el (in the mail-lib package) has support for
> Opera; I was wondering if it might be possible to fold that into the FSF
> version?
I recall a discussion about this earlier, when someone proposed a
patch for Opera, and that someone didn't think Emacs should support
non-free browsers like Opera. The XEmacs folks didn't have that
concern, though, so the patch was applied to that version of
browse-url.el.
If you think this decision should be reconsidered, for Emacs, I think
it has to be discussed on emacs-devel@gnu.org.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-15 13:48 ` [Reuben Thomas] browse-url.el Opera support Simon Josefsson
@ 2004-01-15 14:12 ` Reuben Thomas
2004-01-15 14:28 ` Simon Josefsson
` (3 more replies)
[not found] ` <mailman.716.1074194876.928.bug-gnu-emacs@gnu.org>
1 sibling, 4 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-15 14:12 UTC (permalink / raw)
Cc: bug-gnu-emacs, Dave Love
On Thu, 15 Jan 2004, Simon Josefsson wrote:
> Dave Love <d.love@dl.ac.uk> writes:
>
> > [I removed the attachment of XEmacs code.]
> >
> > From: Reuben Thomas <rrt@sc3d.org>
> > Subject: browse-url.el Opera support
> > To: fx@gnu.org
> > Date: Tue, 13 Jan 2004 14:20:26 +0100 (CET)
> > Reply-To: Reuben Thomas <rrt@mupsych.org>
> >
> > I'm an Opera user and recently switched from XEmacs to FSF Emacs. The
> > XEmacs version of browse-url.el (in the mail-lib package) has support
> > for Opera; I was wondering if it might be possible to fold that into
> > the FSF version?
>
> I recall a discussion about this earlier, when someone proposed a
> patch for Opera, and that someone didn't think Emacs should support
> non-free browsers like Opera. The XEmacs folks didn't have that
> concern, though, so the patch was applied to that version of
> browse-url.el.
>
> If you think this decision should be reconsidered, for Emacs, I think
> it has to be discussed on emacs-devel@gnu.org.
I don't have the stomach for such a discussion right now. Having to argue
to get a patch that is acknowledged to be technically and legally fine
into a free software package against philosophical objections seems
rather contrary to much of the spirit of free software.
I supply bug reports and patches to free software projects all the time.
I'm quite happy to have them questioned on technical grounds; similarly,
if I find some code that would be useful in a free software project, it's
reasonable for the maintainers to enquire as to its provenance, especially
in a project like GNU where great pains are taken to ensure that the
software will always be legally free, by being owned by the FSF.
But this case is neither. It implies that the FSF not only wants me to use
free software, but is happy to use its considerable leverage (i.e. much of
the software I use is from the FSF) to bully me into doing so: use a free
web browser or we won't support you. As it happens, Opera is the one
non-free bit of software that I am aware of using regularly. I use it
because it works better for me than the alternatives. I wish it weren't
so; I find free software more satisfying on philosophical grounds, and in
general of higher quality and better supported than non-free software. But
a couple of years ago I didn't really see a better choice than Opera, and
I switched to it. I'm hoping that Mozilla Firebird, when it goes stable,
will replace Opera; I encourage other people to use Mozilla. But I don't
see what my (free!) choice of browser has to do with the authors of GNU
Emacs.
Funnily enough, I wouldn't even be involved in this discussion if it
weren't that browse-url.el sucks anyway: I can't remember another program
that I've had to throw several kb of script at before it can open URLs in
my web browser the way I want: in most programs, I just have to configure
a string that looks something like
foobrowser -remoteWindow("%u")
and it Just Works. This, of course, is an Emacs problem, not a GNU
problem, but it adds injury to insult [sic].
Oh well, better write me off as a deluded open-sourcer :-)
Sigh,
Reuben
--
http://www.mupsych.org/~rrt/
Fasting Alleviates Concupiscence Effortlessly
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-15 14:12 ` Reuben Thomas
@ 2004-01-15 14:28 ` Simon Josefsson
2004-01-16 19:54 ` Richard Stallman
` (2 subsequent siblings)
3 siblings, 0 replies; 21+ messages in thread
From: Simon Josefsson @ 2004-01-15 14:28 UTC (permalink / raw)
Cc: bug-gnu-emacs, Dave Love
If someone remember more details about the prior Opera browse-url
discussion, that would be useful. I tried searching a little, but
didn't find anything. I might have just imagined it... No, I found
it, here's a link:
http://article.gmane.org/gmane.emacs.xemacs.beta/1280/match=emacs+browse+url+opera
Reuben Thomas <rrt@sc3d.org> writes:
> use a free web browser or we won't support you.
Sorry, browse-url should support any browser, just use the
'browse-url-generic' browser and specify the name of the application
in `browse-url-generic-program'.
Giving an explicit reference to a commercial product is a step
further, and I can understand why a free program might not want to do
that.
> Funnily enough, I wouldn't even be involved in this discussion if it
> weren't that browse-url.el sucks anyway: I can't remember another program
> that I've had to throw several kb of script at before it can open URLs in
> my web browser the way I want: in most programs, I just have to configure
> a string that looks something like
>
> foobrowser -remoteWindow("%u")
>
> and it Just Works. This, of course, is an Emacs problem, not a GNU
> problem, but it adds injury to insult [sic].
Can you describe what your script does? Using the generic URL
browser, and then customizing `browse-url-generic-program' and
`browse-url-generic-args' seems rather flexible. I'm not sure how it
can be made more flexible.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-15 14:12 ` Reuben Thomas
2004-01-15 14:28 ` Simon Josefsson
@ 2004-01-16 19:54 ` Richard Stallman
2004-01-17 15:15 ` Reuben Thomas
[not found] ` <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>
[not found] ` <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>
2004-01-17 0:16 ` Dave Love
3 siblings, 2 replies; 21+ messages in thread
From: Richard Stallman @ 2004-01-16 19:54 UTC (permalink / raw)
Cc: bug-gnu-emacs, d.love, jas
The free software movement is based on the recognition that non-free
software is antisocial and unethical. It is a social problem, and our
work is to solve that problem. Success for us does not mean writing
popular free programs, it means ending the antisocial practice of
distributing non-free software.
Your argument for including this patch seems to be based on a
principle that that technical decisions should be made solely on
technical grounds. That principle is a grave and fundamental error.
It rejects the lessons society learned after the development of
nuclear weapons: that technical decisions must be based on
consideration of social responsibility. GNU derives from an idea of
social responsibility, and we make technical decisions based on that.
We can't tell what programs to use, but helping you use a non-free
program is not part of the GNU Project's mission. I decided before
not to include this code, and I stand by the decision.
Not supporting non-free programs in Emacs is one of the ways we show
we are serious when we say they are unethical. That may not convince
you, but we hope it will convince others.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-16 19:54 ` Richard Stallman
@ 2004-01-17 15:15 ` Reuben Thomas
2004-01-18 6:32 ` Simon Josefsson
2004-01-18 19:14 ` Richard Stallman
[not found] ` <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>
1 sibling, 2 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-17 15:15 UTC (permalink / raw)
Cc: bug-gnu-emacs, d.love, jas
On Fri, 16 Jan 2004, Richard Stallman wrote:
> The free software movement is based on the recognition that non-free
> software is antisocial and unethical. It is a social problem, and our
> work is to solve that problem. Success for us does not mean writing
> popular free programs, it means ending the antisocial practice of
> distributing non-free software.
The main means you've chosen to end the practice of distributing non-free
software is to distribute free alternatives, so you're not going to be
successful if your programs aren't popular.
> Your argument for including this patch seems to be based on a principle
> that that technical decisions should be made solely on technical
> grounds.
I have no such principle. If I had to state anything so dangerous as an
absolute principle, it would be much closer to your position than to the
one you infer. I do believe in proportionality, though: this particular
case (a very small feature) should, in my view be decided pretty much
purely on technical grounds. There are some matters that shouldn't: for
example, using a proprietary markup format instead of HTML for the WWW
would be unethical (as well as plain stupid) however technically superior
it might be.
The principle I lack is that principles are absolute criteria that must
always be applied (in particular, I don't believe that battles are lost
for want of a nail).
> That principle is a grave and fundamental error.
I agree completely.
> It rejects the lessons society learned after the development of nuclear
> weapons: that technical decisions must be based on consideration of
> social responsibility. GNU derives from an idea of social
> responsibility, and we make technical decisions based on that.
And again, I agree. I probably wouldn't be in the privileged position of
having an affordable computer system almost all of whose operation I can
scrutinise and change, all the while sharing those changes with others and
benefitting from their expertise and ideas, were it not for the efforts of
the FSF on whose software I largely depend.
> We can't tell what programs to use, but helping you use a non-free
> program is not part of the GNU Project's mission. I decided before
> not to include this code, and I stand by the decision.
It's up to the authors of a program what conditions they make on its use
and its development. I expressed my frustration with a particular
decision, but I can't claim that it's wrong. At least in this case I get a
reasoned argument from the authors; with non-free software that would be
the last thing I'd expect.
> Not supporting non-free programs in Emacs is one of the ways we show we
> are serious when we say they are unethical. That may not convince you,
> but we hope it will convince others.
I think I'm probably more convinced than most; and for all that I don't
entirely agree with your opinion, I'm very glad that someone holds it,
just as I'm also glad that not everyone does.
On second thoughts, I've found the time to look for a solution to this
particular problem in the form of code, which you'll find in another part
of this thread as a response to a message from Dave Love.
--
http://www.mupsych.org/~rrt/ | golf, n. a good walk spoiled (Twain)
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-17 15:15 ` Reuben Thomas
@ 2004-01-18 6:32 ` Simon Josefsson
2004-01-18 7:15 ` Reuben Thomas
` (4 more replies)
2004-01-18 19:14 ` Richard Stallman
1 sibling, 5 replies; 21+ messages in thread
From: Simon Josefsson @ 2004-01-18 6:32 UTC (permalink / raw)
Cc: bug-gnu-emacs, Richard Stallman, d.love
Let me add another more down-to-earth argument: if free software
support non-free tools, like Opera in browse-url.el in this example,
it becomes the free software people's work to make it work. The emacs
maintainers have to apply the patches, document it, change the code
whenever the tool changes its API, etc. This takes time, aka money.
It is not clear why Emacs maintainers should donate time to people
that don't give anything back. In some cases Emacs maintainers can do
so when it is easy to do, and makes the users considerably happier.
This seem to be the case for browse-url.el: as far as I recall,
Netscape wasn't free software initially, but browse-url support it.
If Opera Inc. were to donate money for support in browse-el.el, I
would reconsider the situation, and might allow the modification. But
I'm not sure the Emacs maintainers would. In that situation it may be
a good opportunity to push Opera Inc. into using a free license on
their software, instead of donating money. Unless the corporation's
is mainly interested in pursuing non-free software for its own sake,
it may make economical sense for them to re-license their software,
instead of donating money to free software projects for adding Opera
support. Especially if the sum of money would be large. A relicensed
Opera would be better for the free software community, instead of the
Emacs maintainers accepting money for making a certain modification.
So it might actually be better, in the long-term, to even refuse
donations in exchange for certain modifications.
Regarding your modified browse-url.el:
It is very difficult to evaluate your work when you send the entire
file, instead of a patch (use 'diff -u'). In any case, I don't think
anyone has requested removing support for already supported non-free
tools, like Netscape. Also, changing the type of existing variables,
like browse-url-generic-args, may break backwards compatibility, which
I think is a no-no for that kind of variable.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 6:32 ` Simon Josefsson
@ 2004-01-18 7:15 ` Reuben Thomas
2004-01-18 22:27 ` Reuben Thomas
` (3 subsequent siblings)
4 siblings, 0 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-18 7:15 UTC (permalink / raw)
Cc: bug-gnu-emacs, Richard Stallman, d.love
> It is very difficult to evaluate your work when you send the entire
> file, instead of a patch (use 'diff -u'). In any case, I don't think
> anyone has requested removing support for already supported non-free
> tools, like Netscape.
I thought of it as adding consistency rather than removing support!
> Also, changing the type of existing variables, like
> browse-url-generic-args, may break backwards compatibility, which I
> think is a no-no for that kind of variable.
OK, I'll rework and send a diff.
--
http://www.mupsych.org/~rrt/
impeccable, a. not liable to detection (Bierce)
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 6:32 ` Simon Josefsson
2004-01-18 7:15 ` Reuben Thomas
@ 2004-01-18 22:27 ` Reuben Thomas
2004-01-19 20:12 ` Richard Stallman
2004-01-19 18:35 ` Reuben Thomas
` (2 subsequent siblings)
4 siblings, 1 reply; 21+ messages in thread
From: Reuben Thomas @ 2004-01-18 22:27 UTC (permalink / raw)
Cc: Emacs Bugs, Richard Stallman, d.love
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1788 bytes --]
> Let me add another more down-to-earth argument: if free software
> support non-free tools, like Opera in browse-url.el in this example,
> it becomes the free software people's work to make it work. The emacs
> maintainers have to apply the patches, document it, change the code
> whenever the tool changes its API, etc. This takes time, aka money.
> It is not clear why Emacs maintainers should donate time to people
> that don't give anything back.
But it's becoming clear to me that here too, it depends. After all, Emacs
supports Windows and Netscape. It's a bit ironic that if you're a non-free
system with a near-monopoly (as Windows is and Netscape was) you can get
support. Opera, as a non-free product, is much less offensive (in
particular, it tries to be standards-compliant, and Opera Software don't
go around foisting new "standards" on the world) but it's too small to be
worth supporting...
> Unless the corporation's is mainly interested in pursuing non-free
> software for its own sake, it may make economical sense for them to
> re-license their software,
Sadly, Opera seem to make most of their money from licensing their
browser.
> Regarding your modified browse-url.el:
>
> It is very difficult to evaluate your work when you send the entire
> file, instead of a patch (use 'diff -u').
Attached. The diff is against browse-url.el as shipped with Emacs 21.3.1;
if you'd like it against CVS or something else, please ask.
> In any case, I don't think
> anyone has requested removing support for already supported non-free
> tools, like Netscape.
I've removed the other changes...
> Also, changing the type of existing variables,
> like browse-url-generic-args,
...including this.
--
http://www.mupsych.org/~rrt/ | The only person worth beating is yourself
[-- Attachment #2: Type: TEXT/PLAIN, Size: 3591 bytes --]
--- /usr/share/emacs/21.3/lisp/net/browse-url.el 2003-10-27 14:35:16.000000000 +0100
+++ /home/rrt/elisp/browse-url.el 2004-01-18 23:18:36.000000000 +0100
@@ -215,7 +215,7 @@
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
-;; ("." . browse-url-netscape)))
+;; ("." . browse-url-netscape)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
@@ -226,6 +226,7 @@
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
+ (require 'cl)
(require 'w3-auto nil t))
(defgroup browse-url nil
@@ -788,7 +789,7 @@
When called non-interactively, optional second argument NEW-WINDOW is
used instead of `browse-url-new-window-flag'."
- (interactive (browse-url-interactive-arg "URL: "))
+ (interactive (browse-url-interactive-arg "URL: "))
(apply 'start-process (concat "gnome-moz-remote " url)
nil
"gnome-moz-remote"
@@ -1079,10 +1080,44 @@
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load URL.
-Default to the URL around or before point. A fresh copy of the
-browser is started up in a new process with possible additional arguments
-`browse-url-generic-args'. This is appropriate for browsers which
-don't offer a form of remote control."
+Default to the URL around or before point. A fresh copy of the browser
+is started up in a new process with possible additional arguments
+`browse-url-generic-args', in which the URL is substituted for
+`__URL__' if it exists, or added as a final argument if not."
+ (interactive (browse-url-interactive-arg "URL: "))
+ (unless browse-url-generic-program
+ (error "No browser defined (`browse-url-generic-program')"))
+ (let (found-tok)
+ (let ((args
+ (mapcar
+ (lambda (s)
+ (if (string-match "__URL__" s)
+ (progn
+ (setq found-tok t)
+ (replace-match url t t s))
+ s))
+ browse-url-generic-args)))
+ (unless found-tok
+ (setq args (append args (list url))))
+ (apply 'start-process (concat browse-url-generic-program " " url) nil
+ browse-url-generic-program
+ args))))
+
+; Values for browse-url-generic-args
+;
+; These could be put in a list indexed by browser name to allow common
+; browsers to be chosen from a list and the method of starting the URL
+; (same window, new window, new tab) to be an option.
+;
+; Browser Same window New window New tab
+;
+; Opera "" -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-page)
+; Konqueror ?? "" ??
+; Mozilla -remote openURL(__URL__) -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-tab)
+; gnome-moz-remote --raise __URL__ --raise --newwin __URL__ --raise --remote=openURL(__URL__,new-tab)
+; lynx-xterm n/a xterm -e lynx __URL__ n/a
+
+ ;; new-window ignored
(interactive (browse-url-interactive-arg "URL: "))
(if (not browse-url-generic-program)
(error "No browser defined (`browse-url-generic-program')"))
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 22:27 ` Reuben Thomas
@ 2004-01-19 20:12 ` Richard Stallman
0 siblings, 0 replies; 21+ messages in thread
From: Richard Stallman @ 2004-01-19 20:12 UTC (permalink / raw)
Cc: bug-gnu-emacs, d.love, jas
But it's becoming clear to me that here too, it depends. After all, Emacs
supports Windows and Netscape.
We tell GNU package maintainers that it is their choice whether to
support a non-free system such as Windows. I don't spend time on
Emacs for Windows, but people volunteer to take care of it, so I let
them do it.
It is a strategic decision that having Emacs run on Microsoft Windows
is probably a good idea. Nobody can be completely certain, but
Microsoft Windows has more users than Emacs does.
But it's becoming clear to me that here too, it depends. After all, Emacs
supports Windows and Netscape. It's a bit ironic that if you're a non-free
system with a near-monopoly (as Windows is and Netscape was) you can get
support.
>From our point of view, non-free software is equally unethical in
either case. Supporting a widely used program does us more good and
tends to do them less good. Also, when a program is widely known,
there is no danger we will inform people of its existence and thus
lead them to try it.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 6:32 ` Simon Josefsson
2004-01-18 7:15 ` Reuben Thomas
2004-01-18 22:27 ` Reuben Thomas
@ 2004-01-19 18:35 ` Reuben Thomas
2004-01-19 18:38 ` Reuben Thomas
2004-02-05 15:44 ` Dave Love
4 siblings, 0 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-19 18:35 UTC (permalink / raw)
Cc: Emacs Bugs, Richard Stallman, d.love
[-- Attachment #1: Type: TEXT/PLAIN, Size: 325 bytes --]
On Sun, 18 Jan 2004, Simon Josefsson wrote:
> Regarding your modified browse-url.el:
I attach a new diff; I think the previous one may include some stray elisp
code from the middle of a function. Sorry about that.
--
http://www.mupsych.org/~rrt/
memoir, n. a lie that flatters the author's ego and the reader's intellect
[-- Attachment #2: Type: TEXT/PLAIN, Size: 3669 bytes --]
--- /usr/share/emacs/21.3/lisp/net/browse-url.el 2003-10-27 14:35:16.000000000 +0100
+++ /home/rrt/elisp/browse-url.el 2004-01-19 19:18:12.000000000 +0100
@@ -215,7 +215,7 @@
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
-;; ("." . browse-url-netscape)))
+;; ("." . browse-url-netscape)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
@@ -226,6 +226,7 @@
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
+ (require 'cl)
(require 'w3-auto nil t))
(defgroup browse-url nil
@@ -788,7 +789,7 @@
When called non-interactively, optional second argument NEW-WINDOW is
used instead of `browse-url-new-window-flag'."
- (interactive (browse-url-interactive-arg "URL: "))
+ (interactive (browse-url-interactive-arg "URL: "))
(apply 'start-process (concat "gnome-moz-remote " url)
nil
"gnome-moz-remote"
@@ -1079,16 +1080,42 @@
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load URL.
-Default to the URL around or before point. A fresh copy of the
-browser is started up in a new process with possible additional arguments
-`browse-url-generic-args'. This is appropriate for browsers which
-don't offer a form of remote control."
+Default to the URL around or before point. A fresh copy of the browser
+is started up in a new process with possible additional arguments
+`browse-url-generic-args', in which the URL is substituted for
+`__URL__' if it exists, or added as a final argument if not."
(interactive (browse-url-interactive-arg "URL: "))
- (if (not browse-url-generic-program)
+ (unless browse-url-generic-program
(error "No browser defined (`browse-url-generic-program')"))
- (apply 'start-process (concat browse-url-generic-program url) nil
- browse-url-generic-program
- (append browse-url-generic-args (list url))))
+ (let (found-tok)
+ (let ((args
+ (mapcar
+ (lambda (s)
+ (if (string-match "__URL__" s)
+ (progn
+ (setq found-tok t)
+ (replace-match url t t s))
+ s))
+ browse-url-generic-args)))
+ (unless found-tok
+ (setq args (append args (list url))))
+ (apply 'start-process (concat browse-url-generic-program " " "some url") nil
+ browse-url-generic-program
+ args))))
+
+; Values for browse-url-generic-args
+;
+; These could be put in a list indexed by browser name to allow common
+; browsers to be chosen from a list and the method of starting the URL
+; (same window, new window, new tab) to be an option.
+;
+; Browser Same window New window New tab
+;
+; Opera "" -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-page)
+; Konqueror ?? "" ??
+; Mozilla -remote openURL(__URL__) -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-tab)
+; gnome-moz-remote --raise __URL__ --raise --newwin __URL__ --raise --remote=openURL(__URL__,new-tab)
+; lynx-xterm n/a xterm -e lynx __URL__ n/a
;;;###autoload
(defun browse-url-kde (url &optional new-window)
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 6:32 ` Simon Josefsson
` (2 preceding siblings ...)
2004-01-19 18:35 ` Reuben Thomas
@ 2004-01-19 18:38 ` Reuben Thomas
2004-02-05 15:44 ` Dave Love
4 siblings, 0 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-19 18:38 UTC (permalink / raw)
Cc: Emacs Bugs, Richard Stallman, d.love
[-- Attachment #1: Type: TEXT/PLAIN, Size: 287 bytes --]
> Regarding your modified browse-url.el:
With many abasements, I offer yet another diff, this time reverting a
little debugging code in the previous diff to what I actually intended.
--
http://www.mupsych.org/~rrt/
My dark path darkens; rise over the mountain, distant moon (Murasaki)
[-- Attachment #2: Type: TEXT/PLAIN, Size: 3662 bytes --]
--- /usr/share/emacs/21.3/lisp/net/browse-url.el 2003-10-27 14:35:16.000000000 +0100
+++ /home/rrt/elisp/browse-url.el 2004-01-19 19:36:27.000000000 +0100
@@ -215,7 +215,7 @@
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
-;; ("." . browse-url-netscape)))
+;; ("." . browse-url-netscape)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
@@ -226,6 +226,7 @@
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
+ (require 'cl)
(require 'w3-auto nil t))
(defgroup browse-url nil
@@ -788,7 +789,7 @@
When called non-interactively, optional second argument NEW-WINDOW is
used instead of `browse-url-new-window-flag'."
- (interactive (browse-url-interactive-arg "URL: "))
+ (interactive (browse-url-interactive-arg "URL: "))
(apply 'start-process (concat "gnome-moz-remote " url)
nil
"gnome-moz-remote"
@@ -1079,16 +1080,42 @@
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load URL.
-Default to the URL around or before point. A fresh copy of the
-browser is started up in a new process with possible additional arguments
-`browse-url-generic-args'. This is appropriate for browsers which
-don't offer a form of remote control."
+Default to the URL around or before point. A fresh copy of the browser
+is started up in a new process with possible additional arguments
+`browse-url-generic-args', in which the URL is substituted for
+`__URL__' if it exists, or added as a final argument if not."
(interactive (browse-url-interactive-arg "URL: "))
- (if (not browse-url-generic-program)
+ (unless browse-url-generic-program
(error "No browser defined (`browse-url-generic-program')"))
- (apply 'start-process (concat browse-url-generic-program url) nil
- browse-url-generic-program
- (append browse-url-generic-args (list url))))
+ (let (found-tok)
+ (let ((args
+ (mapcar
+ (lambda (s)
+ (if (string-match "__URL__" s)
+ (progn
+ (setq found-tok t)
+ (replace-match url t t s))
+ s))
+ browse-url-generic-args)))
+ (unless found-tok
+ (setq args (append args (list url))))
+ (apply 'start-process (concat browse-url-generic-program " " url) nil
+ browse-url-generic-program
+ args))))
+
+; Values for browse-url-generic-args
+;
+; These could be put in a list indexed by browser name to allow common
+; browsers to be chosen from a list and the method of starting the URL
+; (same window, new window, new tab) to be an option.
+;
+; Browser Same window New window New tab
+;
+; Opera "" -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-page)
+; Konqueror ?? "" ??
+; Mozilla -remote openURL(__URL__) -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-tab)
+; gnome-moz-remote --raise __URL__ --raise --newwin __URL__ --raise --remote=openURL(__URL__,new-tab)
+; lynx-xterm n/a xterm -e lynx __URL__ n/a
;;;###autoload
(defun browse-url-kde (url &optional new-window)
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-18 6:32 ` Simon Josefsson
` (3 preceding siblings ...)
2004-01-19 18:38 ` Reuben Thomas
@ 2004-02-05 15:44 ` Dave Love
2004-02-05 16:09 ` Reuben Thomas
4 siblings, 1 reply; 21+ messages in thread
From: Dave Love @ 2004-02-05 15:44 UTC (permalink / raw)
Cc: Reuben Thomas, bug-gnu-emacs, Richard Stallman
Simon Josefsson <jas@extundo.com> writes:
> Let me add another more down-to-earth argument: if free software
> support non-free tools, like Opera in browse-url.el in this example,
> it becomes the free software people's work to make it work.
I'm afraid some of this sounds patronizing to me. (I'm sure it's not
meant to be.)
You should be able to find four or five Lisp files devoted to support
of non-free stuff straight off.
> The emacs
> maintainers have to apply the patches, document it, change the code
> whenever the tool changes its API, etc. This takes time, aka money.
> It is not clear why Emacs maintainers should donate time to people
> that don't give anything back.
I've donated interfaces to non-free stuff because I needed them
(e.g. for debugging tasks gdb couldn't do). There's no obligation on
users to give anything back -- it's free.
Anyhow, the point is that there should be a different interface so
it's _no_ maintenance work to support different browsers. If that
makes it easy to use proprietary ones, so be it, as long as it's easy
for the free ones I want to use.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-02-05 15:44 ` Dave Love
@ 2004-02-05 16:09 ` Reuben Thomas
0 siblings, 0 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-02-05 16:09 UTC (permalink / raw)
Cc: Emacs Bugs, Richard Stallman, Simon Josefsson
On Thu, 5 Feb 2004, Dave Love wrote:
[some stuff]
which reminded me that I submitted my patch to browse-url.el to improve
the handling of opening web browsers without being browser-specific some
weeks ago, and I've heard nothing back. Is this normal? Was there
something wrong with it? Should I resubmit, or what? Or did I just miss
something going on on emacs-bugs? (I'm not subscribed to it; is that a
problem when I submit a patch?)
--
http://www.mupsych.org/~rrt/
Fate is unmoved by hope; rather, what we hope for changes (Murasaki)
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-17 15:15 ` Reuben Thomas
2004-01-18 6:32 ` Simon Josefsson
@ 2004-01-18 19:14 ` Richard Stallman
1 sibling, 0 replies; 21+ messages in thread
From: Richard Stallman @ 2004-01-18 19:14 UTC (permalink / raw)
Cc: bug-gnu-emacs, d.love, jas
I am glad that our views are closer together than I had realized.
The main means you've chosen to end the practice of distributing non-free
software is to distribute free alternatives, so you're not going to be
successful if your programs aren't popular.
No need to worry. Emacs is popular enough.
I do believe in proportionality, though: this particular
case (a very small feature) should, in my view be decided pretty much
purely on technical grounds.
I try to decide each issue based on its most important consequences,
whether those be technical or social. We should never let the
intermediate goals block our view of the ultimate goal.
Thanks for working on simplifying browse-url.el. I will try to
take a look at the new version soon.
^ permalink raw reply [flat|nested] 21+ messages in thread
[parent not found: <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>]
* Re: [Reuben Thomas] browse-url.el Opera support
[not found] ` <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>
@ 2004-01-17 20:43 ` David Kastrup
0 siblings, 0 replies; 21+ messages in thread
From: David Kastrup @ 2004-01-17 20:43 UTC (permalink / raw)
Reuben Thomas <rrt@sc3d.org> writes:
> On Fri, 16 Jan 2004, Richard Stallman wrote:
>
> > The free software movement is based on the recognition that
> > non-free software is antisocial and unethical. It is a social
> > problem, and our work is to solve that problem. Success for us
> > does not mean writing popular free programs, it means ending the
> > antisocial practice of distributing non-free software.
>
> The main means you've chosen to end the practice of distributing
> non-free software is to distribute free alternatives, so you're not
> going to be successful if your programs aren't popular.
If my goal is free speech, then this goal is achieved when everybody
that wants to can speak up. Even if the percentage of those that
actually want to make use of that freedom are few.
> I have no such principle. If I had to state anything so dangerous as
> an absolute principle, it would be much closer to your position than
> to the one you infer. I do believe in proportionality, though: this
> particular case (a very small feature) should, in my view be decided
> pretty much purely on technical grounds.
On technical grounds, there is no necessity for it. There are
already hooks that make it reasonably easy to get the behavior you
want.
So it is easy enough for the Opera user community to discuss and
propose and implement and distribute what they consider best for
using in connection with Emacs. They just can't rely on the GNU
project to maintain and distribute and recommend such stuff.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 21+ messages in thread
[parent not found: <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>]
* Re: [Reuben Thomas] browse-url.el Opera support
[not found] ` <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>
@ 2004-01-16 21:43 ` David Kastrup
2004-01-17 12:53 ` Richard Stallman
0 siblings, 1 reply; 21+ messages in thread
From: David Kastrup @ 2004-01-16 21:43 UTC (permalink / raw)
Richard Stallman <rms@gnu.org> writes:
> The free software movement is based on the recognition that non-free
> software is antisocial and unethical. It is a social problem, and
> our work is to solve that problem. Success for us does not mean
> writing popular free programs, it means ending the antisocial
> practice of distributing non-free software.
Restricting the user's choice of what programs he might use for
whatever reasons is also restricting his freedoms.
However, in this case there is no such restriction: you can set
browse-url-generic-program and browse-url-generic-args to support
Opera, and then set browse-url-browser-function to point to
browse-url-generic.
In short: Opera is supported just fine, you just don't have a default
configuration for it distributed with Emacs.
So the question is not whether or not to support Opera (it is
supported via the generic interface), but to offer a default
configuration and cast into code a decision how Opera should be
supported best as considered by the GNU project.
Given that Opera is non-free software, the appropriate choice is to
leave this responsibility with the user.
I would consider the omission of a generic interface an unduly
restriction of the user. But this is not what we are having here.
If you want to configure your browser to be Opera, it will take you
setting 3 configuration variables instead of one, and making the
decision yourself how to call it.
That's tolerable.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-16 21:43 ` David Kastrup
@ 2004-01-17 12:53 ` Richard Stallman
0 siblings, 0 replies; 21+ messages in thread
From: Richard Stallman @ 2004-01-17 12:53 UTC (permalink / raw)
Cc: gnu-emacs-bug
Restricting the user's choice of what programs he might use for
whatever reasons is also restricting his freedoms.
Whatever we decide to support or not support, this does not restrict
the users. Since our software is free, they can change it.
They are never restricted by our technical decisions.
GNU Project policy is that supporting a non-free program is never a
high priority mission, not even when that program is widely used, as
is Microsoft Windows.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-15 14:12 ` Reuben Thomas
` (2 preceding siblings ...)
[not found] ` <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>
@ 2004-01-17 0:16 ` Dave Love
2004-01-17 15:27 ` Reuben Thomas
3 siblings, 1 reply; 21+ messages in thread
From: Dave Love @ 2004-01-17 0:16 UTC (permalink / raw)
Cc: bug-gnu-emacs, Simon Josefsson
Reuben Thomas <rrt@sc3d.org> writes:
> Funnily enough, I wouldn't even be involved in this discussion if it
> weren't that browse-url.el sucks anyway: I can't remember another program
> that I've had to throw several kb of script at before it can open URLs in
> my web browser the way I want:
I don't understand `several kb of script', but the point is right.
The current mechanism would have been junked if I'd been able to
continue maintaining browse-url.
> in most programs, I just have to configure
> a string that looks something like
>
> foobrowser -remoteWindow("%u")
>
> and it Just Works.
In most cases, I'd hope you wouldn't have to configure anything.
There should be heuristics to DTRT in common cases, e.g. use
`sensible-browser' (?) in Debian or whatever the environment variable
mechanism was that ESR proposed -- he does write some useful things.
Emacs shouldn't know about the specific browser you're using (except,
perhaps, when you want to run it in an Emacs window). Doing anything
else just clobbers free software users, who surely have more free
browsers available than proprietary ones. It's especially galling
that Emacs on MS Windows (as I understand it) does sort-of DTRT, if
invoking Internet Exploiter could be considered right.
browse-url should still be able to intercept and DTRT with mailto: &c,
of course.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [Reuben Thomas] browse-url.el Opera support
2004-01-17 0:16 ` Dave Love
@ 2004-01-17 15:27 ` Reuben Thomas
0 siblings, 0 replies; 21+ messages in thread
From: Reuben Thomas @ 2004-01-17 15:27 UTC (permalink / raw)
Cc: bug-gnu-emacs, Simon Josefsson
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2328 bytes --]
> I don't understand `several kb of script'
I was looking at the length of browse-url.el. I now see that a lot of it
isn't just calling browsers, but the bit that is (especially the support
for particular browsers) is embarrassingly long.
> The current mechanism would have been junked if I'd been able to
> continue maintaining browse-url.
I've had a go at reworking browse-url-generic to be useful with more
browsers and simpler to customise.
> In most cases, I'd hope you wouldn't have to configure anything.
:-) Well, browse-url already defaults to htmlview for the generic browser,
which works well for me.
OK, I attach a preliminary rework of browse-url.el. I've done three main
things:
1. In line with what RMS said elsewhere, I've removed support for non-free
browsers. Most of the code in this category was to support old versions of
Netscape. Mozilla and new versions of Netscape are adequately supported by
my new implementation of browse-url-generic.
2. I've removed support for other browsers that can be supported by my new
browse-url-generic, e.g. MMM, Grail, Lynx-in-xterm.
3. I've rewritten browse-url-generic so that browse-url-generic-args is a
string, not a list (I've not redone the other browser support code to be
consistent with this; perhaps it's not worthwhile or even
counterproductive). This string may contain the token __URL__; if so, the
URL given is substituted for it. Otherwise, the URL is added as an extra
final argument. The string is split at spaces to be passed to
start-process.
The reason for using a string rather than a list of args is that it's
easier for users to configure. Slightly more careful parsing of the string
(e.g. respecting quotes when splitting it into individual args) would
solve most remaining problems with that approach.
I'm also sorely tempted to remove the special support for Mosaic, as it's
long and the program is obsolete, but perhaps there are enough users on
older hardware who don't have alternative more modern browsers.
The version of browse-url.el I attach is a modified version of that
supplied with Emacs 21.3.1, and all the modifications are by me (I didn't
use any of the XEmacs code I mentioned before). It's also a little under
half the size of the 21.3.1 version.
--
http://www.mupsych.org/~rrt/ | Floc: an egregiously good aperitif
[-- Attachment #2: Type: TEXT/PLAIN, Size: 32103 bytes --]
;;; browse-url.el --- pass a URL to a WWW browser
;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001
;; Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: Dave Love <fx@gnu.org>
;; Created: 03 Apr 1995
;; Keywords: hypertext, hypermedia, mouse
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This package provides functions which read a URL (Uniform Resource
;; Locator) from the minibuffer, defaulting to the URL around point,
;; and ask a World-Wide Web browser to load it. It can also load the
;; URL associated with the current buffer. Different browsers use
;; different methods of remote control so there is one function for
;; each supported browser. If the chosen browser is not running, it
;; is started. Currently there is support for the following browsers,
;; some of them probably now obsolete:
;; Function Browser Earliest version
;; browse-url-mosaic XMosaic/mMosaic <= 2.4
;; browse-url-cci XMosaic 2.5
;; browse-url-w3 w3 0
;; browse-url-w3-gnudoit w3 remotely
;; browse-url-lynx-emacs Lynx 0
;; browse-url-generic arbitrary
;; browse-url-default-windows-browser MS-Windows browser
;; browse-url-gnome-moz GNOME interface to Mozilla
;; Browsers can cache Web pages so it may be necessary to tell them to
;; reload the current page if it has changed (e.g. if you have edited
;; it). There is currently no perfect automatic solution to this.
;; If using XMosaic before version 2.5, check the definition of
;; browse-url-usr1-signal below.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
;; XMosaic version 2.5 introduced Common Client Interface allowing you
;; to control mosaic through Unix sockets.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
;; William M. Perry's excellent "w3" WWW browser for
;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
;; has a function w3-follow-url-at-point, but that
;; doesn't let you edit the URL like browse-url.
;; The `gnuserv' package that can be used to control it in another
;; Emacs process is available from
;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
;; Lynx is now distributed by the FSF. See also
;; <URL:http://lynx.browser.org/>.
;; Free graphical browsers that could be used by `browse-url-generic'
;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and
;; <URL:http://www.unlv.edu/chimera/>, Arena
;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena>, Grail
;; <URL:http://grail.sourceforge.net/>, and Amaya
;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic
;; <URL:ftp://ftp.enst.fr/pub/mbone/mMosaic/>,
;; <URL:http://perso.enst.fr/~dauphin/mMosaic/> (with development
;; support for Java applets and multicast) can be used like Mosaic by
;; setting `browse-url-mosaic-program' appropriately.
;; I [Denis Howe, not Dave Love] recommend Nelson Minar
;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing
;; HTML and thank Nelson for his many useful comments on this code.
;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/
;; software/own/hm--html-menus/>. For composing correct HTML see also
;; PSGML the general SGML structure editor package
;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
;; with this.
;; This package generalises function html-previewer-process in Marc
;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the
;; ffap.el package. The huge hyperbole package also contains similar
;; functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Help!
;; Can you write and test some code for the Macintosh and Windows
;; Mozilla remote control APIs? (See the URL above).
;; Do any other browsers have remote control?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Usage
;; To display the URL at or before point:
;; M-x browse-url-at-point RET
;; or, similarly but with the opportunity to edit the URL extracted from
;; the buffer, use:
;; M-x browse-url
;; To display a URL by shift-clicking on it, put this in your ~/.emacs
;; file:
;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
;; (Note that using Shift-mouse-1 is not desirable because
;; that event has a standard meaning in Emacs.)
;; To display the current buffer in a web browser:
;; M-x browse-url-of-buffer RET
;; To display the current region in a web browser:
;; M-x browse-url-of-region RET
;; In Dired, to display the file named on the current line:
;; M-x browse-url-of-dired-file RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customisation (~/.emacs)
;; To see what variables are available for customization, type
;; `M-x set-variable browse-url TAB'. Better, use
;; `M-x customize-group browse-url'.
;; Bind the browse-url commands to keys with the `C-c C-z' prefix
;; (as used by html-helper-mode):
;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
;; (global-set-key "\C-c\C-zu" 'browse-url)
;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
;; (add-hook 'dired-mode-hook
;; (lambda ()
;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file)))
;; Browse URLs in mail messages under RMAIL by clicking mouse-2:
;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
;; Alternatively, add `goto-address' to `rmail-show-message-hook'.
;; Gnus provides a standard feature to activate URLs in article
;; buffers for invocation of browse-url.
;; Use the Emacs w3 browser when not running under X11:
;; (or (eq window-system 'x)
;; (setq browse-url-browser-function 'browse-url-w3))
;; To always save modified buffers before displaying the file in a browser:
;; (setq browse-url-save-file t)
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
;; ("." . browse-url-generic)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
(require 'w3-auto nil t))
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
:link '(emacs-commentary-link "browse-url")
:group 'hypermedia)
;;;###autoload
(defcustom browse-url-browser-function
(if (memq system-type '(windows-nt ms-dos))
'browse-url-default-windows-browser
'browse-url-generic)
"*Function to display the current buffer in a WWW browser.
This is used by the `browse-url-at-point', `browse-url-at-mouse', and
`browse-url-of-file' commands.
If the value is not a function it should be a list of pairs
\(REGEXP . FUNCTION). In this case the function called will be the one
associated with the first REGEXP which matches the current URL. The
function is passed the URL and any other args of `browse-url'. The last
regexp should probably be \".\" to specify a default browser."
:type '(choice
(function-item :tag "Emacs W3" :value browse-url-w3)
(function-item :tag "W3 in another Emacs via `gnudoit'"
:value browse-url-w3-gnudoit)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
(function-item :tag "Lynx in an Emacs window"
:value browse-url-lynx-emacs)
(function-item :tag "Specified by `Browse Url Generic Program'"
:value browse-url-generic)
(function-item :tag "Default Windows browser"
:value browse-url-default-windows-browser)
(function :tag "Your own function")
(alist :tag "Regexp/function association list"
:key-type regexp :value-type function))
:version "21.1"
:group 'browse-url)
;;;###autoload
(defcustom browse-url-new-window-flag nil
"*If non-nil, always open a new browser window with appropriate browsers.
Passing an interactive argument to \\[browse-url], or specific browser
commands reverses the effect of this variable. Requires Netscape version
1.1N or later or XMosaic version 2.5 or later if using those browsers."
:type 'boolean
:group 'browse-url)
(defcustom browse-url-mosaic-program "xmosaic"
"The name by which to invoke Mosaic (or mMosaic)."
:type 'string
:version "20.3"
:group 'browse-url)
(defcustom browse-url-mosaic-arguments nil
"A list of strings to pass to Mosaic as arguments."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-filename-alist
(\` ; Backquote syntax won't work.
(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/")
;; The above loses the username to avoid the browser prompting for
;; it in anonymous cases. If it's not anonymous the next regexp
;; applies.
("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
(,@ (if (memq system-type '(windows-nt ms-dos))
'(("^\\([a-zA-Z]:\\)[\\/]" . "file:\\1/")
("^[\\/][\\/]+" . "file://"))))
("^/+" . "file:/")))
"An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'.
Any substring of a filename matching one of the REGEXPs is replaced by
the corresponding STRING using `replace-match', not treating STRING
literally. All pairs are applied in the order given. The default
value converts ange-ftp/EFS-style paths into ftp URLs and prepends
`file:' to any path beginning with `/'.
For example, adding to the default a specific translation of an ange-ftp
address to an HTTP URL:
(setq browse-url-filename-alist
'((\"/webmaster@webserver:/home/www/html/\" .
\"http://www.acme.co.uk/\")
(\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\")
(\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\")
(\"^/+\" . \"file:/\")))
"
:type '(repeat (cons :format "%v"
(regexp :tag "Regexp")
(string :tag "Replacement")))
:version "20.3"
:group 'browse-url)
;;;###autoload
(defcustom browse-url-save-file nil
"*If non-nil, save the buffer before displaying its file.
Used by the `browse-url-of-file' command."
:type 'boolean
:group 'browse-url)
(defcustom browse-url-of-file-hook nil
"Run after `browse-url-of-file' has asked a browser to load a file."
:type 'hook
:group 'browse-url)
(defvar browse-url-usr1-signal
(if (and (boundp 'emacs-major-version)
(or (> emacs-major-version 19) (>= emacs-minor-version 29)))
'SIGUSR1 ; Why did I think this was in lower case before?
30) ; Check /usr/include/signal.h.
"The argument to `signal-process' for sending SIGUSR1 to XMosaic.
Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer
which is 30 on SunOS and 16 on HP-UX and Solaris.")
(defcustom browse-url-CCI-port 3003
"Port to access XMosaic via CCI.
This can be any number between 1024 and 65535 but must correspond to
the value set in the browser."
:type 'integer
:group 'browse-url)
(defcustom browse-url-CCI-host "localhost"
"*Host to access XMosaic via CCI.
This should be the host name of the machine running XMosaic with CCI
enabled. The port number should be set in `browse-url-CCI-port'."
:type 'string
:group 'browse-url)
(defvar browse-url-temp-file-name nil)
(make-variable-buffer-local 'browse-url-temp-file-name)
(defcustom browse-url-lynx-emacs-args (and (not window-system)
'("-show_cursor"))
"A list of strings defining options for Lynx in an Emacs buffer.
The default is none in a window system, otherwise `-show_cursor' to
indicate the position of the current link in the absence of
highlighting, assuming the normal default for showing the cursor."
:type '(repeat (string :tag "Argument"))
:version "20.3"
:group 'browse-url)
(defcustom browse-url-gnudoit-program "gnudoit"
"The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
:type 'string
:group 'browse-url)
(defcustom browse-url-gnudoit-args '("-q")
"*A list of strings defining options for `browse-url-gnudoit-program'.
These might set the port, for instance."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defcustom browse-url-generic-program "htmlview"
"*The name of the browser program used by `browse-url-generic'."
:type '(choice string (const :tag "None" nil))
:group 'browse-url)
(defcustom browse-url-generic-args ""
"*A string defining options for `browse-url-generic-program'."
:type 'string
:group 'browse-url)
(defcustom browse-url-temp-dir temporary-file-directory
"The name of a directory for browse-url's temporary files.
Such files are generated by functions like `browse-url-of-region'.
You might want to set this to somewhere with restricted read permissions
for privacy's sake."
:type 'string
:group 'browse-url)
(defcustom browse-url-lynx-input-field 'avoid
"*Action on selecting an existing Lynx buffer at an input field.
What to do when sending a new URL to an existing Lynx buffer in Emacs
if the Lynx cursor is on an input field (in which case the `g' command
would be entered as data). Such fields are recognized by the
underlines ____. Allowed values: nil: disregard it, 'warn: warn the
user and don't emit the URL, 'avoid: try to avoid the field by moving
down (this *won't* always work)."
:type '(choice (const :tag "Move to try to avoid field" :value avoid)
(const :tag "Disregard" :value nil)
(const :tag "Warn, don't emit URL" :value warn))
:version "20.3"
:group 'browse-url)
(defvar browse-url-lynx-input-attempts 10
"*How many times to try to move down from a series of lynx input fields.")
(defcustom browse-url-lynx-input-delay 0.2
"How many seconds to wait for lynx between moves down from an input field.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL input
(defun browse-url-url-at-point ()
(let ((url (thing-at-point 'url)))
(set-text-properties 0 (length url) nil url)
url))
;; Having this as a separate function called by the browser-specific
;; functions allows them to be stand-alone commands, making it easier
;; to switch between browsers.
(defun browse-url-interactive-arg (prompt)
"Read a URL from the minibuffer, prompting with PROMPT.
Default to the URL at or before point. If invoked with a mouse button,
set point to the position clicked first. Return a list for use in
`interactive' containing the URL and `browse-url-new-window-flag' or its
negation if a prefix argument was given."
(let ((event (elt (this-command-keys) 0)))
(and (listp event) (mouse-set-point event)))
(list (read-string prompt (browse-url-url-at-point))
(not (eq (null browse-url-new-window-flag)
(null current-prefix-arg)))))
;; interactive-p needs to be called at a function's top-level, hence
;; the macro.
(defmacro browse-url-maybe-new-window (arg)
`(if (interactive-p)
,arg
browse-url-new-window-flag))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browse current buffer
;;;###autoload
(defun browse-url-of-file (&optional file)
"Ask a WWW browser to display FILE.
Display the current buffer's file if FILE is nil or if called
interactively. Turn the filename into a URL with function
`browse-url-file-url'. Pass the URL to a browser using the
`browse-url' function then run `browse-url-of-file-hook'."
(interactive)
(or file
(setq file (buffer-file-name))
(error "Current buffer has no file"))
(let ((buf (get-file-buffer file)))
(if buf
(save-excursion
(set-buffer buf)
(cond ((not (buffer-modified-p)))
(browse-url-save-file (save-buffer))
(t (message "%s modified since last save" file))))))
(browse-url (browse-url-file-url file))
(run-hooks 'browse-url-of-file-hook))
(defun browse-url-file-url (file)
"Return the URL corresponding to FILE.
Use variable `browse-url-filename-alist' to map filenames to URLs."
;; URL-encode special chars, do % first
(let ((s 0))
(while (setq s (string-match "%" file s))
(setq file (replace-match "%25" t t file)
s (1+ s))))
(while (string-match "[*\"()',=;? ]" file)
(let ((enc (format "%%%x" (aref file (match-beginning 0)))))
(setq file (replace-match enc t t file))))
(dolist (map browse-url-filename-alist)
(when (and map (string-match (car map) file))
(setq file (replace-match (cdr map) t nil file))))
file)
;;;###autoload
(defun browse-url-of-buffer (&optional buffer)
"Ask a WWW browser to display BUFFER.
Display the current buffer if BUFFER is nil. Display only the
currently visible part of BUFFER (from a temporary file) if buffer is
narrowed."
(interactive)
(save-excursion
(and buffer (set-buffer buffer))
(let ((file-name
;; Ignore real name if restricted
(and (= (- (point-max) (point-min)) (buffer-size))
(or buffer-file-name
(and (boundp 'dired-directory) dired-directory)))))
(or file-name
(progn
(or browse-url-temp-file-name
(setq browse-url-temp-file-name
(convert-standard-filename
(make-temp-file
(expand-file-name "burl" browse-url-temp-dir)))))
(setq file-name browse-url-temp-file-name)
(write-region (point-min) (point-max) file-name nil 'no-message)))
(browse-url-of-file file-name))))
(defun browse-url-delete-temp-file (&optional temp-file-name)
;; Delete browse-url-temp-file-name from the file system
;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead
(let ((file-name (or temp-file-name browse-url-temp-file-name)))
(if (and file-name (file-exists-p file-name))
(delete-file file-name))))
(add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
;;;###autoload
(defun browse-url-of-dired-file ()
"In Dired, ask a WWW browser to display the file named on this line."
(interactive)
(browse-url-of-file (dired-get-filename)))
;;;###autoload
(defun browse-url-of-region (min max)
"Ask a WWW browser to display the current region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region min max)
(browse-url-of-buffer))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-independent commands
;; A generic command to call the current browse-url-browser-function
;;;###autoload
(defun browse-url (url &rest args)
"Ask a WWW browser to load URL.
Prompts for a URL, defaulting to the URL at or before point. Variable
`browse-url-browser-function' says which browser to use."
(interactive (browse-url-interactive-arg "URL: "))
(unless (interactive-p)
(setq args (or args (list browse-url-new-window-flag))))
(if (functionp browse-url-browser-function)
(apply browse-url-browser-function url args)
;; The `function' can be an alist; look down it for first match
;; and apply the function (which might be a lambda).
(catch 'done
(dolist (bf browse-url-browser-function)
(when (string-match (car bf) url)
(apply (cdr bf) url args)
(throw 'done t)))
(error "No browse-url-browser-function matching URL %s"
url))))
;;;###autoload
(defun browse-url-at-point (&optional arg)
"Ask a WWW browser to load the URL at or before point.
Doesn't let you edit the URL like `browse-url'. Variable
`browse-url-browser-function' says which browser to use."
(interactive "P")
(let ((url (browse-url-url-at-point)))
(if url
(browse-url url (if arg
(not browse-url-new-window-flag)
browse-url-new-window-flag))
(error "No URL found"))))
;;;###autoload
(defun browse-url-at-mouse (event)
"Ask a WWW browser to load a URL clicked with the mouse.
The URL is the one around or before the position of the mouse click
but point is not changed. Doesn't let you edit the URL like
`browse-url'. Variable `browse-url-browser-function' says which browser
to use."
(interactive "e")
(save-excursion
(mouse-set-point event)
;; This handles browse-url-new-window-flag properly
;; when it gets no arg.
(browse-url-at-point)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-specific commands
;; --- Default MS-Windows browser ---
(defun browse-url-default-windows-browser (url &optional new-window)
(interactive (browse-url-interactive-arg "URL: "))
(if (eq system-type 'ms-dos)
(if dos-windows-version
(shell-command (concat "start " (shell-quote-argument url)))
(error "Browsing URLs is not supported on this system"))
(w32-shell-execute "open" url)))
;;;###autoload
(defun browse-url-mosaic (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point. The strings in variable
`browse-url-mosaic-arguments' are also passed to Mosaic and the
program is invoked according to the variable
`browse-url-mosaic-program'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new Mosaic 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 "Mosaic URL: "))
(let ((pidfile (expand-file-name "~/.mosaicpid"))
pid)
(if (file-readable-p pidfile)
(save-excursion
(find-file pidfile)
(goto-char (point-min))
(setq pid (read (current-buffer)))
(kill-buffer nil)))
(if (and pid (zerop (signal-process pid 0))) ; Mosaic running
(save-excursion
(find-file (format "/tmp/Mosaic.%d" pid))
(erase-buffer)
(insert (if (browse-url-maybe-new-window new-window)
"newwin\n"
"goto\n")
url "\n")
(save-buffer)
(kill-buffer nil)
;; Send signal SIGUSR to Mosaic
(message "Signalling Mosaic...")
(signal-process pid browse-url-usr1-signal)
;; Or you could try:
;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
(message "Signalling Mosaic...done")
)
;; Mosaic not running - start it
(message "Starting Mosaic...")
(apply 'start-process "xmosaic" nil browse-url-mosaic-program
(append browse-url-mosaic-arguments (list url)))
(message "Starting Mosaic...done"))))
;; --- Mosaic using CCI ---
;;;###autoload
(defun browse-url-cci (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point.
This function only works for XMosaic version 2.5 or later. You must
select `CCI' from XMosaic's File menu, set the CCI Port Address to the
value of variable `browse-url-CCI-port', and enable `Accept requests'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new browser 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 "Mosaic URL: "))
(open-network-stream "browse-url" " *browse-url*"
browse-url-CCI-host browse-url-CCI-port)
;; Todo: start browser if fails
(process-send-string "browse-url"
(concat "get url (" url ") output "
(if (browse-url-maybe-new-window new-window)
"new"
"current")
"\r\n"))
(process-send-string "browse-url" "disconnect\r\n")
(delete-process "browse-url"))
;; --- W3 ---
;;;###autoload
(defun browse-url-w3 (url &optional new-window)
"Ask the w3 WWW browser to load URL.
Default to the URL around or before point.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new window. 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 "W3 URL: "))
(require 'w3) ; w3-fetch-other-window not autoloaded
(if (browse-url-maybe-new-window new-window)
(w3-fetch-other-window url)
(w3-fetch url)))
;;;###autoload
(defun browse-url-w3-gnudoit (url &optional new-window)
;; new-window ignored
"Ask another Emacs running gnuserv to load the URL using the W3 browser.
The `browse-url-gnudoit-program' program is used with options given by
`browse-url-gnudoit-args'. Default to the URL around or before point."
(interactive (browse-url-interactive-arg "W3 URL: "))
(apply 'start-process (concat "gnudoit:" url) nil
browse-url-gnudoit-program
(append browse-url-gnudoit-args
(list (concat "(w3-fetch \"" url "\")")
"(raise-frame)"))))
;; --- Lynx in an Emacs "term" window ---
;;;###autoload
(defun browse-url-lynx-emacs (url &optional new-buffer)
"Ask the Lynx WWW browser to load URL.
Default to the URL around or before point. With a prefix argument, run
a new Lynx process in a new buffer.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new lynx in a new term window,
otherwise use any 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 "Lynx URL: "))
(let* ((system-uses-terminfo t) ; Lynx uses terminfo
;; (term-term-name "vt100") ; ??
(buf (get-buffer "*lynx*"))
(proc (and buf (get-buffer-process buf)))
(n browse-url-lynx-input-attempts))
(if (and (browse-url-maybe-new-window new-buffer) buf)
;; Rename away the OLD buffer. This isn't very polite, but
;; term insists on working in a buffer named *lynx* and would
;; choke on *lynx*<1>
(progn (set-buffer buf)
(rename-uniquely)))
(if (or (browse-url-maybe-new-window new-buffer)
(not buf)
(not proc)
(not (memq (process-status proc) '(run stop))))
;; start a new lynx
(progn
(setq buf
(apply #'make-term
`("lynx" "lynx" nil ,@browse-url-lynx-emacs-args
,url)))
(switch-to-buffer buf)
(term-char-mode)
(set-process-sentinel
(get-buffer-process buf)
;; Don't leave around a dead one (especially because of its
;; munged keymap.)
(lambda (process event)
(if (not (memq (process-status process) '(run stop)))
(let ((buf (process-buffer process)))
(if buf (kill-buffer buf)))))))
;; send the url to lynx in the old buffer
(let ((win (get-buffer-window buf t)))
(if win
(select-window win)
(switch-to-buffer buf)))
(if (eq (following-char) ?_)
(cond ((eq browse-url-lynx-input-field 'warn)
(error "Please move out of the input field first"))
((eq browse-url-lynx-input-field 'avoid)
(while (and (eq (following-char) ?_) (> n 0))
(term-send-down) ; down arrow
(sit-for browse-url-lynx-input-delay))
(if (eq (following-char) ?_)
(error "Cannot move out of the input field, sorry")))))
(term-send-string proc (concat "g" ; goto
"\C-u" ; kill default url
url
"\r")))))
;; --- mailto ---
;;;###autoload
(defun browse-url-mail (url &optional new-window)
"Open a new mail message buffer within Emacs.
Default to using the mailto: URL around or before point as the
recipient's address. Supplying a non-nil interactive prefix argument
will cause the mail to be composed in another window rather than the
current one.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil use `compose-mail-other-window', otherwise `compose-mail'. 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 "Mailto URL: "))
(save-excursion
(let ((to (if (string-match "^mailto:" url)
(substring url 7)
url)))
(if (browse-url-maybe-new-window new-window)
(compose-mail-other-window to nil nil nil
(list 'insert-buffer (current-buffer)))
(compose-mail to nil nil nil nil
(list 'insert-buffer (current-buffer)))))))
;; --- Random browser ---
;;;###autoload
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load
URL. Default to the URL around or before point. The arguments passed
are defined by the string `browse-url-generic', in which the URL is
substituted for `__URL__' if it exists, or added as a final argument
if not."
(interactive (browse-url-interactive-arg "URL: "))
(if (not browse-url-generic-program)
(error "No browser defined (`browse-url-generic-program')"))
(let ((args
(if (string-match "__URL__" browse-url-generic-args)
(replace-match url t t browse-url-generic-args)
(concat browse-url-generic-args "" url))))
(apply 'start-process (concat browse-url-generic-program " " url) nil
browse-url-generic-program
(split-string args " "))))
; Values for browse-url-generic-args
;
; These could be put in a list indexed by browser name to allow common
; browsers to be chosen from a list and the method of starting the URL
; (same window, new window, new tab) to be an option.
;
; Browser Same window New window New tab
;
; Opera "" -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-page)
; Konqueror ?? "" ??
; Mozilla -remote openURL(__URL__) -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-tab)
; gnome-moz-remote --raise __URL__ --raise --newwin __URL__ --raise --remote=openURL(__URL__,new-tab)
; lynx-xterm n/a xterm -e lynx __URL__ n/a
(provide 'browse-url)
;;; browse-url.el ends here
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
^ permalink raw reply [flat|nested] 21+ messages in thread
[parent not found: <mailman.716.1074194876.928.bug-gnu-emacs@gnu.org>]
* [Reuben Thomas] browse-url.el Opera support
@ 2004-01-15 12:12 Dave Love
0 siblings, 0 replies; 21+ messages in thread
From: Dave Love @ 2004-01-15 12:12 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 44 bytes --]
[I removed the attachment of XEmacs code.]
[-- Attachment #2: Type: message/rfc822, Size: 48563 bytes --]
[-- Attachment #2.1.1: Type: text/plain, Size: 1724 bytes --]
I'm an Opera user and recently switched from XEmacs to FSF Emacs. The
XEmacs version of browse-url.el (in the mail-lib package) has support for
Opera; I was wondering if it might be possible to fold that into the FSF
version?
I just copied the Opera code from the XEmacs version and it seemed to work
nicely. The XEmacs file has the following copyright notice:
;;; browse-url.el --- pass a URL to a WWW browser
;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001, 2002
;; Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: XEmacs Development Team
;; Created: 03 Apr 1995
;; Keywords: hypertext, hypermedia, mouse
;; This file is part of XEmacs.
;; XEmacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; XEmacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
which suggests that the code is already assigned to the FSF, so it could
be included in GNU Emacs.
I attach the XEmacs version of browse-url.el, and my modified version of
FSF Emacs 21.3.1's browse-url.el. Let me know if I can help in any other
way.
--
http://www.mupsych.org/~rrt/ | Caution Children At Play Drive Slowly
(Anon)
[-- Attachment #2.1.2: Type: text/plain, Size: 45149 bytes --]
;;; browse-url.el --- pass a URL to a WWW browser
;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001
;; Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: Dave Love <fx@gnu.org>
;; Created: 03 Apr 1995
;; Keywords: hypertext, hypermedia, mouse
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This package provides functions which read a URL (Uniform Resource
;; Locator) from the minibuffer, defaulting to the URL around point,
;; and ask a World-Wide Web browser to load it. It can also load the
;; URL associated with the current buffer. Different browsers use
;; different methods of remote control so there is one function for
;; each supported browser. If the chosen browser is not running, it
;; is started. Currently there is support for the following browsers,
;; some of them probably now obsolete:
;; Function Browser Earliest version
;; browse-url-netscape Netscape 1.1b1
;; browse-url-mosaic XMosaic/mMosaic <= 2.4
;; browse-url-cci XMosaic 2.5
;; browse-url-w3 w3 0
;; browse-url-w3-gnudoit w3 remotely
;; browse-url-iximosaic IXI Mosaic ?
;; browse-url-lynx-* Lynx 0
;; browse-url-grail Grail 0.3b1
;; browse-url-mmm MMM ?
;; browse-url-generic arbitrary
;; browse-url-default-windows-browser MS-Windows browser
;; browse-url-gnome-moz GNOME interface to Mozilla
;; browse-url-kde KDE konqueror (kfm)
;; [A version of the Netscape browser is now free software
;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is
;; reasonable to have that as the default.]
;; Note that versions of Netscape before 1.1b1 did not have remote
;; control. <URL:http://www.netscape.com/newsref/std/x-remote.html>.
;; Browsers can cache Web pages so it may be necessary to tell them to
;; reload the current page if it has changed (e.g. if you have edited
;; it). There is currently no perfect automatic solution to this.
;; Netscape allows you to specify the id of the window you want to
;; control but which window DO you want to control and how do you
;; discover its id?
;; If using XMosaic before version 2.5, check the definition of
;; browse-url-usr1-signal below.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
;; XMosaic version 2.5 introduced Common Client Interface allowing you
;; to control mosaic through Unix sockets.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
;; William M. Perry's excellent "w3" WWW browser for
;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
;; has a function w3-follow-url-at-point, but that
;; doesn't let you edit the URL like browse-url.
;; The `gnuserv' package that can be used to control it in another
;; Emacs process is available from
;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
;; Grail is the freely available WWW browser implemented in Python, a
;; cool object-oriented freely available interpreted language. Grail
;; 0.3b1 was the first version to have remote control as distributed.
;; For more information on Grail see
;; <URL:http://grail.cnri.reston.va.us/> and for more information on
;; Python see <url:http://www.python.org/>. Grail support in
;; browse-url.el written by Barry Warsaw <bwarsaw@python.org>.
;; MMM is a semi-free WWW browser implemented in Objective Caml, an
;; interesting impure functional programming language. See
;; <URL:http://pauillac.inria.fr/%7Erouaix/mmm/>.
;; Lynx is now distributed by the FSF. See also
;; <URL:http://lynx.browser.org/>.
;; Free graphical browsers that could be used by `browse-url-generic'
;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and
;; <URL:http://www.unlv.edu/chimera/>, Arena
;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena> and Amaya
;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic
;; <URL:ftp://ftp.enst.fr/pub/mbone/mMosaic/>,
;; <URL:http://perso.enst.fr/~dauphin/mMosaic/> (with development
;; support for Java applets and multicast) can be used like Mosaic by
;; setting `browse-url-mosaic-program' appropriately.
;; I [Denis Howe, not Dave Love] recommend Nelson Minar
;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing
;; HTML and thank Nelson for his many useful comments on this code.
;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/
;; software/own/hm--html-menus/>. For composing correct HTML see also
;; PSGML the general SGML structure editor package
;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
;; with this.
;; This package generalises function html-previewer-process in Marc
;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the
;; ffap.el package. The huge hyperbole package also contains similar
;; functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Help!
;; Can you write and test some code for the Macintrash and Windoze
;; Netscape remote control APIs? (See the URL above).
;; Do any other browsers have remote control?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Usage
;; To display the URL at or before point:
;; M-x browse-url-at-point RET
;; or, similarly but with the opportunity to edit the URL extracted from
;; the buffer, use:
;; M-x browse-url
;; To display a URL by shift-clicking on it, put this in your ~/.emacs
;; file:
;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
;; (Note that using Shift-mouse-1 is not desirable because
;; that event has a standard meaning in Emacs.)
;; To display the current buffer in a web browser:
;; M-x browse-url-of-buffer RET
;; To display the current region in a web browser:
;; M-x browse-url-of-region RET
;; In Dired, to display the file named on the current line:
;; M-x browse-url-of-dired-file RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customisation (~/.emacs)
;; To see what variables are available for customization, type
;; `M-x set-variable browse-url TAB'. Better, use
;; `M-x customize-group browse-url'.
;; Bind the browse-url commands to keys with the `C-c C-z' prefix
;; (as used by html-helper-mode):
;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
;; (global-set-key "\C-c\C-zu" 'browse-url)
;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
;; (add-hook 'dired-mode-hook
;; (lambda ()
;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file)))
;; Browse URLs in mail messages under RMAIL by clicking mouse-2:
;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
;; Alternatively, add `goto-address' to `rmail-show-message-hook'.
;; Gnus provides a standard feature to activate URLs in article
;; buffers for invocation of browse-url.
;; Use the Emacs w3 browser when not running under X11:
;; (or (eq window-system 'x)
;; (setq browse-url-browser-function 'browse-url-w3))
;; To always save modified buffers before displaying the file in a browser:
;; (setq browse-url-save-file t)
;; To get round the Netscape caching problem, you could EITHER have
;; write-file in html-helper-mode make Netscape reload the document:
;;
;; (autoload 'browse-url-netscape-reload "browse-url"
;; "Ask a WWW browser to redisplay the current file." t)
;; (add-hook 'html-helper-mode-hook
;; (lambda ()
;; (add-hook 'local-write-file-hooks
;; (lambda ()
;; (let ((local-write-file-hooks))
;; (save-buffer))
;; (browse-url-netscape-reload)
;; t) ; => file written by hook
;; t))) ; append to l-w-f-hooks
;;
;; OR have browse-url-of-file ask Netscape to load and then reload the
;; file:
;;
;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
;; You may also want to customise browse-url-netscape-arguments, e.g.
;; (setq browse-url-netscape-arguments '("-install"))
;;
;; or similarly for the other browsers.
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
;; ("." . browse-url-netscape)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
(require 'w3-auto nil t))
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
:link '(emacs-commentary-link "browse-url")
:group 'hypermedia)
;;;###autoload
(defcustom browse-url-browser-function
(if (memq system-type '(windows-nt ms-dos))
'browse-url-default-windows-browser
'browse-url-generic)
"*Function to display the current buffer in a WWW browser.
This is used by the `browse-url-at-point', `browse-url-at-mouse', and
`browse-url-of-file' commands.
If the value is not a function it should be a list of pairs
\(REGEXP . FUNCTION). In this case the function called will be the one
associated with the first REGEXP which matches the current URL. The
function is passed the URL and any other args of `browse-url'. The last
regexp should probably be \".\" to specify a default browser."
:type '(choice
(function-item :tag "Emacs W3" :value browse-url-w3)
(function-item :tag "W3 in another Emacs via `gnudoit'"
:value browse-url-w3-gnudoit)
(function-item :tag "Netscape" :value browse-url-netscape)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
(function-item :tag "IXI Mosaic" :value browse-url-iximosaic)
(function-item :tag "Lynx in an xterm window"
:value browse-url-lynx-xterm)
(function-item :tag "Lynx in an Emacs window"
:value browse-url-lynx-emacs)
(function-item :tag "Grail" :value browse-url-grail)
(function-item :tag "MMM" :value browse-url-mmm)
(function-item :tag "KDE" :value browse-url-kde)
(function-item :tag "Specified by `Browse Url Generic Program'"
:value browse-url-generic)
(function-item :tag "Default Windows browser"
:value browse-url-default-windows-browser)
(function-item :tag "GNOME invoking Mozilla"
:value browse-url-gnome-moz)
(function :tag "Your own function")
(alist :tag "Regexp/function association list"
:key-type regexp :value-type function))
:version "21.1"
:group 'browse-url)
(defcustom browse-url-netscape-program "netscape"
;; Info about netscape-remote from Karl Berry.
"The name by which to invoke Netscape.
The free program `netscape-remote' from
<URL:http://home.netscape.com/newsref/std/remote.c> is said to start
up very much quicker than `netscape'. Reported to compile on a GNU
system, given vroot.h from the same directory, with cc flags
-DSTANDALONE -L/usr/X11R6/lib -lXmu -lX11."
:type 'string
:group 'browse-url)
(defcustom browse-url-netscape-arguments nil
"A list of strings to pass to Netscape as arguments."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments
"A list of strings to pass to Netscape when it starts up.
Defaults to the value of `browse-url-netscape-arguments' at the time
`browse-url' is loaded."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defcustom browse-url-new-window-flag nil
"*If non-nil, always open a new browser window with appropriate browsers.
Passing an interactive argument to \\[browse-url], or specific browser
commands reverses the effect of this variable. Requires Netscape version
1.1N or later or XMosaic version 2.5 or later if using those browsers."
:type 'boolean
:group 'browse-url)
;;;###autoload
(defcustom browse-url-netscape-display nil
"*The X display for running Netscape, if not same as Emacs'."
:type '(choice string (const :tag "Default" nil))
:group 'browse-url)
(defcustom browse-url-mosaic-program "xmosaic"
"The name by which to invoke Mosaic (or mMosaic)."
:type 'string
:version "20.3"
:group 'browse-url)
(defcustom browse-url-mosaic-arguments nil
"A list of strings to pass to Mosaic as arguments."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-filename-alist
(\` ; Backquote syntax won't work.
(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/")
;; The above loses the username to avoid the browser prompting for
;; it in anonymous cases. If it's not anonymous the next regexp
;; applies.
("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
(,@ (if (memq system-type '(windows-nt ms-dos))
'(("^\\([a-zA-Z]:\\)[\\/]" . "file:\\1/")
("^[\\/][\\/]+" . "file://"))))
("^/+" . "file:/")))
"An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'.
Any substring of a filename matching one of the REGEXPs is replaced by
the corresponding STRING using `replace-match', not treating STRING
literally. All pairs are applied in the order given. The default
value converts ange-ftp/EFS-style paths into ftp URLs and prepends
`file:' to any path beginning with `/'.
For example, adding to the default a specific translation of an ange-ftp
address to an HTTP URL:
(setq browse-url-filename-alist
'((\"/webmaster@webserver:/home/www/html/\" .
\"http://www.acme.co.uk/\")
(\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\")
(\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\")
(\"^/+\" . \"file:/\")))
"
:type '(repeat (cons :format "%v"
(regexp :tag "Regexp")
(string :tag "Replacement")))
:version "20.3"
:group 'browse-url)
;;;###autoload
(defcustom browse-url-save-file nil
"*If non-nil, save the buffer before displaying its file.
Used by the `browse-url-of-file' command."
:type 'boolean
:group 'browse-url)
(defcustom browse-url-of-file-hook nil
"Run after `browse-url-of-file' has asked a browser to load a file.
Set this to `browse-url-netscape-reload' to force Netscape to load the
file rather than displaying a cached copy."
:type 'hook
:options '(browse-url-netscape-reload)
:group 'browse-url)
(defvar browse-url-usr1-signal
(if (and (boundp 'emacs-major-version)
(or (> emacs-major-version 19) (>= emacs-minor-version 29)))
'SIGUSR1 ; Why did I think this was in lower case before?
30) ; Check /usr/include/signal.h.
"The argument to `signal-process' for sending SIGUSR1 to XMosaic.
Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer
which is 30 on SunOS and 16 on HP-UX and Solaris.")
(defcustom browse-url-CCI-port 3003
"Port to access XMosaic via CCI.
This can be any number between 1024 and 65535 but must correspond to
the value set in the browser."
:type 'integer
:group 'browse-url)
(defcustom browse-url-CCI-host "localhost"
"*Host to access XMosaic via CCI.
This should be the host name of the machine running XMosaic with CCI
enabled. The port number should be set in `browse-url-CCI-port'."
:type 'string
:group 'browse-url)
(defvar browse-url-temp-file-name nil)
(make-variable-buffer-local 'browse-url-temp-file-name)
(defcustom browse-url-xterm-program "xterm"
"The name of the terminal emulator used by `browse-url-lynx-xterm'.
This might, for instance, be a separate colour version of xterm."
:type 'string
:group 'browse-url)
(defcustom browse-url-xterm-args nil
"*A list of strings defining options for `browse-url-xterm-program'.
These might set its size, for instance."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-lynx-emacs-args (and (not window-system)
'("-show_cursor"))
"A list of strings defining options for Lynx in an Emacs buffer.
The default is none in a window system, otherwise `-show_cursor' to
indicate the position of the current link in the absence of
highlighting, assuming the normal default for showing the cursor."
:type '(repeat (string :tag "Argument"))
:version "20.3"
:group 'browse-url)
(defcustom browse-url-gnudoit-program "gnudoit"
"The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
:type 'string
:group 'browse-url)
(defcustom browse-url-gnudoit-args '("-q")
"*A list of strings defining options for `browse-url-gnudoit-program'.
These might set the port, for instance."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defcustom browse-url-generic-program "htmlview"
"*The name of the browser program used by `browse-url-generic'."
:type '(choice string (const :tag "None" nil))
:group 'browse-url)
(defcustom browse-url-generic-args nil
"*A list of strings defining options for `browse-url-generic-program'."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-temp-dir temporary-file-directory
"The name of a directory for browse-url's temporary files.
Such files are generated by functions like `browse-url-of-region'.
You might want to set this to somewhere with restricted read permissions
for privacy's sake."
:type 'string
:group 'browse-url)
(defcustom browse-url-netscape-version
3
"The version of Netscape you are using.
This affects how URL reloading is done; the mechanism changed
incompatibly at version 4."
:type 'number
:group 'browse-url)
(defcustom browse-url-lynx-input-field 'avoid
"*Action on selecting an existing Lynx buffer at an input field.
What to do when sending a new URL to an existing Lynx buffer in Emacs
if the Lynx cursor is on an input field (in which case the `g' command
would be entered as data). Such fields are recognized by the
underlines ____. Allowed values: nil: disregard it, 'warn: warn the
user and don't emit the URL, 'avoid: try to avoid the field by moving
down (this *won't* always work)."
:type '(choice (const :tag "Move to try to avoid field" :value avoid)
(const :tag "Disregard" :value nil)
(const :tag "Warn, don't emit URL" :value warn))
:version "20.3"
:group 'browse-url)
(defvar browse-url-lynx-input-attempts 10
"*How many times to try to move down from a series of lynx input fields.")
(defcustom browse-url-lynx-input-delay 0.2
"How many seconds to wait for lynx between moves down from an input field.")
(defcustom browse-url-kde-program "kfmclient"
"The name by which to invoke the KDE web browser."
:type 'string
:version "21.1"
:group 'browse-url)
(defcustom browse-url-kde-args '("openURL")
"*A list of strings defining options for `browse-url-kde-program'."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL input
(defun browse-url-url-at-point ()
(let ((url (thing-at-point 'url)))
(set-text-properties 0 (length url) nil url)
url))
;; Having this as a separate function called by the browser-specific
;; functions allows them to be stand-alone commands, making it easier
;; to switch between browsers.
(defun browse-url-interactive-arg (prompt)
"Read a URL from the minibuffer, prompting with PROMPT.
Default to the URL at or before point. If invoked with a mouse button,
set point to the position clicked first. Return a list for use in
`interactive' containing the URL and `browse-url-new-window-flag' or its
negation if a prefix argument was given."
(let ((event (elt (this-command-keys) 0)))
(and (listp event) (mouse-set-point event)))
(list (read-string prompt (browse-url-url-at-point))
(not (eq (null browse-url-new-window-flag)
(null current-prefix-arg)))))
;; interactive-p needs to be called at a function's top-level, hence
;; the macro.
(defmacro browse-url-maybe-new-window (arg)
`(if (interactive-p)
,arg
browse-url-new-window-flag))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browse current buffer
;;;###autoload
(defun browse-url-of-file (&optional file)
"Ask a WWW browser to display FILE.
Display the current buffer's file if FILE is nil or if called
interactively. Turn the filename into a URL with function
`browse-url-file-url'. Pass the URL to a browser using the
`browse-url' function then run `browse-url-of-file-hook'."
(interactive)
(or file
(setq file (buffer-file-name))
(error "Current buffer has no file"))
(let ((buf (get-file-buffer file)))
(if buf
(save-excursion
(set-buffer buf)
(cond ((not (buffer-modified-p)))
(browse-url-save-file (save-buffer))
(t (message "%s modified since last save" file))))))
(browse-url (browse-url-file-url file))
(run-hooks 'browse-url-of-file-hook))
(defun browse-url-file-url (file)
"Return the URL corresponding to FILE.
Use variable `browse-url-filename-alist' to map filenames to URLs."
;; URL-encode special chars, do % first
(let ((s 0))
(while (setq s (string-match "%" file s))
(setq file (replace-match "%25" t t file)
s (1+ s))))
(while (string-match "[*\"()',=;? ]" file)
(let ((enc (format "%%%x" (aref file (match-beginning 0)))))
(setq file (replace-match enc t t file))))
(dolist (map browse-url-filename-alist)
(when (and map (string-match (car map) file))
(setq file (replace-match (cdr map) t nil file))))
file)
;;;###autoload
(defun browse-url-of-buffer (&optional buffer)
"Ask a WWW browser to display BUFFER.
Display the current buffer if BUFFER is nil. Display only the
currently visible part of BUFFER (from a temporary file) if buffer is
narrowed."
(interactive)
(save-excursion
(and buffer (set-buffer buffer))
(let ((file-name
;; Ignore real name if restricted
(and (= (- (point-max) (point-min)) (buffer-size))
(or buffer-file-name
(and (boundp 'dired-directory) dired-directory)))))
(or file-name
(progn
(or browse-url-temp-file-name
(setq browse-url-temp-file-name
(convert-standard-filename
(make-temp-file
(expand-file-name "burl" browse-url-temp-dir)))))
(setq file-name browse-url-temp-file-name)
(write-region (point-min) (point-max) file-name nil 'no-message)))
(browse-url-of-file file-name))))
(defun browse-url-delete-temp-file (&optional temp-file-name)
;; Delete browse-url-temp-file-name from the file system
;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead
(let ((file-name (or temp-file-name browse-url-temp-file-name)))
(if (and file-name (file-exists-p file-name))
(delete-file file-name))))
(add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
;;;###autoload
(defun browse-url-of-dired-file ()
"In Dired, ask a WWW browser to display the file named on this line."
(interactive)
(browse-url-of-file (dired-get-filename)))
;;;###autoload
(defun browse-url-of-region (min max)
"Ask a WWW browser to display the current region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region min max)
(browse-url-of-buffer))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-independent commands
;; A generic command to call the current browse-url-browser-function
;;;###autoload
(defun browse-url (url &rest args)
"Ask a WWW browser to load URL.
Prompts for a URL, defaulting to the URL at or before point. Variable
`browse-url-browser-function' says which browser to use."
(interactive (browse-url-interactive-arg "URL: "))
(unless (interactive-p)
(setq args (or args (list browse-url-new-window-flag))))
(if (functionp browse-url-browser-function)
(apply browse-url-browser-function url args)
;; The `function' can be an alist; look down it for first match
;; and apply the function (which might be a lambda).
(catch 'done
(dolist (bf browse-url-browser-function)
(when (string-match (car bf) url)
(apply (cdr bf) url args)
(throw 'done t)))
(error "No browse-url-browser-function matching URL %s"
url))))
;;;###autoload
(defun browse-url-at-point (&optional arg)
"Ask a WWW browser to load the URL at or before point.
Doesn't let you edit the URL like `browse-url'. Variable
`browse-url-browser-function' says which browser to use."
(interactive "P")
(let ((url (browse-url-url-at-point)))
(if url
(browse-url url (if arg
(not browse-url-new-window-flag)
browse-url-new-window-flag))
(error "No URL found"))))
;;;###autoload
(defun browse-url-at-mouse (event)
"Ask a WWW browser to load a URL clicked with the mouse.
The URL is the one around or before the position of the mouse click
but point is not changed. Doesn't let you edit the URL like
`browse-url'. Variable `browse-url-browser-function' says which browser
to use."
(interactive "e")
(save-excursion
(mouse-set-point event)
;; This handles browse-url-new-window-flag properly
;; when it gets no arg.
(browse-url-at-point)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-specific commands
;; --- Default MS-Windows browser ---
(defun browse-url-default-windows-browser (url &optional new-window)
(interactive (browse-url-interactive-arg "URL: "))
(if (eq system-type 'ms-dos)
(if dos-windows-version
(shell-command (concat "start " (shell-quote-argument url)))
(error "Browsing URLs is not supported on this system"))
(w32-shell-execute "open" url)))
;; --- Netscape ---
(defun browse-url-process-environment ()
"Set DISPLAY in the environment to the X display Netscape is running on.
This is either the value of variable `browse-url-netscape-display' if
non-nil, or the same display as Emacs if different from the current
environment, otherwise just use the current environment."
(let ((display (or browse-url-netscape-display (browse-url-emacs-display))))
(if display
(cons (concat "DISPLAY=" display) process-environment)
process-environment)))
(defun browse-url-emacs-display ()
"Return the X display Emacs is running on.
This is nil if the display is the same as the DISPLAY environment variable.
Actually Emacs could be using several displays; this just returns the
one showing the selected frame."
(let ((display (cdr-safe (assq 'display (frame-parameters)))))
(and (not (equal display (getenv "DISPLAY")))
display)))
;;;###autoload
(defun browse-url-netscape (url &optional new-window)
"Ask the Netscape WWW browser to load URL.
Default to the URL around or before point. The strings in variable
`browse-url-netscape-arguments' are also passed to Netscape.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new Netscape 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 "netscape " url) nil
browse-url-netscape-program
(append
browse-url-netscape-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")
")"))))))))
(set-process-sentinel process
`(lambda (process change)
(browse-url-netscape-sentinel process ,url)))))
(defun browse-url-netscape-sentinel (process url)
"Handle a change to the process communicating with Netscape."
(or (eq (process-exit-status process) 0)
(let* ((process-environment (browse-url-process-environment)))
;; Netscape not running - start it
(message "Starting Netscape...")
(apply 'start-process (concat "netscape" url) nil
browse-url-netscape-program
(append browse-url-netscape-startup-arguments (list url))))))
(defun browse-url-netscape-reload ()
"Ask Netscape to reload its current document.
How depends on `browse-url-netscape-version'."
(interactive)
;; Backwards incompatibility reported by
;; <peter.kruse@psychologie.uni-regensburg.de>.
(browse-url-netscape-send (if (>= browse-url-netscape-version 4)
"xfeDoCommand(reload)"
"reload")))
(defun browse-url-netscape-send (command)
"Send a remote control command to Netscape."
(let* ((process-environment (browse-url-process-environment)))
(apply 'start-process "netscape" nil
browse-url-netscape-program
(append browse-url-netscape-arguments
(list "-remote" command)))))
;; GNOME means of invoking either Mozilla or Netrape.
(defcustom browse-url-gnome-moz-arguments '()
"A list of strings passed to the GNOME mozilla viewer as arguments."
:version "21.1"
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defun browse-url-gnome-moz (url &optional new-window)
"Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'.
Default to the URL around or before point. The strings in variable
`browse-url-gnome-moz-arguments' are also passed.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new browser window, otherwise use an
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: "))
(apply 'start-process (concat "gnome-moz-remote " url)
nil
"gnome-moz-remote"
(append
browse-url-gnome-moz-arguments
(if (browse-url-maybe-new-window new-window)
'("--newwin"))
(list "--raise" url))))
;; --- Mosaic ---
;;;###autoload
(defun browse-url-mosaic (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point. The strings in variable
`browse-url-mosaic-arguments' are also passed to Mosaic and the
program is invoked according to the variable
`browse-url-mosaic-program'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new Mosaic 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 "Mosaic URL: "))
(let ((pidfile (expand-file-name "~/.mosaicpid"))
pid)
(if (file-readable-p pidfile)
(save-excursion
(find-file pidfile)
(goto-char (point-min))
(setq pid (read (current-buffer)))
(kill-buffer nil)))
(if (and pid (zerop (signal-process pid 0))) ; Mosaic running
(save-excursion
(find-file (format "/tmp/Mosaic.%d" pid))
(erase-buffer)
(insert (if (browse-url-maybe-new-window new-window)
"newwin\n"
"goto\n")
url "\n")
(save-buffer)
(kill-buffer nil)
;; Send signal SIGUSR to Mosaic
(message "Signalling Mosaic...")
(signal-process pid browse-url-usr1-signal)
;; Or you could try:
;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
(message "Signalling Mosaic...done")
)
;; Mosaic not running - start it
(message "Starting Mosaic...")
(apply 'start-process "xmosaic" nil browse-url-mosaic-program
(append browse-url-mosaic-arguments (list url)))
(message "Starting Mosaic...done"))))
;; --- Grail ---
;;;###autoload
(defvar browse-url-grail
(concat (or (getenv "GRAILDIR") "~/.grail") "/user/rcgrail.py")
"Location of Grail remote control client script `rcgrail.py'.
Typically found in $GRAILDIR/rcgrail.py, or ~/.grail/user/rcgrail.py.")
;;;###autoload
(defun browse-url-grail (url &optional new-window)
"Ask the Grail WWW browser to load URL.
Default to the URL around or before point. Runs the program in the
variable `browse-url-grail'."
(interactive (browse-url-interactive-arg "Grail URL: "))
(message "Sending URL to Grail...")
(save-excursion
(set-buffer (get-buffer-create " *Shell Command Output*"))
(erase-buffer)
;; don't worry about this failing.
(if new-window
(call-process browse-url-grail nil 0 nil "-b" url)
(call-process browse-url-grail nil 0 nil url))
(message "Sending URL to Grail... done")))
;; --- Mosaic using CCI ---
;;;###autoload
(defun browse-url-cci (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point.
This function only works for XMosaic version 2.5 or later. You must
select `CCI' from XMosaic's File menu, set the CCI Port Address to the
value of variable `browse-url-CCI-port', and enable `Accept requests'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new browser 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 "Mosaic URL: "))
(open-network-stream "browse-url" " *browse-url*"
browse-url-CCI-host browse-url-CCI-port)
;; Todo: start browser if fails
(process-send-string "browse-url"
(concat "get url (" url ") output "
(if (browse-url-maybe-new-window new-window)
"new"
"current")
"\r\n"))
(process-send-string "browse-url" "disconnect\r\n")
(delete-process "browse-url"))
;; --- IXI Mosaic ---
;;;###autoload
(defun browse-url-iximosaic (url &optional new-window)
;; new-window ignored
"Ask the IXIMosaic WWW browser to load URL.
Default to the URL around or before point."
(interactive (browse-url-interactive-arg "IXI Mosaic URL: "))
(start-process "tellw3b" nil "tellw3b"
"-service WWW_BROWSER ixi_showurl " url))
;; --- W3 ---
;;;###autoload
(defun browse-url-w3 (url &optional new-window)
"Ask the w3 WWW browser to load URL.
Default to the URL around or before point.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new window. 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 "W3 URL: "))
(require 'w3) ; w3-fetch-other-window not autoloaded
(if (browse-url-maybe-new-window new-window)
(w3-fetch-other-window url)
(w3-fetch url)))
;;;###autoload
(defun browse-url-w3-gnudoit (url &optional new-window)
;; new-window ignored
"Ask another Emacs running gnuserv to load the URL using the W3 browser.
The `browse-url-gnudoit-program' program is used with options given by
`browse-url-gnudoit-args'. Default to the URL around or before point."
(interactive (browse-url-interactive-arg "W3 URL: "))
(apply 'start-process (concat "gnudoit:" url) nil
browse-url-gnudoit-program
(append browse-url-gnudoit-args
(list (concat "(w3-fetch \"" url "\")")
"(raise-frame)"))))
;; --- Lynx in an xterm ---
;;;###autoload
(defun browse-url-lynx-xterm (url &optional new-window)
;; new-window ignored
"Ask the Lynx WWW browser to load URL.
Default to the URL around or before point. A new Lynx process is run
in an Xterm window using the Xterm program named by `browse-url-xterm-program'
with possible additional arguments `browse-url-xterm-args'."
(interactive (browse-url-interactive-arg "Lynx URL: "))
(apply #'start-process `(,(concat "lynx" url) nil ,browse-url-xterm-program
,@browse-url-xterm-args "-e" "lynx"
,url)))
;; --- Lynx in an Emacs "term" window ---
;;;###autoload
(defun browse-url-lynx-emacs (url &optional new-buffer)
"Ask the Lynx WWW browser to load URL.
Default to the URL around or before point. With a prefix argument, run
a new Lynx process in a new buffer.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new lynx in a new term window,
otherwise use any 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 "Lynx URL: "))
(let* ((system-uses-terminfo t) ; Lynx uses terminfo
;; (term-term-name "vt100") ; ??
(buf (get-buffer "*lynx*"))
(proc (and buf (get-buffer-process buf)))
(n browse-url-lynx-input-attempts))
(if (and (browse-url-maybe-new-window new-buffer) buf)
;; Rename away the OLD buffer. This isn't very polite, but
;; term insists on working in a buffer named *lynx* and would
;; choke on *lynx*<1>
(progn (set-buffer buf)
(rename-uniquely)))
(if (or (browse-url-maybe-new-window new-buffer)
(not buf)
(not proc)
(not (memq (process-status proc) '(run stop))))
;; start a new lynx
(progn
(setq buf
(apply #'make-term
`("lynx" "lynx" nil ,@browse-url-lynx-emacs-args
,url)))
(switch-to-buffer buf)
(term-char-mode)
(set-process-sentinel
(get-buffer-process buf)
;; Don't leave around a dead one (especially because of its
;; munged keymap.)
(lambda (process event)
(if (not (memq (process-status process) '(run stop)))
(let ((buf (process-buffer process)))
(if buf (kill-buffer buf)))))))
;; send the url to lynx in the old buffer
(let ((win (get-buffer-window buf t)))
(if win
(select-window win)
(switch-to-buffer buf)))
(if (eq (following-char) ?_)
(cond ((eq browse-url-lynx-input-field 'warn)
(error "Please move out of the input field first"))
((eq browse-url-lynx-input-field 'avoid)
(while (and (eq (following-char) ?_) (> n 0))
(term-send-down) ; down arrow
(sit-for browse-url-lynx-input-delay))
(if (eq (following-char) ?_)
(error "Cannot move out of the input field, sorry")))))
(term-send-string proc (concat "g" ; goto
"\C-u" ; kill default url
url
"\r")))))
;; --- MMM ---
;;;###autoload
(defun browse-url-mmm (url &optional new-window)
"Ask the MMM WWW browser to load URL.
Default to the URL around or before point."
(interactive (browse-url-interactive-arg "MMM URL: "))
(message "Sending URL to MMM...")
(save-excursion
(set-buffer (get-buffer-create " *Shell Command Output*"))
(erase-buffer)
;; mmm_remote just SEGVs if the file isn't there...
(if (or (file-exists-p (expand-file-name "~/.mmm_remote"))
;; location in v 0.4:
(file-exists-p (expand-file-name "~/.mmm/remote")))
(call-process "mmm_remote" nil 0 nil url)
(call-process "mmm" nil 0 nil "-external" url))
(message "Sending URL to MMM... done")))
;; --- mailto ---
;;;###autoload
(defun browse-url-mail (url &optional new-window)
"Open a new mail message buffer within Emacs.
Default to using the mailto: URL around or before point as the
recipient's address. Supplying a non-nil interactive prefix argument
will cause the mail to be composed in another window rather than the
current one.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil use `compose-mail-other-window', otherwise `compose-mail'. 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 "Mailto URL: "))
(save-excursion
(let ((to (if (string-match "^mailto:" url)
(substring url 7)
url)))
(if (browse-url-maybe-new-window new-window)
(compose-mail-other-window to nil nil nil
(list 'insert-buffer (current-buffer)))
(compose-mail to nil nil nil nil
(list 'insert-buffer (current-buffer)))))))
;; --- Random browser ---
;;;###autoload
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load URL.
Default to the URL around or before point. A fresh copy of the
browser is started up in a new process with possible additional arguments
`browse-url-generic-args'. This is appropriate for browsers which
don't offer a form of remote control."
(interactive (browse-url-interactive-arg "URL: "))
(if (not browse-url-generic-program)
(error "No browser defined (`browse-url-generic-program')"))
(apply 'start-process (concat browse-url-generic-program url) nil
browse-url-generic-program
(append browse-url-generic-args (list url))))
;;;###autoload
(defun browse-url-kde (url &optional new-window)
"Ask the KDE WWW browser to load URL.
Default to the URL around or before point."
(interactive (browse-url-interactive-arg "KDE URL: "))
(message "Sending URL to KDE...")
(apply #'start-process `(,(concat "KDE" url) nil ,browse-url-kde-program
,@browse-url-kde-args ,url)))
(defcustom browse-url-opera-program "opera"
"*The name by which to invoke Opera."
:type 'string
:group 'browse-url)
(defcustom browse-url-opera-arguments '()
"*A list of strings to pass to Opera as arguments."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-opera-startup-arguments browse-url-opera-arguments
"*A list of strings to pass to Opera when it starts up.
Defaults to the value of `browse-url-opera-arguments' at the time
`browse-url' is loaded."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defun browse-url-opera (url &optional new-window)
"Ask the Opera WWW browser to load URL.
Default to the URL around or before point. The strings in variable
`browse-url-opera-arguments' are also passed to Opera.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new Opera window, otherwise use an
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 "opera " url) nil
browse-url-opera-program
(append
browse-url-opera-arguments
(list "-remote"
(concat "openURL("
url
(if new-window ",new-window")
")"))))))
(set-process-sentinel process
`(lambda (process change)
(browse-url-opera-sentinel process ,url)))))
(defun browse-url-opera-sentinel (process url)
"Handle a change to the process communicating with Opera."
(or (eq (process-exit-status process) 0)
(let* ((process-environment (browse-url-process-environment)))
;; Opera is not running - start it
(message "Starting Opera...")
(apply 'start-process (concat "opera " url) nil
browse-url-opera-program
(append browse-url-opera-startup-arguments (list url))))))
(provide 'browse-url)
;;; browse-url.el ends here
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2004-02-05 16:09 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.693.1074172442.928.bug-gnu-emacs@gnu.org>
2004-01-15 13:48 ` [Reuben Thomas] browse-url.el Opera support Simon Josefsson
2004-01-15 14:12 ` Reuben Thomas
2004-01-15 14:28 ` Simon Josefsson
2004-01-16 19:54 ` Richard Stallman
2004-01-17 15:15 ` Reuben Thomas
2004-01-18 6:32 ` Simon Josefsson
2004-01-18 7:15 ` Reuben Thomas
2004-01-18 22:27 ` Reuben Thomas
2004-01-19 20:12 ` Richard Stallman
2004-01-19 18:35 ` Reuben Thomas
2004-01-19 18:38 ` Reuben Thomas
2004-02-05 15:44 ` Dave Love
2004-02-05 16:09 ` Reuben Thomas
2004-01-18 19:14 ` Richard Stallman
[not found] ` <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>
2004-01-17 20:43 ` David Kastrup
[not found] ` <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>
2004-01-16 21:43 ` David Kastrup
2004-01-17 12:53 ` Richard Stallman
2004-01-17 0:16 ` Dave Love
2004-01-17 15:27 ` Reuben Thomas
[not found] ` <mailman.716.1074194876.928.bug-gnu-emacs@gnu.org>
2004-01-15 22:32 ` Kevin Rodgers
2004-01-15 12:12 Dave Love
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).