browse-url.el 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. ;;; browse-url.el --- pass a URL to a WWW browser
  2. ;; Copyright (C) 1995-2012 Free Software Foundation, Inc.
  3. ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
  4. ;; Maintainer: FSF
  5. ;; Created: 03 Apr 1995
  6. ;; Keywords: hypertext, hypermedia, mouse
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This package provides functions which read a URL (Uniform Resource
  20. ;; Locator) from the minibuffer, defaulting to the URL around point,
  21. ;; and ask a World-Wide Web browser to load it. It can also load the
  22. ;; URL associated with the current buffer. Different browsers use
  23. ;; different methods of remote control so there is one function for
  24. ;; each supported browser. If the chosen browser is not running, it
  25. ;; is started. Currently there is support for the following browsers,
  26. ;; some of them probably now obsolete:
  27. ;; Function Browser Earliest version
  28. ;; browse-url-mozilla Mozilla Don't know
  29. ;; browse-url-firefox Firefox Don't know (tried with 1.0.1)
  30. ;; browse-url-chromium Chromium 3.0
  31. ;; browse-url-galeon Galeon Don't know
  32. ;; browse-url-epiphany Epiphany Don't know
  33. ;; browse-url-netscape Netscape 1.1b1
  34. ;; browse-url-mosaic XMosaic/mMosaic <= 2.4
  35. ;; browse-url-cci XMosaic 2.5
  36. ;; browse-url-w3 w3 0
  37. ;; browse-url-w3-gnudoit w3 remotely
  38. ;; browse-url-text-* Any text browser 0
  39. ;; browse-url-generic arbitrary
  40. ;; browse-url-default-windows-browser MS-Windows browser
  41. ;; browse-url-default-macosx-browser Mac OS X browser
  42. ;; browse-url-xdg-open Free Desktop xdg-open on Gnome, KDE, Xfce4, LXDE
  43. ;; browse-url-gnome-moz GNOME interface to Mozilla
  44. ;; browse-url-kde KDE konqueror (kfm)
  45. ;; browse-url-elinks Elinks Don't know (tried with 0.12.GIT)
  46. ;; [A version of the Netscape browser is now free software
  47. ;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is
  48. ;; reasonable to have that as the default.]
  49. ;; Note that versions of Netscape before 1.1b1 did not have remote
  50. ;; control. <URL:http://www.netscape.com/newsref/std/x-remote.html>.
  51. ;; Browsers can cache Web pages so it may be necessary to tell them to
  52. ;; reload the current page if it has changed (e.g. if you have edited
  53. ;; it). There is currently no perfect automatic solution to this.
  54. ;; Netscape allows you to specify the id of the window you want to
  55. ;; control but which window DO you want to control and how do you
  56. ;; discover its id?
  57. ;; William M. Perry's excellent "w3" WWW browser for
  58. ;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
  59. ;; has a function w3-follow-url-at-point, but that
  60. ;; doesn't let you edit the URL like browse-url.
  61. ;; The `gnuserv' package that can be used to control it in another
  62. ;; Emacs process is available from
  63. ;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
  64. ;; Lynx is now distributed by the FSF. See also
  65. ;; <URL:http://lynx.browser.org/>.
  66. ;; Free graphical browsers that could be used by `browse-url-generic'
  67. ;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and
  68. ;; <URL:http://www.unlv.edu/chimera/>, Arena
  69. ;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena> and Amaya
  70. ;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic
  71. ;; <URL:ftp://ftp.enst.fr/pub/mbone/mMosaic/>,
  72. ;; <URL:http://www.enst.fr/~dauphin/mMosaic/> (with development
  73. ;; support for Java applets and multicast) can be used like Mosaic by
  74. ;; setting `browse-url-mosaic-program' appropriately.
  75. ;; I [Denis Howe, not Dave Love] recommend Nelson Minar
  76. ;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing
  77. ;; HTML and thank Nelson for his many useful comments on this code.
  78. ;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
  79. ;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/
  80. ;; software/own/hm--html-menus/>. For composing correct HTML see also
  81. ;; PSGML the general SGML structure editor package
  82. ;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
  83. ;; with this.
  84. ;; This package generalizes function html-previewer-process in Marc
  85. ;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the
  86. ;; ffap.el package. The huge hyperbole package also contains similar
  87. ;; functions.
  88. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  89. ;; Help!
  90. ;; Can you write and test some code for the Macintrash and Windoze
  91. ;; Netscape remote control APIs? (See the URL above).
  92. ;; Do any other browsers have remote control?
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ;; Usage
  95. ;; To display the URL at or before point:
  96. ;; M-x browse-url-at-point RET
  97. ;; or, similarly but with the opportunity to edit the URL extracted from
  98. ;; the buffer, use:
  99. ;; M-x browse-url
  100. ;; To display a URL by shift-clicking on it, put this in your ~/.emacs
  101. ;; file:
  102. ;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
  103. ;; (Note that using Shift-mouse-1 is not desirable because
  104. ;; that event has a standard meaning in Emacs.)
  105. ;; To display the current buffer in a web browser:
  106. ;; M-x browse-url-of-buffer RET
  107. ;; To display the current region in a web browser:
  108. ;; M-x browse-url-of-region RET
  109. ;; In Dired, to display the file named on the current line:
  110. ;; M-x browse-url-of-dired-file RET
  111. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  112. ;; Customization (~/.emacs)
  113. ;; To see what variables are available for customization, type
  114. ;; `M-x set-variable browse-url TAB'. Better, use
  115. ;; `M-x customize-group browse-url'.
  116. ;; Bind the browse-url commands to keys with the `C-c C-z' prefix
  117. ;; (as used by html-helper-mode):
  118. ;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
  119. ;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
  120. ;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
  121. ;; (global-set-key "\C-c\C-zu" 'browse-url)
  122. ;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
  123. ;; (add-hook 'dired-mode-hook
  124. ;; (lambda ()
  125. ;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file)))
  126. ;; Browse URLs in mail messages under RMAIL by clicking mouse-2:
  127. ;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
  128. ;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
  129. ;; Alternatively, add `goto-address' to `rmail-show-message-hook'.
  130. ;; Gnus provides a standard feature to activate URLs in article
  131. ;; buffers for invocation of browse-url.
  132. ;; Use the Emacs w3 browser when not running under X11:
  133. ;; (or (eq window-system 'x)
  134. ;; (setq browse-url-browser-function 'browse-url-w3))
  135. ;; To always save modified buffers before displaying the file in a browser:
  136. ;; (setq browse-url-save-file t)
  137. ;; To get round the Netscape caching problem, you could EITHER have
  138. ;; write-file in html-helper-mode make Netscape reload the document:
  139. ;;
  140. ;; (autoload 'browse-url-netscape-reload "browse-url"
  141. ;; "Ask a WWW browser to redisplay the current file." t)
  142. ;; (add-hook 'html-helper-mode-hook
  143. ;; (lambda ()
  144. ;; (add-hook 'local-write-file-hooks
  145. ;; (lambda ()
  146. ;; (let ((local-write-file-hooks))
  147. ;; (save-buffer))
  148. ;; (browse-url-netscape-reload)
  149. ;; t) ; => file written by hook
  150. ;; t))) ; append to l-w-f-hooks
  151. ;;
  152. ;; OR have browse-url-of-file ask Netscape to load and then reload the
  153. ;; file:
  154. ;;
  155. ;; (add-hook 'browse-url-of-file-hook 'browse-url-netscape-reload)
  156. ;; You may also want to customize browse-url-netscape-arguments, e.g.
  157. ;; (setq browse-url-netscape-arguments '("-install"))
  158. ;;
  159. ;; or similarly for the other browsers.
  160. ;; To invoke different browsers for different URLs:
  161. ;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
  162. ;; ("." . browse-url-netscape)))
  163. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  164. ;;; Code:
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ;; Variables
  167. (eval-when-compile (require 'cl))
  168. (defgroup browse-url nil
  169. "Use a web browser to look at a URL."
  170. :prefix "browse-url-"
  171. :link '(emacs-commentary-link "browse-url")
  172. :group 'external
  173. :group 'comm)
  174. ;;;###autoload
  175. (defcustom browse-url-browser-function
  176. 'browse-url-default-browser
  177. "Function to display the current buffer in a WWW browser.
  178. This is used by the `browse-url-at-point', `browse-url-at-mouse', and
  179. `browse-url-of-file' commands.
  180. If the value is not a function it should be a list of pairs
  181. \(REGEXP . FUNCTION). In this case the function called will be the one
  182. associated with the first REGEXP which matches the current URL. The
  183. function is passed the URL and any other args of `browse-url'. The last
  184. regexp should probably be \".\" to specify a default browser."
  185. :type '(choice
  186. (function-item :tag "Emacs W3" :value browse-url-w3)
  187. (function-item :tag "W3 in another Emacs via `gnudoit'"
  188. :value browse-url-w3-gnudoit)
  189. (function-item :tag "Mozilla" :value browse-url-mozilla)
  190. (function-item :tag "Firefox" :value browse-url-firefox)
  191. (function-item :tag "Chromium" :value browse-url-chromium)
  192. (function-item :tag "Galeon" :value browse-url-galeon)
  193. (function-item :tag "Epiphany" :value browse-url-epiphany)
  194. (function-item :tag "Netscape" :value browse-url-netscape)
  195. (function-item :tag "Mosaic" :value browse-url-mosaic)
  196. (function-item :tag "Mosaic using CCI" :value browse-url-cci)
  197. (function-item :tag "Text browser in an xterm window"
  198. :value browse-url-text-xterm)
  199. (function-item :tag "Text browser in an Emacs window"
  200. :value browse-url-text-emacs)
  201. (function-item :tag "KDE" :value browse-url-kde)
  202. (function-item :tag "Elinks" :value browse-url-elinks)
  203. (function-item :tag "Specified by `Browse Url Generic Program'"
  204. :value browse-url-generic)
  205. (function-item :tag "Default Windows browser"
  206. :value browse-url-default-windows-browser)
  207. (function-item :tag "Default Mac OS X browser"
  208. :value browse-url-default-macosx-browser)
  209. (function-item :tag "GNOME invoking Mozilla"
  210. :value browse-url-gnome-moz)
  211. (function-item :tag "Default browser"
  212. :value browse-url-default-browser)
  213. (function :tag "Your own function")
  214. (alist :tag "Regexp/function association list"
  215. :key-type regexp :value-type function))
  216. :version "24.1"
  217. :group 'browse-url)
  218. (defcustom browse-url-mailto-function 'browse-url-mail
  219. "Function to display mailto: links.
  220. This variable uses the same syntax as the
  221. `browse-url-browser-function' variable. If the
  222. `browse-url-mailto-function' variable is nil, that variable will
  223. be used instead."
  224. :type '(choice
  225. (function-item :tag "Emacs Mail" :value browse-url-mail)
  226. (function-item :tag "None" nil))
  227. :version "24.1"
  228. :group 'browse-url)
  229. (defcustom browse-url-netscape-program "netscape"
  230. ;; Info about netscape-remote from Karl Berry.
  231. "The name by which to invoke Netscape.
  232. The free program `netscape-remote' from
  233. <URL:http://home.netscape.com/newsref/std/remote.c> is said to start
  234. up very much quicker than `netscape'. Reported to compile on a GNU
  235. system, given vroot.h from the same directory, with cc flags
  236. -DSTANDALONE -L/usr/X11R6/lib -lXmu -lX11."
  237. :type 'string
  238. :group 'browse-url)
  239. (defcustom browse-url-netscape-arguments nil
  240. "A list of strings to pass to Netscape as arguments."
  241. :type '(repeat (string :tag "Argument"))
  242. :group 'browse-url)
  243. (defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments
  244. "A list of strings to pass to Netscape when it starts up.
  245. Defaults to the value of `browse-url-netscape-arguments' at the time
  246. `browse-url' is loaded."
  247. :type '(repeat (string :tag "Argument"))
  248. :group 'browse-url)
  249. (defcustom browse-url-browser-display nil
  250. "The X display for running the browser, if not same as Emacs's."
  251. :type '(choice string (const :tag "Default" nil))
  252. :group 'browse-url)
  253. (defcustom browse-url-mozilla-program "mozilla"
  254. "The name by which to invoke Mozilla."
  255. :type 'string
  256. :group 'browse-url)
  257. (defcustom browse-url-mozilla-arguments nil
  258. "A list of strings to pass to Mozilla as arguments."
  259. :type '(repeat (string :tag "Argument"))
  260. :group 'browse-url)
  261. (defcustom browse-url-mozilla-startup-arguments browse-url-mozilla-arguments
  262. "A list of strings to pass to Mozilla when it starts up.
  263. Defaults to the value of `browse-url-mozilla-arguments' at the time
  264. `browse-url' is loaded."
  265. :type '(repeat (string :tag "Argument"))
  266. :group 'browse-url)
  267. (defcustom browse-url-firefox-program
  268. (let ((candidates '("firefox" "iceweasel" "icecat")))
  269. (while (and candidates (not (executable-find (car candidates))))
  270. (setq candidates (cdr candidates)))
  271. (or (car candidates) "firefox"))
  272. "The name by which to invoke Firefox."
  273. :type 'string
  274. :group 'browse-url)
  275. (defcustom browse-url-firefox-arguments nil
  276. "A list of strings to pass to Firefox as arguments."
  277. :type '(repeat (string :tag "Argument"))
  278. :group 'browse-url)
  279. (defcustom browse-url-firefox-startup-arguments browse-url-firefox-arguments
  280. "A list of strings to pass to Firefox when it starts up.
  281. Defaults to the value of `browse-url-firefox-arguments' at the time
  282. `browse-url' is loaded."
  283. :type '(repeat (string :tag "Argument"))
  284. :group 'browse-url)
  285. (defcustom browse-url-chromium-program
  286. (let ((candidates '("chromium" "chromium-browser")))
  287. (while (and candidates (not (executable-find (car candidates))))
  288. (setq candidates (cdr candidates)))
  289. (or (car candidates) "chromium"))
  290. "The name by which to invoke Chromium."
  291. :type 'string
  292. :version "24.1"
  293. :group 'browse-url)
  294. (defcustom browse-url-chromium-arguments nil
  295. "A list of strings to pass to Chromium as arguments."
  296. :type '(repeat (string :tag "Argument"))
  297. :version "24.1"
  298. :group 'browse-url)
  299. (defcustom browse-url-galeon-program "galeon"
  300. "The name by which to invoke Galeon."
  301. :type 'string
  302. :group 'browse-url)
  303. (defcustom browse-url-galeon-arguments nil
  304. "A list of strings to pass to Galeon as arguments."
  305. :type '(repeat (string :tag "Argument"))
  306. :group 'browse-url)
  307. (defcustom browse-url-galeon-startup-arguments browse-url-galeon-arguments
  308. "A list of strings to pass to Galeon when it starts up.
  309. Defaults to the value of `browse-url-galeon-arguments' at the time
  310. `browse-url' is loaded."
  311. :type '(repeat (string :tag "Argument"))
  312. :group 'browse-url)
  313. (defcustom browse-url-epiphany-program "epiphany"
  314. "The name by which to invoke Epiphany."
  315. :type 'string
  316. :group 'browse-url)
  317. (defcustom browse-url-epiphany-arguments nil
  318. "A list of strings to pass to Epiphany as arguments."
  319. :type '(repeat (string :tag "Argument"))
  320. :group 'browse-url)
  321. (defcustom browse-url-epiphany-startup-arguments browse-url-epiphany-arguments
  322. "A list of strings to pass to Epiphany when it starts up.
  323. Defaults to the value of `browse-url-epiphany-arguments' at the time
  324. `browse-url' is loaded."
  325. :type '(repeat (string :tag "Argument"))
  326. :group 'browse-url)
  327. ;; GNOME means of invoking either Mozilla or Netscape.
  328. (defvar browse-url-gnome-moz-program "gnome-moz-remote")
  329. (defcustom browse-url-gnome-moz-arguments '()
  330. "A list of strings passed to the GNOME mozilla viewer as arguments."
  331. :version "21.1"
  332. :type '(repeat (string :tag "Argument"))
  333. :group 'browse-url)
  334. (defcustom browse-url-mozilla-new-window-is-tab nil
  335. "Whether to open up new windows in a tab or a new window.
  336. If non-nil, then open the URL in a new tab rather than a new window if
  337. `browse-url-mozilla' is asked to open it in a new window."
  338. :type 'boolean
  339. :group 'browse-url)
  340. (defcustom browse-url-firefox-new-window-is-tab nil
  341. "Whether to open up new windows in a tab or a new window.
  342. If non-nil, then open the URL in a new tab rather than a new window if
  343. `browse-url-firefox' is asked to open it in a new window.
  344. This option is currently ignored on MS-Windows, since the necessary
  345. functionality is not available there."
  346. :type 'boolean
  347. :group 'browse-url)
  348. (defcustom browse-url-galeon-new-window-is-tab nil
  349. "Whether to open up new windows in a tab or a new window.
  350. If non-nil, then open the URL in a new tab rather than a new window if
  351. `browse-url-galeon' is asked to open it in a new window."
  352. :type 'boolean
  353. :group 'browse-url)
  354. (defcustom browse-url-epiphany-new-window-is-tab nil
  355. "Whether to open up new windows in a tab or a new window.
  356. If non-nil, then open the URL in a new tab rather than a new window if
  357. `browse-url-epiphany' is asked to open it in a new window."
  358. :type 'boolean
  359. :group 'browse-url)
  360. (defcustom browse-url-netscape-new-window-is-tab nil
  361. "Whether to open up new windows in a tab or a new window.
  362. If non-nil, then open the URL in a new tab rather than a new
  363. window if `browse-url-netscape' is asked to open it in a new
  364. window."
  365. :type 'boolean
  366. :group 'browse-url)
  367. (defcustom browse-url-new-window-flag nil
  368. "Non-nil means always open a new browser window with appropriate browsers.
  369. Passing an interactive argument to \\[browse-url], or specific browser
  370. commands reverses the effect of this variable. Requires Netscape version
  371. 1.1N or later or XMosaic version 2.5 or later if using those browsers."
  372. :type 'boolean
  373. :group 'browse-url)
  374. (defcustom browse-url-mosaic-program "xmosaic"
  375. "The name by which to invoke Mosaic (or mMosaic)."
  376. :type 'string
  377. :version "20.3"
  378. :group 'browse-url)
  379. (defcustom browse-url-mosaic-arguments nil
  380. "A list of strings to pass to Mosaic as arguments."
  381. :type '(repeat (string :tag "Argument"))
  382. :group 'browse-url)
  383. (defcustom browse-url-mosaic-pidfile "~/.mosaicpid"
  384. "The name of the pidfile created by Mosaic."
  385. :type 'string
  386. :group 'browse-url)
  387. (defcustom browse-url-filename-alist
  388. `(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/")
  389. ;; The above loses the username to avoid the browser prompting for
  390. ;; it in anonymous cases. If it's not anonymous the next regexp
  391. ;; applies.
  392. ("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
  393. ,@(if (memq system-type '(windows-nt ms-dos cygwin))
  394. '(("^\\([a-zA-Z]:\\)[\\/]" . "file:///\\1/")
  395. ("^[\\/][\\/]+" . "file://")))
  396. ("^/+" . "file:///"))
  397. "An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'.
  398. Any substring of a filename matching one of the REGEXPs is replaced by
  399. the corresponding STRING using `replace-match', not treating STRING
  400. literally. All pairs are applied in the order given. The default
  401. value converts ange-ftp/EFS-style file names into ftp URLs and prepends
  402. `file:' to any file name beginning with `/'.
  403. For example, adding to the default a specific translation of an ange-ftp
  404. address to an HTTP URL:
  405. (setq browse-url-filename-alist
  406. '((\"/webmaster@webserver:/home/www/html/\" .
  407. \"http://www.acme.co.uk/\")
  408. (\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\")
  409. (\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\")
  410. (\"^/+\" . \"file:/\")))"
  411. :type '(repeat (cons :format "%v"
  412. (regexp :tag "Regexp")
  413. (string :tag "Replacement")))
  414. :version "23.1"
  415. :group 'browse-url)
  416. (defcustom browse-url-save-file nil
  417. "If non-nil, save the buffer before displaying its file.
  418. Used by the `browse-url-of-file' command."
  419. :type 'boolean
  420. :group 'browse-url)
  421. (defcustom browse-url-of-file-hook nil
  422. "Run after `browse-url-of-file' has asked a browser to load a file.
  423. Set this to `browse-url-netscape-reload' to force Netscape to load the
  424. file rather than displaying a cached copy."
  425. :type 'hook
  426. :options '(browse-url-netscape-reload)
  427. :group 'browse-url)
  428. (defcustom browse-url-CCI-port 3003
  429. "Port to access XMosaic via CCI.
  430. This can be any number between 1024 and 65535 but must correspond to
  431. the value set in the browser."
  432. :type 'integer
  433. :group 'browse-url)
  434. (defcustom browse-url-CCI-host "localhost"
  435. "Host to access XMosaic via CCI.
  436. This should be the host name of the machine running XMosaic with CCI
  437. enabled. The port number should be set in `browse-url-CCI-port'."
  438. :type 'string
  439. :group 'browse-url)
  440. (defvar browse-url-temp-file-name nil)
  441. (make-variable-buffer-local 'browse-url-temp-file-name)
  442. (defcustom browse-url-xterm-program "xterm"
  443. "The name of the terminal emulator used by `browse-url-text-xterm'.
  444. This might, for instance, be a separate color version of xterm."
  445. :type 'string
  446. :group 'browse-url)
  447. (defcustom browse-url-xterm-args nil
  448. "A list of strings defining options for `browse-url-xterm-program'.
  449. These might set its size, for instance."
  450. :type '(repeat (string :tag "Argument"))
  451. :group 'browse-url)
  452. (defcustom browse-url-gnudoit-program "gnudoit"
  453. "The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
  454. :type 'string
  455. :group 'browse-url)
  456. (defcustom browse-url-gnudoit-args '("-q")
  457. "A list of strings defining options for `browse-url-gnudoit-program'.
  458. These might set the port, for instance."
  459. :type '(repeat (string :tag "Argument"))
  460. :group 'browse-url)
  461. (defcustom browse-url-generic-program nil
  462. "The name of the browser program used by `browse-url-generic'."
  463. :type '(choice string (const :tag "None" nil))
  464. :group 'browse-url)
  465. (defcustom browse-url-generic-args nil
  466. "A list of strings defining options for `browse-url-generic-program'."
  467. :type '(repeat (string :tag "Argument"))
  468. :group 'browse-url)
  469. (defcustom browse-url-temp-dir temporary-file-directory
  470. "The name of a directory for browse-url's temporary files.
  471. Such files are generated by functions like `browse-url-of-region'.
  472. You might want to set this to somewhere with restricted read permissions
  473. for privacy's sake."
  474. :type 'string
  475. :group 'browse-url)
  476. (defcustom browse-url-netscape-version 3
  477. "The version of Netscape you are using.
  478. This affects how URL reloading is done; the mechanism changed
  479. incompatibly at version 4."
  480. :type 'number
  481. :group 'browse-url)
  482. (defcustom browse-url-text-browser "lynx"
  483. "The name of the text browser to invoke."
  484. :type 'string
  485. :group 'browse-url
  486. :version "23.1")
  487. (defcustom browse-url-text-emacs-args (and (not window-system)
  488. '("-show_cursor"))
  489. "A list of strings defining options for a text browser in an Emacs buffer.
  490. The default is none in a window system, otherwise `-show_cursor' to
  491. indicate the position of the current link in the absence of
  492. highlighting, assuming the normal default for showing the cursor."
  493. :type '(repeat (string :tag "Argument"))
  494. :version "23.1"
  495. :group 'browse-url)
  496. (defcustom browse-url-text-input-field 'avoid
  497. "Action on selecting an existing text browser buffer at an input field.
  498. What to do when sending a new URL to an existing text browser buffer in Emacs
  499. if the browser cursor is on an input field (in which case the `g' command
  500. would be entered as data). Such fields are recognized by the
  501. underlines ____. Allowed values: nil: disregard it, `warn': warn the
  502. user and don't emit the URL, `avoid': try to avoid the field by moving
  503. down (this *won't* always work)."
  504. :type '(choice (const :tag "Move to try to avoid field" :value avoid)
  505. (const :tag "Disregard" :value nil)
  506. (const :tag "Warn, don't emit URL" :value warn))
  507. :version "23.1"
  508. :group 'browse-url)
  509. (defcustom browse-url-text-input-attempts 10
  510. "How many times to try to move down from a series of text browser input fields."
  511. :type 'integer
  512. :version "23.1"
  513. :group 'browse-url)
  514. (defcustom browse-url-text-input-delay 0.2
  515. "Seconds to wait for a text browser between moves down from an input field."
  516. :type 'number
  517. :version "23.1"
  518. :group 'browse-url)
  519. (defcustom browse-url-kde-program "kfmclient"
  520. "The name by which to invoke the KDE web browser."
  521. :type 'string
  522. :version "21.1"
  523. :group 'browse-url)
  524. (defcustom browse-url-kde-args '("openURL")
  525. "A list of strings defining options for `browse-url-kde-program'."
  526. :type '(repeat (string :tag "Argument"))
  527. :group 'browse-url)
  528. (defcustom browse-url-elinks-wrapper '("xterm" "-e")
  529. "Wrapper command prepended to the Elinks command-line."
  530. :type '(repeat (string :tag "Wrapper"))
  531. :group 'browse-url)
  532. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  533. ;; URL encoding
  534. (defun browse-url-url-encode-chars (text chars)
  535. "URL-encode the chars in TEXT that match CHARS.
  536. CHARS is a regexp-like character alternative (e.g., \"[)$]\")."
  537. (let ((encoded-text (copy-sequence text))
  538. (s 0))
  539. (while (setq s (string-match chars encoded-text s))
  540. (setq encoded-text
  541. (replace-match (format "%%%x"
  542. (string-to-char (match-string 0 encoded-text)))
  543. t t encoded-text)
  544. s (1+ s)))
  545. encoded-text))
  546. (defun browse-url-encode-url (url)
  547. "Escape annoying characters in URL.
  548. The annoying characters are those that can mislead a web browser
  549. regarding its parameter treatment."
  550. ;; FIXME: Is there an actual example of a web browser getting
  551. ;; confused? (This used to encode commas, but at least Firefox
  552. ;; handles commas correctly and doesn't accept encoded commas.)
  553. (browse-url-url-encode-chars url "[)$]"))
  554. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  555. ;; URL input
  556. (defun browse-url-url-at-point ()
  557. (let ((url (thing-at-point 'url)))
  558. (set-text-properties 0 (length url) nil url)
  559. url))
  560. ;; Having this as a separate function called by the browser-specific
  561. ;; functions allows them to be stand-alone commands, making it easier
  562. ;; to switch between browsers.
  563. (defun browse-url-interactive-arg (prompt)
  564. "Read a URL from the minibuffer, prompting with PROMPT.
  565. If `transient-mark-mode' is non-nil and the mark is active,
  566. it defaults to the current region, else to the URL at or before
  567. point. If invoked with a mouse button, it moves point to the
  568. position clicked before acting.
  569. This function returns a list (URL NEW-WINDOW-FLAG)
  570. for use in `interactive'."
  571. (let ((event (elt (this-command-keys) 0)))
  572. (and (listp event) (mouse-set-point event)))
  573. (list (read-string prompt (or (and transient-mark-mode mark-active
  574. ;; rfc2396 Appendix E.
  575. (replace-regexp-in-string
  576. "[\t\r\f\n ]+" ""
  577. (buffer-substring-no-properties
  578. (region-beginning) (region-end))))
  579. (browse-url-url-at-point)))
  580. (not (eq (null browse-url-new-window-flag)
  581. (null current-prefix-arg)))))
  582. ;; called-interactive-p needs to be called at a function's top-level, hence
  583. ;; this macro. We use that rather than interactive-p because
  584. ;; use in a keyboard macro should not change this behavior.
  585. (defmacro browse-url-maybe-new-window (arg)
  586. `(if (or noninteractive (not (called-interactively-p 'any)))
  587. ,arg
  588. browse-url-new-window-flag))
  589. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  590. ;; Browse current buffer
  591. ;;;###autoload
  592. (defun browse-url-of-file (&optional file)
  593. "Ask a WWW browser to display FILE.
  594. Display the current buffer's file if FILE is nil or if called
  595. interactively. Turn the filename into a URL with function
  596. `browse-url-file-url'. Pass the URL to a browser using the
  597. `browse-url' function then run `browse-url-of-file-hook'."
  598. (interactive)
  599. (or file
  600. (setq file (buffer-file-name))
  601. (error "Current buffer has no file"))
  602. (let ((buf (get-file-buffer file)))
  603. (if buf
  604. (with-current-buffer buf
  605. (cond ((not (buffer-modified-p)))
  606. (browse-url-save-file (save-buffer))
  607. (t (message "%s modified since last save" file))))))
  608. (browse-url (browse-url-file-url file))
  609. (run-hooks 'browse-url-of-file-hook))
  610. (defun browse-url-file-url (file)
  611. "Return the URL corresponding to FILE.
  612. Use variable `browse-url-filename-alist' to map filenames to URLs."
  613. ;; De-munge Cygwin filenames before passing them to Windows browser.
  614. (if (eq system-type 'cygwin)
  615. (let ((winfile (with-output-to-string
  616. (call-process "cygpath" nil standard-output
  617. nil "-m" file))))
  618. (setq file (substring winfile 0 -1))))
  619. (let ((coding (and (default-value 'enable-multibyte-characters)
  620. (or file-name-coding-system
  621. default-file-name-coding-system))))
  622. (if coding (setq file (encode-coding-string file coding))))
  623. (setq file (browse-url-url-encode-chars file "[*\"()',=;?% ]"))
  624. (dolist (map browse-url-filename-alist)
  625. (when (and map (string-match (car map) file))
  626. (setq file (replace-match (cdr map) t nil file))))
  627. file)
  628. ;;;###autoload
  629. (defun browse-url-of-buffer (&optional buffer)
  630. "Ask a WWW browser to display BUFFER.
  631. Display the current buffer if BUFFER is nil. Display only the
  632. currently visible part of BUFFER (from a temporary file) if buffer is
  633. narrowed."
  634. (interactive)
  635. (save-excursion
  636. (and buffer (set-buffer buffer))
  637. (let ((file-name
  638. ;; Ignore real name if restricted
  639. (and (= (- (point-max) (point-min)) (buffer-size))
  640. (or buffer-file-name
  641. (and (boundp 'dired-directory) dired-directory)))))
  642. (or file-name
  643. (progn
  644. (or browse-url-temp-file-name
  645. (setq browse-url-temp-file-name
  646. (convert-standard-filename
  647. (make-temp-file
  648. (expand-file-name "burl" browse-url-temp-dir)
  649. nil ".html"))))
  650. (setq file-name browse-url-temp-file-name)
  651. (write-region (point-min) (point-max) file-name nil 'no-message)))
  652. (browse-url-of-file file-name))))
  653. (defun browse-url-delete-temp-file (&optional temp-file-name)
  654. ;; Delete browse-url-temp-file-name from the file system
  655. ;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead
  656. (let ((file-name (or temp-file-name browse-url-temp-file-name)))
  657. (if (and file-name (file-exists-p file-name))
  658. (delete-file file-name))))
  659. (add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
  660. (declare-function dired-get-filename "dired"
  661. (&optional localp no-error-if-not-filep))
  662. ;;;###autoload
  663. (defun browse-url-of-dired-file ()
  664. "In Dired, ask a WWW browser to display the file named on this line."
  665. (interactive)
  666. (let ((tem (dired-get-filename t t)))
  667. (if tem
  668. (browse-url-of-file (expand-file-name tem))
  669. (error "No file on this line"))))
  670. ;;;###autoload
  671. (defun browse-url-of-region (min max)
  672. "Ask a WWW browser to display the current region."
  673. (interactive "r")
  674. (save-excursion
  675. (save-restriction
  676. (narrow-to-region min max)
  677. (browse-url-of-buffer))))
  678. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  679. ;; Browser-independent commands
  680. ;; A generic command to call the current browse-url-browser-function
  681. ;;;###autoload
  682. (defun browse-url (url &rest args)
  683. "Ask a WWW browser to load URL.
  684. Prompts for a URL, defaulting to the URL at or before point. Variable
  685. `browse-url-browser-function' says which browser to use.
  686. If the URL is a mailto: URL, consult `browse-url-mailto-function'
  687. first, if that exists."
  688. (interactive (browse-url-interactive-arg "URL: "))
  689. (unless (called-interactively-p 'interactive)
  690. (setq args (or args (list browse-url-new-window-flag))))
  691. (let ((process-environment (copy-sequence process-environment))
  692. (function (or (and (string-match "\\`mailto:" url)
  693. browse-url-mailto-function)
  694. browse-url-browser-function))
  695. ;; Ensure that `default-directory' exists and is readable (b#6077).
  696. (default-directory (if (and (file-directory-p default-directory)
  697. (file-readable-p default-directory))
  698. default-directory
  699. (expand-file-name "~/"))))
  700. ;; When connected to various displays, be careful to use the display of
  701. ;; the currently selected frame, rather than the original start display,
  702. ;; which may not even exist any more.
  703. (if (stringp (frame-parameter (selected-frame) 'display))
  704. (setenv "DISPLAY" (frame-parameter (selected-frame) 'display)))
  705. (if (and (consp function)
  706. (not (functionp function)))
  707. ;; The `function' can be an alist; look down it for first match
  708. ;; and apply the function (which might be a lambda).
  709. (catch 'done
  710. (dolist (bf function)
  711. (when (string-match (car bf) url)
  712. (apply (cdr bf) url args)
  713. (throw 'done t)))
  714. (error "No browse-url-browser-function matching URL %s"
  715. url))
  716. ;; Unbound symbols go down this leg, since void-function from
  717. ;; apply is clearer than wrong-type-argument from dolist.
  718. (apply function url args))))
  719. ;;;###autoload
  720. (defun browse-url-at-point (&optional arg)
  721. "Ask a WWW browser to load the URL at or before point.
  722. Doesn't let you edit the URL like `browse-url'. Variable
  723. `browse-url-browser-function' says which browser to use."
  724. (interactive "P")
  725. (let ((url (browse-url-url-at-point)))
  726. (if url
  727. (browse-url url (if arg
  728. (not browse-url-new-window-flag)
  729. browse-url-new-window-flag))
  730. (error "No URL found"))))
  731. ;;;###autoload
  732. (defun browse-url-at-mouse (event)
  733. "Ask a WWW browser to load a URL clicked with the mouse.
  734. The URL is the one around or before the position of the mouse click
  735. but point is not changed. Doesn't let you edit the URL like
  736. `browse-url'. Variable `browse-url-browser-function' says which browser
  737. to use."
  738. (interactive "e")
  739. (save-excursion
  740. (mouse-set-point event)
  741. ;; This handles browse-url-new-window-flag properly
  742. ;; when it gets no arg.
  743. (browse-url-at-point)))
  744. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  745. ;; Browser-specific commands
  746. ;; --- Default MS-Windows browser ---
  747. (defvar dos-windows-version)
  748. (declare-function w32-shell-execute "w32fns.c") ;; Defined in C.
  749. (defun browse-url-default-windows-browser (url &optional new-window)
  750. (interactive (browse-url-interactive-arg "URL: "))
  751. (cond ((eq system-type 'ms-dos)
  752. (if dos-windows-version
  753. (shell-command (concat "start " (shell-quote-argument url)))
  754. (error "Browsing URLs is not supported on this system")))
  755. ((eq system-type 'cygwin)
  756. (call-process "cygstart" nil nil nil url))
  757. (t (w32-shell-execute "open" url))))
  758. (defun browse-url-default-macosx-browser (url &optional new-window)
  759. (interactive (browse-url-interactive-arg "URL: "))
  760. (start-process (concat "open " url) nil "open" url))
  761. ;; --- Netscape ---
  762. (defun browse-url-process-environment ()
  763. "Set DISPLAY in the environment to the X display the browser will use.
  764. This is either the value of variable `browse-url-browser-display' if
  765. non-nil, or the same display as Emacs if different from the current
  766. environment, otherwise just use the current environment."
  767. (let ((display (or browse-url-browser-display (browse-url-emacs-display))))
  768. (if display
  769. (cons (concat "DISPLAY=" display) process-environment)
  770. process-environment)))
  771. (defun browse-url-emacs-display ()
  772. "Return the X display Emacs is running on.
  773. This is nil if the display is the same as the DISPLAY environment variable.
  774. Actually Emacs could be using several displays; this just returns the
  775. one showing the selected frame."
  776. (let ((display (cdr-safe (assq 'display (frame-parameters)))))
  777. (and (not (equal display (getenv "DISPLAY")))
  778. display)))
  779. (defun browse-url-default-browser (url &rest args)
  780. "Find a suitable browser and ask it to load URL.
  781. Default to the URL around or before point.
  782. When called interactively, if variable `browse-url-new-window-flag' is
  783. non-nil, load the document in a new window, if possible, otherwise use
  784. a random existing one. A non-nil interactive prefix argument reverses
  785. the effect of `browse-url-new-window-flag'.
  786. When called non-interactively, optional second argument NEW-WINDOW is
  787. used instead of `browse-url-new-window-flag'."
  788. (apply
  789. (cond
  790. ((memq system-type '(windows-nt ms-dos cygwin))
  791. 'browse-url-default-windows-browser)
  792. ((memq system-type '(darwin))
  793. 'browse-url-default-macosx-browser)
  794. ((browse-url-can-use-xdg-open) 'browse-url-xdg-open)
  795. ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz)
  796. ((executable-find browse-url-mozilla-program) 'browse-url-mozilla)
  797. ((executable-find browse-url-firefox-program) 'browse-url-firefox)
  798. ((executable-find browse-url-chromium-program) 'browse-url-chromium)
  799. ((executable-find browse-url-galeon-program) 'browse-url-galeon)
  800. ((executable-find browse-url-kde-program) 'browse-url-kde)
  801. ((executable-find browse-url-netscape-program) 'browse-url-netscape)
  802. ((executable-find browse-url-mosaic-program) 'browse-url-mosaic)
  803. ((executable-find browse-url-xterm-program) 'browse-url-text-xterm)
  804. ((locate-library "w3") 'browse-url-w3)
  805. (t
  806. (lambda (&rest ignore) (error "No usable browser found"))))
  807. url args))
  808. (defun browse-url-can-use-xdg-open ()
  809. "Return non-nil if the \"xdg-open\" program can be used.
  810. xdg-open is a desktop utility that calls your preferred web browser.
  811. This requires you to be running either Gnome, KDE, Xfce4 or LXDE."
  812. (and (getenv "DISPLAY")
  813. (executable-find "xdg-open")
  814. ;; xdg-open may call gnome-open and that does not wait for its child
  815. ;; to finish. This child may then be killed when the parent dies.
  816. ;; Use nohup to work around. See bug#7166, bug#8917, bug#9779 and
  817. ;; http://lists.gnu.org/archive/html/emacs-devel/2009-07/msg00279.html
  818. (executable-find "nohup")
  819. (or (getenv "GNOME_DESKTOP_SESSION_ID")
  820. ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
  821. (condition-case nil
  822. (eq 0 (call-process
  823. "dbus-send" nil nil nil
  824. "--dest=org.gnome.SessionManager"
  825. "--print-reply"
  826. "/org/gnome/SessionManager"
  827. "org.gnome.SessionManager.CanShutdown"))
  828. (error nil))
  829. (equal (getenv "KDE_FULL_SESSION") "true")
  830. (condition-case nil
  831. (eq 0 (call-process
  832. "/bin/sh" nil nil nil
  833. "-c"
  834. ;; FIXME use string-match rather than grep.
  835. "xprop -root _DT_SAVE_MODE|grep xfce4"))
  836. (error nil))
  837. (member (getenv "DESKTOP_SESSION") '("LXDE" "Lubuntu"))
  838. (equal (getenv "XDG_CURRENT_DESKTOP") "LXDE"))))
  839. ;;;###autoload
  840. (defun browse-url-xdg-open (url &optional ignored)
  841. "Pass the specified URL to the \"xdg-open\" command.
  842. xdg-open is a desktop utility that calls your preferred web browser.
  843. The optional argument IGNORED is not used."
  844. (interactive (browse-url-interactive-arg "URL: "))
  845. (call-process "xdg-open" nil 0 nil url))
  846. ;;;###autoload
  847. (defun browse-url-netscape (url &optional new-window)
  848. "Ask the Netscape WWW browser to load URL.
  849. Default to the URL around or before point. The strings in variable
  850. `browse-url-netscape-arguments' are also passed to Netscape.
  851. When called interactively, if variable `browse-url-new-window-flag' is
  852. non-nil, load the document in a new Netscape window, otherwise use a
  853. random existing one. A non-nil interactive prefix argument reverses
  854. the effect of `browse-url-new-window-flag'.
  855. If `browse-url-netscape-new-window-is-tab' is non-nil, then
  856. whenever a document would otherwise be loaded in a new window, it
  857. is loaded in a new tab in an existing window instead.
  858. When called non-interactively, optional second argument NEW-WINDOW is
  859. used instead of `browse-url-new-window-flag'."
  860. (interactive (browse-url-interactive-arg "URL: "))
  861. (setq url (browse-url-encode-url url))
  862. (let* ((process-environment (browse-url-process-environment))
  863. (process
  864. (apply 'start-process
  865. (concat "netscape " url) nil
  866. browse-url-netscape-program
  867. (append
  868. browse-url-netscape-arguments
  869. (if (eq window-system 'w32)
  870. (list url)
  871. (append
  872. (if new-window '("-noraise"))
  873. (list "-remote"
  874. (concat "openURL(" url
  875. (if (browse-url-maybe-new-window
  876. new-window)
  877. (if browse-url-netscape-new-window-is-tab
  878. ",new-tab"
  879. ",new-window"))
  880. ")"))))))))
  881. (set-process-sentinel process
  882. `(lambda (process change)
  883. (browse-url-netscape-sentinel process ,url)))))
  884. (defun browse-url-netscape-sentinel (process url)
  885. "Handle a change to the process communicating with Netscape."
  886. (or (eq (process-exit-status process) 0)
  887. (let* ((process-environment (browse-url-process-environment)))
  888. ;; Netscape not running - start it
  889. (message "Starting %s..." browse-url-netscape-program)
  890. (apply 'start-process (concat "netscape" url) nil
  891. browse-url-netscape-program
  892. (append browse-url-netscape-startup-arguments (list url))))))
  893. (defun browse-url-netscape-reload ()
  894. "Ask Netscape to reload its current document.
  895. How depends on `browse-url-netscape-version'."
  896. (interactive)
  897. ;; Backwards incompatibility reported by
  898. ;; <peter.kruse@psychologie.uni-regensburg.de>.
  899. (browse-url-netscape-send (if (>= browse-url-netscape-version 4)
  900. "xfeDoCommand(reload)"
  901. "reload")))
  902. (defun browse-url-netscape-send (command)
  903. "Send a remote control command to Netscape."
  904. (let* ((process-environment (browse-url-process-environment)))
  905. (apply 'start-process "netscape" nil
  906. browse-url-netscape-program
  907. (append browse-url-netscape-arguments
  908. (list "-remote" command)))))
  909. ;;;###autoload
  910. (defun browse-url-mozilla (url &optional new-window)
  911. "Ask the Mozilla WWW browser to load URL.
  912. Default to the URL around or before point. The strings in variable
  913. `browse-url-mozilla-arguments' are also passed to Mozilla.
  914. When called interactively, if variable `browse-url-new-window-flag' is
  915. non-nil, load the document in a new Mozilla window, otherwise use a
  916. random existing one. A non-nil interactive prefix argument reverses
  917. the effect of `browse-url-new-window-flag'.
  918. If `browse-url-mozilla-new-window-is-tab' is non-nil, then whenever a
  919. document would otherwise be loaded in a new window, it is loaded in a
  920. new tab in an existing window instead.
  921. When called non-interactively, optional second argument NEW-WINDOW is
  922. used instead of `browse-url-new-window-flag'."
  923. (interactive (browse-url-interactive-arg "URL: "))
  924. (setq url (browse-url-encode-url url))
  925. (let* ((process-environment (browse-url-process-environment))
  926. (process
  927. (apply 'start-process
  928. (concat "mozilla " url) nil
  929. browse-url-mozilla-program
  930. (append
  931. browse-url-mozilla-arguments
  932. (list "-remote"
  933. (concat "openURL("
  934. url
  935. (if (browse-url-maybe-new-window
  936. new-window)
  937. (if browse-url-mozilla-new-window-is-tab
  938. ",new-tab"
  939. ",new-window"))
  940. ")"))))))
  941. (set-process-sentinel process
  942. `(lambda (process change)
  943. (browse-url-mozilla-sentinel process ,url)))))
  944. (defun browse-url-mozilla-sentinel (process url)
  945. "Handle a change to the process communicating with Mozilla."
  946. (or (eq (process-exit-status process) 0)
  947. (let* ((process-environment (browse-url-process-environment)))
  948. ;; Mozilla is not running - start it
  949. (message "Starting %s..." browse-url-mozilla-program)
  950. (apply 'start-process (concat "mozilla " url) nil
  951. browse-url-mozilla-program
  952. (append browse-url-mozilla-startup-arguments (list url))))))
  953. ;;;###autoload
  954. (defun browse-url-firefox (url &optional new-window)
  955. "Ask the Firefox WWW browser to load URL.
  956. Default to the URL around or before point. The strings in
  957. variable `browse-url-firefox-arguments' are also passed to
  958. Firefox.
  959. When called interactively, if variable
  960. `browse-url-new-window-flag' is non-nil, load the document in a
  961. new Firefox window, otherwise use a random existing one. A
  962. non-nil interactive prefix argument reverses the effect of
  963. `browse-url-new-window-flag'.
  964. If `browse-url-firefox-new-window-is-tab' is non-nil, then
  965. whenever a document would otherwise be loaded in a new window, it
  966. is loaded in a new tab in an existing window instead.
  967. When called non-interactively, optional second argument
  968. NEW-WINDOW is used instead of `browse-url-new-window-flag'.
  969. On MS-Windows systems the optional `new-window' parameter is
  970. ignored. Firefox for Windows does not support the \"-remote\"
  971. command line parameter. Therefore, the
  972. `browse-url-new-window-flag' and `browse-url-firefox-new-window-is-tab'
  973. are ignored as well. Firefox on Windows will always open the requested
  974. URL in a new window."
  975. (interactive (browse-url-interactive-arg "URL: "))
  976. (setq url (browse-url-encode-url url))
  977. (let* ((process-environment (browse-url-process-environment))
  978. (use-remote
  979. (not (memq system-type '(windows-nt ms-dos))))
  980. (process
  981. (apply 'start-process
  982. (concat "firefox " url) nil
  983. browse-url-firefox-program
  984. (append
  985. browse-url-firefox-arguments
  986. (if use-remote
  987. (list "-remote"
  988. (concat
  989. "openURL("
  990. url
  991. (if (browse-url-maybe-new-window new-window)
  992. (if browse-url-firefox-new-window-is-tab
  993. ",new-tab"
  994. ",new-window"))
  995. ")"))
  996. (list url))))))
  997. ;; If we use -remote, the process exits with status code 2 if
  998. ;; Firefox is not already running. The sentinel runs firefox
  999. ;; directly if that happens.
  1000. (when use-remote
  1001. (set-process-sentinel process
  1002. `(lambda (process change)
  1003. (browse-url-firefox-sentinel process ,url))))))
  1004. (defun browse-url-firefox-sentinel (process url)
  1005. "Handle a change to the process communicating with Firefox."
  1006. (or (eq (process-exit-status process) 0)
  1007. (let* ((process-environment (browse-url-process-environment)))
  1008. ;; Firefox is not running - start it
  1009. (message "Starting Firefox...")
  1010. (apply 'start-process (concat "firefox " url) nil
  1011. browse-url-firefox-program
  1012. (append browse-url-firefox-startup-arguments (list url))))))
  1013. ;;;###autoload
  1014. (defun browse-url-chromium (url &optional new-window)
  1015. "Ask the Chromium WWW browser to load URL.
  1016. Default to the URL around or before point. The strings in
  1017. variable `browse-url-chromium-arguments' are also passed to
  1018. Chromium."
  1019. (interactive (browse-url-interactive-arg "URL: "))
  1020. (setq url (browse-url-encode-url url))
  1021. (let* ((process-environment (browse-url-process-environment)))
  1022. (apply 'start-process
  1023. (concat "chromium " url) nil
  1024. browse-url-chromium-program
  1025. (append
  1026. browse-url-chromium-arguments
  1027. (list url)))))
  1028. ;;;###autoload
  1029. (defun browse-url-galeon (url &optional new-window)
  1030. "Ask the Galeon WWW browser to load URL.
  1031. Default to the URL around or before point. The strings in variable
  1032. `browse-url-galeon-arguments' are also passed to Galeon.
  1033. When called interactively, if variable `browse-url-new-window-flag' is
  1034. non-nil, load the document in a new Galeon window, otherwise use a
  1035. random existing one. A non-nil interactive prefix argument reverses
  1036. the effect of `browse-url-new-window-flag'.
  1037. If `browse-url-galeon-new-window-is-tab' is non-nil, then whenever a
  1038. document would otherwise be loaded in a new window, it is loaded in a
  1039. new tab in an existing window instead.
  1040. When called non-interactively, optional second argument NEW-WINDOW is
  1041. used instead of `browse-url-new-window-flag'."
  1042. (interactive (browse-url-interactive-arg "URL: "))
  1043. (setq url (browse-url-encode-url url))
  1044. (let* ((process-environment (browse-url-process-environment))
  1045. (process (apply 'start-process
  1046. (concat "galeon " url)
  1047. nil
  1048. browse-url-galeon-program
  1049. (append
  1050. browse-url-galeon-arguments
  1051. (if (browse-url-maybe-new-window new-window)
  1052. (if browse-url-galeon-new-window-is-tab
  1053. '("--new-tab")
  1054. '("--new-window" "--noraise"))
  1055. '("--existing"))
  1056. (list url)))))
  1057. (set-process-sentinel process
  1058. `(lambda (process change)
  1059. (browse-url-galeon-sentinel process ,url)))))
  1060. (defun browse-url-galeon-sentinel (process url)
  1061. "Handle a change to the process communicating with Galeon."
  1062. (or (eq (process-exit-status process) 0)
  1063. (let* ((process-environment (browse-url-process-environment)))
  1064. ;; Galeon is not running - start it
  1065. (message "Starting %s..." browse-url-galeon-program)
  1066. (apply 'start-process (concat "galeon " url) nil
  1067. browse-url-galeon-program
  1068. (append browse-url-galeon-startup-arguments (list url))))))
  1069. (defun browse-url-epiphany (url &optional new-window)
  1070. "Ask the Epiphany WWW browser to load URL.
  1071. Default to the URL around or before point. The strings in variable
  1072. `browse-url-galeon-arguments' are also passed to Epiphany.
  1073. When called interactively, if variable `browse-url-new-window-flag' is
  1074. non-nil, load the document in a new Epiphany window, otherwise use a
  1075. random existing one. A non-nil interactive prefix argument reverses
  1076. the effect of `browse-url-new-window-flag'.
  1077. If `browse-url-epiphany-new-window-is-tab' is non-nil, then whenever a
  1078. document would otherwise be loaded in a new window, it is loaded in a
  1079. new tab in an existing window instead.
  1080. When called non-interactively, optional second argument NEW-WINDOW is
  1081. used instead of `browse-url-new-window-flag'."
  1082. (interactive (browse-url-interactive-arg "URL: "))
  1083. (setq url (browse-url-encode-url url))
  1084. (let* ((process-environment (browse-url-process-environment))
  1085. (process (apply 'start-process
  1086. (concat "epiphany " url)
  1087. nil
  1088. browse-url-epiphany-program
  1089. (append
  1090. browse-url-epiphany-arguments
  1091. (if (browse-url-maybe-new-window new-window)
  1092. (if browse-url-epiphany-new-window-is-tab
  1093. '("--new-tab")
  1094. '("--new-window" "--noraise"))
  1095. '("--existing"))
  1096. (list url)))))
  1097. (set-process-sentinel process
  1098. `(lambda (process change)
  1099. (browse-url-epiphany-sentinel process ,url)))))
  1100. (defun browse-url-epiphany-sentinel (process url)
  1101. "Handle a change to the process communicating with Epiphany."
  1102. (or (eq (process-exit-status process) 0)
  1103. (let* ((process-environment (browse-url-process-environment)))
  1104. ;; Epiphany is not running - start it
  1105. (message "Starting %s..." browse-url-epiphany-program)
  1106. (apply 'start-process (concat "epiphany " url) nil
  1107. browse-url-epiphany-program
  1108. (append browse-url-epiphany-startup-arguments (list url))))))
  1109. (defvar url-handler-regexp)
  1110. ;;;###autoload
  1111. (defun browse-url-emacs (url &optional new-window)
  1112. "Ask Emacs to load URL into a buffer and show it in another window."
  1113. (interactive (browse-url-interactive-arg "URL: "))
  1114. (require 'url-handlers)
  1115. (let ((file-name-handler-alist
  1116. (cons (cons url-handler-regexp 'url-file-handler)
  1117. file-name-handler-alist)))
  1118. ;; Ignore `new-window': with all other browsers the URL is always shown
  1119. ;; in another window than the current Emacs one since it's shown in
  1120. ;; another application's window.
  1121. ;; (if new-window (find-file-other-window url) (find-file url))
  1122. (find-file-other-window url)))
  1123. ;;;###autoload
  1124. (defun browse-url-gnome-moz (url &optional new-window)
  1125. "Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'.
  1126. Default to the URL around or before point. The strings in variable
  1127. `browse-url-gnome-moz-arguments' are also passed.
  1128. When called interactively, if variable `browse-url-new-window-flag' is
  1129. non-nil, load the document in a new browser window, otherwise use an
  1130. existing one. A non-nil interactive prefix argument reverses the
  1131. effect of `browse-url-new-window-flag'.
  1132. When called non-interactively, optional second argument NEW-WINDOW is
  1133. used instead of `browse-url-new-window-flag'."
  1134. (interactive (browse-url-interactive-arg "URL: "))
  1135. (apply 'start-process (concat "gnome-moz-remote " url)
  1136. nil
  1137. browse-url-gnome-moz-program
  1138. (append
  1139. browse-url-gnome-moz-arguments
  1140. (if (browse-url-maybe-new-window new-window)
  1141. '("--newwin"))
  1142. (list "--raise" url))))
  1143. ;; --- Mosaic ---
  1144. ;;;###autoload
  1145. (defun browse-url-mosaic (url &optional new-window)
  1146. "Ask the XMosaic WWW browser to load URL.
  1147. Default to the URL around or before point. The strings in variable
  1148. `browse-url-mosaic-arguments' are also passed to Mosaic and the
  1149. program is invoked according to the variable
  1150. `browse-url-mosaic-program'.
  1151. When called interactively, if variable `browse-url-new-window-flag' is
  1152. non-nil, load the document in a new Mosaic window, otherwise use a
  1153. random existing one. A non-nil interactive prefix argument reverses
  1154. the effect of `browse-url-new-window-flag'.
  1155. When called non-interactively, optional second argument NEW-WINDOW is
  1156. used instead of `browse-url-new-window-flag'."
  1157. (interactive (browse-url-interactive-arg "Mosaic URL: "))
  1158. (let ((pidfile (expand-file-name browse-url-mosaic-pidfile))
  1159. pid)
  1160. (if (file-readable-p pidfile)
  1161. (save-excursion
  1162. (find-file pidfile)
  1163. (goto-char (point-min))
  1164. (setq pid (read (current-buffer)))
  1165. (kill-buffer nil)))
  1166. (if (and pid (zerop (signal-process pid 0))) ; Mosaic running
  1167. (save-excursion
  1168. (find-file (format "/tmp/Mosaic.%d" pid))
  1169. (erase-buffer)
  1170. (insert (if (browse-url-maybe-new-window new-window)
  1171. "newwin\n"
  1172. "goto\n")
  1173. url "\n")
  1174. (save-buffer)
  1175. (kill-buffer nil)
  1176. ;; Send signal SIGUSR to Mosaic
  1177. (message "Signaling Mosaic...")
  1178. (signal-process pid 'SIGUSR1)
  1179. ;; Or you could try:
  1180. ;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
  1181. (message "Signaling Mosaic...done")
  1182. )
  1183. ;; Mosaic not running - start it
  1184. (message "Starting %s..." browse-url-mosaic-program)
  1185. (apply 'start-process "xmosaic" nil browse-url-mosaic-program
  1186. (append browse-url-mosaic-arguments (list url)))
  1187. (message "Starting %s...done" browse-url-mosaic-program))))
  1188. ;; --- Mosaic using CCI ---
  1189. ;;;###autoload
  1190. (defun browse-url-cci (url &optional new-window)
  1191. "Ask the XMosaic WWW browser to load URL.
  1192. Default to the URL around or before point.
  1193. This function only works for XMosaic version 2.5 or later. You must
  1194. select `CCI' from XMosaic's File menu, set the CCI Port Address to the
  1195. value of variable `browse-url-CCI-port', and enable `Accept requests'.
  1196. When called interactively, if variable `browse-url-new-window-flag' is
  1197. non-nil, load the document in a new browser window, otherwise use a
  1198. random existing one. A non-nil interactive prefix argument reverses
  1199. the effect of `browse-url-new-window-flag'.
  1200. When called non-interactively, optional second argument NEW-WINDOW is
  1201. used instead of `browse-url-new-window-flag'."
  1202. (interactive (browse-url-interactive-arg "Mosaic URL: "))
  1203. (open-network-stream "browse-url" " *browse-url*"
  1204. browse-url-CCI-host browse-url-CCI-port)
  1205. ;; Todo: start browser if fails
  1206. (process-send-string "browse-url"
  1207. (concat "get url (" url ") output "
  1208. (if (browse-url-maybe-new-window new-window)
  1209. "new"
  1210. "current")
  1211. "\r\n"))
  1212. (process-send-string "browse-url" "disconnect\r\n")
  1213. (delete-process "browse-url"))
  1214. ;; --- W3 ---
  1215. ;; External.
  1216. (declare-function w3-fetch-other-window "ext:w3m" (&optional url))
  1217. (declare-function w3-fetch "ext:w3m" (&optional url target))
  1218. ;;;###autoload
  1219. (defun browse-url-w3 (url &optional new-window)
  1220. "Ask the w3 WWW browser to load URL.
  1221. Default to the URL around or before point.
  1222. When called interactively, if variable `browse-url-new-window-flag' is
  1223. non-nil, load the document in a new window. A non-nil interactive
  1224. prefix argument reverses the effect of `browse-url-new-window-flag'.
  1225. When called non-interactively, optional second argument NEW-WINDOW is
  1226. used instead of `browse-url-new-window-flag'."
  1227. (interactive (browse-url-interactive-arg "W3 URL: "))
  1228. (require 'w3) ; w3-fetch-other-window not autoloaded
  1229. (if (browse-url-maybe-new-window new-window)
  1230. (w3-fetch-other-window url)
  1231. (w3-fetch url)))
  1232. ;;;###autoload
  1233. (defun browse-url-w3-gnudoit (url &optional new-window)
  1234. ;; new-window ignored
  1235. "Ask another Emacs running gnuserv to load the URL using the W3 browser.
  1236. The `browse-url-gnudoit-program' program is used with options given by
  1237. `browse-url-gnudoit-args'. Default to the URL around or before point."
  1238. (interactive (browse-url-interactive-arg "W3 URL: "))
  1239. (apply 'start-process (concat "gnudoit:" url) nil
  1240. browse-url-gnudoit-program
  1241. (append browse-url-gnudoit-args
  1242. (list (concat "(w3-fetch \"" url "\")")
  1243. "(raise-frame)"))))
  1244. ;; --- Lynx in an xterm ---
  1245. ;;;###autoload
  1246. (defun browse-url-text-xterm (url &optional new-window)
  1247. ;; new-window ignored
  1248. "Ask a text browser to load URL.
  1249. URL defaults to the URL around or before point.
  1250. This runs the text browser specified by `browse-url-text-browser'.
  1251. in an Xterm window using the Xterm program named by `browse-url-xterm-program'
  1252. with possible additional arguments `browse-url-xterm-args'."
  1253. (interactive (browse-url-interactive-arg "Text browser URL: "))
  1254. (apply #'start-process `(,(concat browse-url-text-browser url)
  1255. nil ,browse-url-xterm-program
  1256. ,@browse-url-xterm-args "-e" ,browse-url-text-browser
  1257. ,url)))
  1258. ;; --- Lynx in an Emacs "term" window ---
  1259. (declare-function term-char-mode "term" ())
  1260. (declare-function term-send-down "term" ())
  1261. (declare-function term-send-string "term" (proc str))
  1262. ;;;###autoload
  1263. (defun browse-url-text-emacs (url &optional new-buffer)
  1264. "Ask a text browser to load URL.
  1265. URL defaults to the URL around or before point.
  1266. This runs the text browser specified by `browse-url-text-browser'.
  1267. With a prefix argument, it runs a new browser process in a new buffer.
  1268. When called interactively, if variable `browse-url-new-window-flag' is
  1269. non-nil, load the document in a new browser process in a new term window,
  1270. otherwise use any existing one. A non-nil interactive prefix argument
  1271. reverses the effect of `browse-url-new-window-flag'.
  1272. When called non-interactively, optional second argument NEW-WINDOW is
  1273. used instead of `browse-url-new-window-flag'."
  1274. (interactive (browse-url-interactive-arg "Text browser URL: "))
  1275. (let* ((system-uses-terminfo t) ; Lynx uses terminfo
  1276. ;; (term-term-name "vt100") ; ??
  1277. (buf (get-buffer "*text browser*"))
  1278. (proc (and buf (get-buffer-process buf)))
  1279. (n browse-url-text-input-attempts))
  1280. (require 'term)
  1281. (if (and (browse-url-maybe-new-window new-buffer) buf)
  1282. ;; Rename away the OLD buffer. This isn't very polite, but
  1283. ;; term insists on working in a buffer named *lynx* and would
  1284. ;; choke on *lynx*<1>
  1285. (progn (set-buffer buf)
  1286. (rename-uniquely)))
  1287. (if (or (browse-url-maybe-new-window new-buffer)
  1288. (not buf)
  1289. (not proc)
  1290. (not (memq (process-status proc) '(run stop))))
  1291. ;; start a new text browser
  1292. (progn
  1293. (setq buf
  1294. (apply #'make-term
  1295. `(,browse-url-text-browser
  1296. ,browse-url-text-browser
  1297. nil ,@browse-url-text-emacs-args
  1298. ,url)))
  1299. (switch-to-buffer buf)
  1300. (term-char-mode)
  1301. (set-process-sentinel
  1302. (get-buffer-process buf)
  1303. ;; Don't leave around a dead one (especially because of its
  1304. ;; munged keymap.)
  1305. (lambda (process event)
  1306. (if (not (memq (process-status process) '(run stop)))
  1307. (let ((buf (process-buffer process)))
  1308. (if buf (kill-buffer buf)))))))
  1309. ;; Send the url to the text browser in the old buffer
  1310. (let ((win (get-buffer-window buf t)))
  1311. (if win
  1312. (select-window win)
  1313. (switch-to-buffer buf)))
  1314. (if (eq (following-char) ?_)
  1315. (cond ((eq browse-url-text-input-field 'warn)
  1316. (error "Please move out of the input field first"))
  1317. ((eq browse-url-text-input-field 'avoid)
  1318. (while (and (eq (following-char) ?_) (> n 0))
  1319. (term-send-down) ; down arrow
  1320. (sit-for browse-url-text-input-delay))
  1321. (if (eq (following-char) ?_)
  1322. (error "Cannot move out of the input field, sorry")))))
  1323. (term-send-string proc (concat "g" ; goto
  1324. "\C-u" ; kill default url
  1325. url
  1326. "\r")))))
  1327. ;; --- mailto ---
  1328. (autoload 'rfc2368-parse-mailto-url "rfc2368")
  1329. ;;;###autoload
  1330. (defun browse-url-mail (url &optional new-window)
  1331. "Open a new mail message buffer within Emacs for the RFC 2368 URL.
  1332. Default to using the mailto: URL around or before point as the
  1333. recipient's address. Supplying a non-nil interactive prefix argument
  1334. will cause the mail to be composed in another window rather than the
  1335. current one.
  1336. When called interactively, if variable `browse-url-new-window-flag' is
  1337. non-nil use `compose-mail-other-window', otherwise `compose-mail'. A
  1338. non-nil interactive prefix argument reverses the effect of
  1339. `browse-url-new-window-flag'.
  1340. When called non-interactively, optional second argument NEW-WINDOW is
  1341. used instead of `browse-url-new-window-flag'."
  1342. (interactive (browse-url-interactive-arg "Mailto URL: "))
  1343. (save-excursion
  1344. (let* ((alist (rfc2368-parse-mailto-url url))
  1345. (to (assoc "To" alist))
  1346. (subject (assoc "Subject" alist))
  1347. (body (assoc "Body" alist))
  1348. (rest (delq to (delq subject (delq body alist))))
  1349. (to (cdr to))
  1350. (subject (cdr subject))
  1351. (body (cdr body))
  1352. (mail-citation-hook (unless body mail-citation-hook)))
  1353. (if (browse-url-maybe-new-window new-window)
  1354. (compose-mail-other-window to subject rest nil
  1355. (list 'insert-buffer (current-buffer)))
  1356. (compose-mail to subject rest nil nil
  1357. (list 'insert-buffer (current-buffer))))
  1358. (when body
  1359. (goto-char (point-min))
  1360. (unless (or (search-forward (concat "\n" mail-header-separator "\n")
  1361. nil 'move)
  1362. (bolp))
  1363. (insert "\n"))
  1364. (goto-char (prog1
  1365. (point)
  1366. (insert (replace-regexp-in-string "\r\n" "\n" body))
  1367. (unless (bolp)
  1368. (insert "\n"))))))))
  1369. ;; --- Random browser ---
  1370. ;;;###autoload
  1371. (defun browse-url-generic (url &optional new-window)
  1372. ;; new-window ignored
  1373. "Ask the WWW browser defined by `browse-url-generic-program' to load URL.
  1374. Default to the URL around or before point. A fresh copy of the
  1375. browser is started up in a new process with possible additional arguments
  1376. `browse-url-generic-args'. This is appropriate for browsers which
  1377. don't offer a form of remote control."
  1378. (interactive (browse-url-interactive-arg "URL: "))
  1379. (if (not browse-url-generic-program)
  1380. (error "No browser defined (`browse-url-generic-program')"))
  1381. (apply 'call-process browse-url-generic-program nil
  1382. 0 nil
  1383. (append browse-url-generic-args (list url))))
  1384. ;;;###autoload
  1385. (defun browse-url-kde (url &optional new-window)
  1386. "Ask the KDE WWW browser to load URL.
  1387. Default to the URL around or before point."
  1388. (interactive (browse-url-interactive-arg "KDE URL: "))
  1389. (message "Sending URL to KDE...")
  1390. (apply #'start-process (concat "KDE " url) nil browse-url-kde-program
  1391. (append browse-url-kde-args (list url))))
  1392. (defun browse-url-elinks-new-window (url)
  1393. "Ask the Elinks WWW browser to load URL in a new window."
  1394. (let ((process-environment (browse-url-process-environment)))
  1395. (apply #'start-process
  1396. (append (list (concat "elinks:" url)
  1397. nil)
  1398. browse-url-elinks-wrapper
  1399. (list "elinks" url)))))
  1400. ;;;###autoload
  1401. (defun browse-url-elinks (url &optional new-window)
  1402. "Ask the Elinks WWW browser to load URL.
  1403. Default to the URL around the point.
  1404. The document is loaded in a new tab of a running Elinks or, if
  1405. none yet running, a newly started instance.
  1406. The Elinks command will be prepended by the program+arguments
  1407. from `browse-url-elinks-wrapper'."
  1408. (interactive (browse-url-interactive-arg "URL: "))
  1409. (setq url (browse-url-encode-url url))
  1410. (if new-window
  1411. (browse-url-elinks-new-window url)
  1412. (let ((process-environment (browse-url-process-environment))
  1413. (elinks-ping-process (start-process "elinks-ping" nil
  1414. "elinks" "-remote" "ping()")))
  1415. (set-process-sentinel elinks-ping-process
  1416. `(lambda (process change)
  1417. (browse-url-elinks-sentinel process ,url))))))
  1418. (defun browse-url-elinks-sentinel (process url)
  1419. "Determines if Elinks is running or a new one has to be started."
  1420. (let ((exit-status (process-exit-status process)))
  1421. ;; Try to determine if an instance is running or if we have to
  1422. ;; create a new one.
  1423. (case exit-status
  1424. (5
  1425. ;; No instance, start a new one.
  1426. (browse-url-elinks-new-window url))
  1427. (0
  1428. ;; Found an instance, open URL in new tab.
  1429. (let ((process-environment (browse-url-process-environment)))
  1430. (start-process (concat "elinks:" url) nil
  1431. "elinks" "-remote"
  1432. (concat "openURL(\"" url "\",new-tab)"))))
  1433. (otherwise
  1434. (error "Unrecognized exit-code %d of process `elinks'"
  1435. exit-status)))))
  1436. (provide 'browse-url)
  1437. ;;; browse-url.el ends here