comparison lisp/net/browse-url.el @ 84361:c05c0eff3e11

Johannes Weiner <hannes at saeurebad.de> (browse-url-browser-function): Add elinks. (browse-url-elinks-wrapper): New option. (browse-url-encode-url, browse-url-elinks) (browse-url-elinks-sentinel): New functions. (browse-url-file-url, browse-url-netscape, browse-url-mozilla) (browse-url-firefox, browse-url-galeon, browse-url-epiphany): Use new function browse-url-encode-url.
author Glenn Morris <rgm@gnu.org>
date Fri, 07 Sep 2007 04:37:01 +0000
parents 33d0b6780fb2
children f12fc8e7482c
comparison
equal deleted inserted replaced
84360:07d871329e5d 84361:c05c0eff3e11
53 ;; browse-url-generic arbitrary 53 ;; browse-url-generic arbitrary
54 ;; browse-url-default-windows-browser MS-Windows browser 54 ;; browse-url-default-windows-browser MS-Windows browser
55 ;; browse-url-default-macosx-browser Mac OS X browser 55 ;; browse-url-default-macosx-browser Mac OS X browser
56 ;; browse-url-gnome-moz GNOME interface to Mozilla 56 ;; browse-url-gnome-moz GNOME interface to Mozilla
57 ;; browse-url-kde KDE konqueror (kfm) 57 ;; browse-url-kde KDE konqueror (kfm)
58 ;; browse-url-elinks Elinks Don't know (tried with 0.12.GIT)
58 59
59 ;; [A version of the Netscape browser is now free software 60 ;; [A version of the Netscape browser is now free software
60 ;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is 61 ;; <URL:http://www.mozilla.org/>, albeit not GPLed, so it is
61 ;; reasonable to have that as the default.] 62 ;; reasonable to have that as the default.]
62 63
261 (function-item :tag "Lynx in an Emacs window" 262 (function-item :tag "Lynx in an Emacs window"
262 :value browse-url-lynx-emacs) 263 :value browse-url-lynx-emacs)
263 (function-item :tag "Grail" :value browse-url-grail) 264 (function-item :tag "Grail" :value browse-url-grail)
264 (function-item :tag "MMM" :value browse-url-mmm) 265 (function-item :tag "MMM" :value browse-url-mmm)
265 (function-item :tag "KDE" :value browse-url-kde) 266 (function-item :tag "KDE" :value browse-url-kde)
267 (function-item :tag "Elinks" :value browse-url-elinks)
266 (function-item :tag "Specified by `Browse Url Generic Program'" 268 (function-item :tag "Specified by `Browse Url Generic Program'"
267 :value browse-url-generic) 269 :value browse-url-generic)
268 (function-item :tag "Default Windows browser" 270 (function-item :tag "Default Windows browser"
269 :value browse-url-default-windows-browser) 271 :value browse-url-default-windows-browser)
270 (function-item :tag "Default Mac OS X browser" 272 (function-item :tag "Default Mac OS X browser"
605 607
606 (defcustom browse-url-kde-args '("openURL") 608 (defcustom browse-url-kde-args '("openURL")
607 "A list of strings defining options for `browse-url-kde-program'." 609 "A list of strings defining options for `browse-url-kde-program'."
608 :type '(repeat (string :tag "Argument")) 610 :type '(repeat (string :tag "Argument"))
609 :group 'browse-url) 611 :group 'browse-url)
612
613 (defcustom browse-url-elinks-wrapper '("xterm" "-e")
614 "*Wrapper command prepended to the Elinks command-line."
615 :type '(repeat (string :tag "Wrapper"))
616 :group 'browse-url)
617
618 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
619 ;; URL encoding
620
621 (defun browse-url-encode-url (url)
622 "Encode all `confusing' characters in URL."
623 (let ((encoded-url (copy-seq url)))
624 (while (string-match "%" encoded-url)
625 (setq encoded-url (replace-match "%25" t t encoded-url)))
626 (while (string-match "[*\"()',=;? ]" encoded-url)
627 (setq encoded-url
628 (replace-match (format "%%%x"
629 (string-to-char (match-string 0 encoded-url)))
630 t t encoded-url)))
631 encoded-url))
610 632
611 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 633 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
612 ;; URL input 634 ;; URL input
613 635
614 ;;;###autoload 636 ;;;###autoload
678 Use variable `browse-url-filename-alist' to map filenames to URLs." 700 Use variable `browse-url-filename-alist' to map filenames to URLs."
679 (let ((coding (and default-enable-multibyte-characters 701 (let ((coding (and default-enable-multibyte-characters
680 (or file-name-coding-system 702 (or file-name-coding-system
681 default-file-name-coding-system)))) 703 default-file-name-coding-system))))
682 (if coding (setq file (encode-coding-string file coding)))) 704 (if coding (setq file (encode-coding-string file coding))))
683 ;; URL-encode special chars, do % first 705 (setq file (browse-url-encode-url file))
684 (let ((s 0))
685 (while (setq s (string-match "%" file s))
686 (setq file (replace-match "%25" t t file)
687 s (1+ s))))
688 (while (string-match "[*\"()',=;? ]" file)
689 (let ((enc (format "%%%x" (aref file (match-beginning 0)))))
690 (setq file (replace-match enc t t file))))
691 (dolist (map browse-url-filename-alist) 706 (dolist (map browse-url-filename-alist)
692 (when (and map (string-match (car map) file)) 707 (when (and map (string-match (car map) file))
693 (setq file (replace-match (cdr map) t nil file)))) 708 (setq file (replace-match (cdr map) t nil file))))
694 file) 709 file)
695 710
891 is loaded in a new tab in an existing window instead. 906 is loaded in a new tab in an existing window instead.
892 907
893 When called non-interactively, optional second argument NEW-WINDOW is 908 When called non-interactively, optional second argument NEW-WINDOW is
894 used instead of `browse-url-new-window-flag'." 909 used instead of `browse-url-new-window-flag'."
895 (interactive (browse-url-interactive-arg "URL: ")) 910 (interactive (browse-url-interactive-arg "URL: "))
896 ;; URL encode any `confusing' characters in the URL. This needs to 911 (setq url (browse-url-encode-url url))
897 ;; include at least commas; presumably also close parens and dollars.
898 (while (string-match "[,)$]" url)
899 (setq url (replace-match
900 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
901 (let* ((process-environment (browse-url-process-environment)) 912 (let* ((process-environment (browse-url-process-environment))
902 (process 913 (process
903 (apply 'start-process 914 (apply 'start-process
904 (concat "netscape " url) nil 915 (concat "netscape " url) nil
905 browse-url-netscape-program 916 browse-url-netscape-program
965 new tab in an existing window instead. 976 new tab in an existing window instead.
966 977
967 When called non-interactively, optional second argument NEW-WINDOW is 978 When called non-interactively, optional second argument NEW-WINDOW is
968 used instead of `browse-url-new-window-flag'." 979 used instead of `browse-url-new-window-flag'."
969 (interactive (browse-url-interactive-arg "URL: ")) 980 (interactive (browse-url-interactive-arg "URL: "))
970 ;; URL encode any `confusing' characters in the URL. This needs to 981 (setq url (browse-url-encode-url url))
971 ;; include at least commas; presumably also close parens and dollars.
972 (while (string-match "[,)$]" url)
973 (setq url (replace-match
974 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
975 (let* ((process-environment (browse-url-process-environment)) 982 (let* ((process-environment (browse-url-process-environment))
976 (process 983 (process
977 (apply 'start-process 984 (apply 'start-process
978 (concat "mozilla " url) nil 985 (concat "mozilla " url) nil
979 browse-url-mozilla-program 986 browse-url-mozilla-program
1027 command line parameter. Therefore, the 1034 command line parameter. Therefore, the
1028 `browse-url-new-window-flag' and `browse-url-firefox-new-window-is-tab' 1035 `browse-url-new-window-flag' and `browse-url-firefox-new-window-is-tab'
1029 are ignored as well. Firefox on Windows will always open the requested 1036 are ignored as well. Firefox on Windows will always open the requested
1030 URL in a new window." 1037 URL in a new window."
1031 (interactive (browse-url-interactive-arg "URL: ")) 1038 (interactive (browse-url-interactive-arg "URL: "))
1032 ;; URL encode any `confusing' characters in the URL. This needs to 1039 (setq url (browse-url-encode-url url))
1033 ;; include at least commas; presumably also close parens.
1034 (while (string-match "[,)]" url)
1035 (setq url (replace-match
1036 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
1037 (let* ((process-environment (browse-url-process-environment)) 1040 (let* ((process-environment (browse-url-process-environment))
1038 (process 1041 (process
1039 (apply 'start-process 1042 (apply 'start-process
1040 (concat "firefox " url) nil 1043 (concat "firefox " url) nil
1041 browse-url-firefox-program 1044 browse-url-firefox-program
1083 new tab in an existing window instead. 1086 new tab in an existing window instead.
1084 1087
1085 When called non-interactively, optional second argument NEW-WINDOW is 1088 When called non-interactively, optional second argument NEW-WINDOW is
1086 used instead of `browse-url-new-window-flag'." 1089 used instead of `browse-url-new-window-flag'."
1087 (interactive (browse-url-interactive-arg "URL: ")) 1090 (interactive (browse-url-interactive-arg "URL: "))
1088 ;; URL encode any `confusing' characters in the URL. This needs to 1091 (setq url (browse-url-encode-url))
1089 ;; include at least commas; presumably also close parens and dollars.
1090 (while (string-match "[,)$]" url)
1091 (setq url (replace-match
1092 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
1093 (let* ((process-environment (browse-url-process-environment)) 1092 (let* ((process-environment (browse-url-process-environment))
1094 (process (apply 'start-process 1093 (process (apply 'start-process
1095 (concat "galeon " url) 1094 (concat "galeon " url)
1096 nil 1095 nil
1097 browse-url-galeon-program 1096 browse-url-galeon-program
1132 new tab in an existing window instead. 1131 new tab in an existing window instead.
1133 1132
1134 When called non-interactively, optional second argument NEW-WINDOW is 1133 When called non-interactively, optional second argument NEW-WINDOW is
1135 used instead of `browse-url-new-window-flag'." 1134 used instead of `browse-url-new-window-flag'."
1136 (interactive (browse-url-interactive-arg "URL: ")) 1135 (interactive (browse-url-interactive-arg "URL: "))
1137 ;; URL encode any `confusing' characters in the URL. This needs to 1136 (setq url (browse-url-encode-url url))
1138 ;; include at least commas; presumably also close parens and dollars.
1139 (while (string-match "[,)$]" url)
1140 (setq url (replace-match
1141 (format "%%%x" (string-to-char (match-string 0 url))) t t url)))
1142 (let* ((process-environment (browse-url-process-environment)) 1137 (let* ((process-environment (browse-url-process-environment))
1143 (process (apply 'start-process 1138 (process (apply 'start-process
1144 (concat "epiphany " url) 1139 (concat "epiphany " url)
1145 nil 1140 nil
1146 browse-url-epiphany-program 1141 browse-url-epiphany-program
1511 (interactive (browse-url-interactive-arg "KDE URL: ")) 1506 (interactive (browse-url-interactive-arg "KDE URL: "))
1512 (message "Sending URL to KDE...") 1507 (message "Sending URL to KDE...")
1513 (apply #'start-process (concat "KDE " url) nil browse-url-kde-program 1508 (apply #'start-process (concat "KDE " url) nil browse-url-kde-program
1514 (append browse-url-kde-args (list url)))) 1509 (append browse-url-kde-args (list url))))
1515 1510
1511 ;;;###autoload
1512 (defun browse-url-elinks (url)
1513 "Ask the Elinks WWW browser to load URL.
1514 Default to the URL around the point.
1515
1516 The document is loaded in a new tab of a running Elinks or, if
1517 none yet running, a newly started instance.
1518
1519 The Elinks command will be prepended by the program+arguments
1520 from `elinks-browse-url-wrapper'."
1521 (interactive (browse-url-interactive-arg "URL: "))
1522 (setq url (browse-url-encode-url url))
1523 (let ((process-environment (browse-url-process-environment))
1524 (elinks-ping-process (start-process "elinks-ping" nil
1525 "elinks" "-remote" "ping()")))
1526 (set-process-sentinel elinks-ping-process
1527 `(lambda (process change)
1528 (browse-url-elinks-sentinel process ,url)))))
1529
1530 (defun browse-url-elinks-sentinel (process url)
1531 "Determines if Elinks is running or a new one has to be started."
1532 (let ((exit-status (process-exit-status process))
1533 (process-environment (browse-url-process-environment)))
1534 ;; Try to determine if an instance is running or if we have to
1535 ;; create a new one.
1536 (case exit-status
1537 (5
1538 ;; No instance, start a new one.
1539 (apply #'start-process
1540 (append (list (concat "elinks:" url) nil)
1541 browse-url-elinks-wrapper
1542 (list "elinks" url))))
1543 (0
1544 ;; Found an instance, open URL in new tab.
1545 (start-process (concat "elinks:" url) nil
1546 "elinks" "-remote"
1547 (concat "openURL(\"" url "\",new-tab)")))
1548 (otherwise
1549 (error "Undefined exit-code of process `elinks'.")))))
1550
1516 (provide 'browse-url) 1551 (provide 'browse-url)
1517 1552
1518 ;; arch-tag: d2079573-5c06-4097-9598-f550fba19430 1553 ;; arch-tag: d2079573-5c06-4097-9598-f550fba19430
1519 ;;; browse-url.el ends here 1554 ;;; browse-url.el ends here