comparison lisp/net/browse-url.el @ 37378:c5e0aa9cbe69

(browse-url-new-window-flag): Renamed from browse-url-new-window-p.
author Gerd Moellmann <gerd@gnu.org>
date Wed, 18 Apr 2001 12:48:36 +0000
parents 392d90bba860
children 16a7e84d5ff3
comparison
equal deleted inserted replaced
37377:76aa4a0b5959 37378:c5e0aa9cbe69
1 ;;; browse-url.el --- Pass a URL to a WWW browser 1 ;;; browse-url.el --- Pass a URL to a WWW browser
2 2
3 ;; Copyright (C) 1995, 96, 97, 98, 99, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001
4 ;; Free Software Foundation, Inc.
4 5
5 ;; Author: Denis Howe <dbh@doc.ic.ac.uk> 6 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
6 ;; Maintainer: Dave Love <fx@gnu.org> 7 ;; Maintainer: Dave Love <fx@gnu.org>
7 ;; Created: 03 Apr 1995 8 ;; Created: 03 Apr 1995
8 ;; Keywords: hypertext, hypermedia, mouse 9 ;; Keywords: hypertext, hypermedia, mouse
295 `browse-url' is loaded." 296 `browse-url' is loaded."
296 :type '(repeat (string :tag "Argument")) 297 :type '(repeat (string :tag "Argument"))
297 :group 'browse-url) 298 :group 'browse-url)
298 299
299 ;;;###autoload 300 ;;;###autoload
300 (defcustom browse-url-new-window-p nil 301 (defcustom browse-url-new-window-flag nil
301 "*If non-nil, always open a new browser window with appropriate browsers. 302 "*If non-nil, always open a new browser window with appropriate browsers.
302 Passing an interactive argument to \\[browse-url], or specific browser 303 Passing an interactive argument to \\[browse-url], or specific browser
303 commands reverses the effect of this variable. Requires Netscape version 304 commands reverses the effect of this variable. Requires Netscape version
304 1.1N or later or XMosaic version 2.5 or later if using those browsers." 305 1.1N or later or XMosaic version 2.5 or later if using those browsers."
305 :type 'boolean 306 :type 'boolean
492 493
493 (defun browse-url-interactive-arg (prompt) 494 (defun browse-url-interactive-arg (prompt)
494 "Read a URL from the minibuffer, prompting with PROMPT. 495 "Read a URL from the minibuffer, prompting with PROMPT.
495 Default to the URL at or before point. If invoked with a mouse button, 496 Default to the URL at or before point. If invoked with a mouse button,
496 set point to the position clicked first. Return a list for use in 497 set point to the position clicked first. Return a list for use in
497 `interactive' containing the URL and `browse-url-new-window-p' or its 498 `interactive' containing the URL and `browse-url-new-window-flag' or its
498 negation if a prefix argument was given." 499 negation if a prefix argument was given."
499 (let ((event (elt (this-command-keys) 0))) 500 (let ((event (elt (this-command-keys) 0)))
500 (and (listp event) (mouse-set-point event))) 501 (and (listp event) (mouse-set-point event)))
501 (list (read-string prompt (browse-url-url-at-point)) 502 (list (read-string prompt (browse-url-url-at-point))
502 (not (eq (null browse-url-new-window-p) 503 (not (eq (null browse-url-new-window-flag)
503 (null current-prefix-arg))))) 504 (null current-prefix-arg)))))
504 505
505 ;; interactive-p needs to be called at a function's top-level, hence 506 ;; interactive-p needs to be called at a function's top-level, hence
506 ;; the macro. 507 ;; the macro.
507 (defmacro browse-url-maybe-new-window (arg) 508 (defmacro browse-url-maybe-new-window (arg)
508 `(if (interactive-p) 509 `(if (interactive-p)
509 ,arg 510 ,arg
510 browse-url-new-window-p)) 511 browse-url-new-window-flag))
511 512
512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 513 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
513 ;; Browse current buffer 514 ;; Browse current buffer
514 515
515 ;;;###autoload 516 ;;;###autoload
608 "Ask a WWW browser to load URL. 609 "Ask a WWW browser to load URL.
609 Prompts for a URL, defaulting to the URL at or before point. Variable 610 Prompts for a URL, defaulting to the URL at or before point. Variable
610 `browse-url-browser-function' says which browser to use." 611 `browse-url-browser-function' says which browser to use."
611 (interactive (browse-url-interactive-arg "URL: ")) 612 (interactive (browse-url-interactive-arg "URL: "))
612 (unless (interactive-p) 613 (unless (interactive-p)
613 (setq args (or args (list browse-url-new-window-p)))) 614 (setq args (or args (list browse-url-new-window-flag))))
614 (if (functionp browse-url-browser-function) 615 (if (functionp browse-url-browser-function)
615 (apply browse-url-browser-function url args) 616 (apply browse-url-browser-function url args)
616 ;; The `function' can be an alist; look down it for first match 617 ;; The `function' can be an alist; look down it for first match
617 ;; and apply the function (which might be a lambda). 618 ;; and apply the function (which might be a lambda).
618 (catch 'done 619 (catch 'done
630 `browse-url-browser-function' says which browser to use." 631 `browse-url-browser-function' says which browser to use."
631 (interactive "P") 632 (interactive "P")
632 (let ((url (browse-url-url-at-point))) 633 (let ((url (browse-url-url-at-point)))
633 (if url 634 (if url
634 (browse-url url (if arg 635 (browse-url url (if arg
635 (not browse-url-new-window-p) 636 (not browse-url-new-window-flag)
636 browse-url-new-window-p)) 637 browse-url-new-window-flag))
637 (error "No URL found")))) 638 (error "No URL found"))))
638 639
639 ;;;###autoload 640 ;;;###autoload
640 (defun browse-url-at-mouse (event) 641 (defun browse-url-at-mouse (event)
641 "Ask a WWW browser to load a URL clicked with the mouse. 642 "Ask a WWW browser to load a URL clicked with the mouse.
644 `browse-url'. Variable `browse-url-browser-function' says which browser 645 `browse-url'. Variable `browse-url-browser-function' says which browser
645 to use." 646 to use."
646 (interactive "e") 647 (interactive "e")
647 (save-excursion 648 (save-excursion
648 (mouse-set-point event) 649 (mouse-set-point event)
649 (browse-url-at-point browse-url-new-window-p))) 650 (browse-url-at-point browse-url-new-window-flag)))
650 651
651 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 652 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
652 ;; Browser-specific commands 653 ;; Browser-specific commands
653 654
654 ;; --- Default MS-Windows browser --- 655 ;; --- Default MS-Windows browser ---
683 (defun browse-url-netscape (url &optional new-window) 684 (defun browse-url-netscape (url &optional new-window)
684 "Ask the Netscape WWW browser to load URL. 685 "Ask the Netscape WWW browser to load URL.
685 Default to the URL around or before point. The strings in variable 686 Default to the URL around or before point. The strings in variable
686 `browse-url-netscape-arguments' are also passed to Netscape. 687 `browse-url-netscape-arguments' are also passed to Netscape.
687 688
688 When called interactively, if variable `browse-url-new-window-p' is 689 When called interactively, if variable `browse-url-new-window-flag' is
689 non-nil, load the document in a new Netscape window, otherwise use a 690 non-nil, load the document in a new Netscape window, otherwise use a
690 random existing one. A non-nil interactive prefix argument reverses 691 random existing one. A non-nil interactive prefix argument reverses
691 the effect of `browse-url-new-window-p'. 692 the effect of `browse-url-new-window-flag'.
692 693
693 When called non-interactively, optional second argument NEW-WINDOW is 694 When called non-interactively, optional second argument NEW-WINDOW is
694 used instead of `browse-url-new-window-p'." 695 used instead of `browse-url-new-window-flag'."
695 (interactive (browse-url-interactive-arg "URL: ")) 696 (interactive (browse-url-interactive-arg "URL: "))
696 ;; URL encode any `confusing' characters in the URL. This needs to 697 ;; URL encode any `confusing' characters in the URL. This needs to
697 ;; include at least commas; presumably also close parens. 698 ;; include at least commas; presumably also close parens.
698 (while (string-match "[,)]" url) 699 (while (string-match "[,)]" url)
699 (setq url (replace-match 700 (setq url (replace-match
758 (defun browse-url-gnome-moz (url &optional new-window) 759 (defun browse-url-gnome-moz (url &optional new-window)
759 "Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'. 760 "Ask Mozilla/Netscape to load URL via the GNOME program `gnome-moz-remote'.
760 Default to the URL around or before point. The strings in variable 761 Default to the URL around or before point. The strings in variable
761 `browse-url-gnome-moz-arguments' are also passed. 762 `browse-url-gnome-moz-arguments' are also passed.
762 763
763 When called interactively, if variable `browse-url-new-window-p' is 764 When called interactively, if variable `browse-url-new-window-flag' is
764 non-nil, load the document in a new browser window, otherwise use an 765 non-nil, load the document in a new browser window, otherwise use an
765 existing one. A non-nil interactive prefix argument reverses the 766 existing one. A non-nil interactive prefix argument reverses the
766 effect of `browse-url-new-window-p'. 767 effect of `browse-url-new-window-flag'.
767 768
768 When called non-interactively, optional second argument NEW-WINDOW is 769 When called non-interactively, optional second argument NEW-WINDOW is
769 used instead of `browse-url-new-window-p'." 770 used instead of `browse-url-new-window-flag'."
770 (interactive (browse-url-interactive-arg "URL: ")) 771 (interactive (browse-url-interactive-arg "URL: "))
771 (apply 'start-process (concat "gnome-moz-remote " url) 772 (apply 'start-process (concat "gnome-moz-remote " url)
772 nil 773 nil
773 "gnome-moz-remote" 774 "gnome-moz-remote"
774 (append 775 (append
786 Default to the URL around or before point. The strings in variable 787 Default to the URL around or before point. The strings in variable
787 `browse-url-mosaic-arguments' are also passed to Mosaic and the 788 `browse-url-mosaic-arguments' are also passed to Mosaic and the
788 program is invoked according to the variable 789 program is invoked according to the variable
789 `browse-url-mosaic-program'. 790 `browse-url-mosaic-program'.
790 791
791 When called interactively, if variable `browse-url-new-window-p' is 792 When called interactively, if variable `browse-url-new-window-flag' is
792 non-nil, load the document in a new Mosaic window, otherwise use a 793 non-nil, load the document in a new Mosaic window, otherwise use a
793 random existing one. A non-nil interactive prefix argument reverses 794 random existing one. A non-nil interactive prefix argument reverses
794 the effect of `browse-url-new-window-p'. 795 the effect of `browse-url-new-window-flag'.
795 796
796 When called non-interactively, optional second argument NEW-WINDOW is 797 When called non-interactively, optional second argument NEW-WINDOW is
797 used instead of `browse-url-new-window-p'." 798 used instead of `browse-url-new-window-flag'."
798 (interactive (browse-url-interactive-arg "Mosaic URL: ")) 799 (interactive (browse-url-interactive-arg "Mosaic URL: "))
799 (let ((pidfile (expand-file-name "~/.mosaicpid")) 800 (let ((pidfile (expand-file-name "~/.mosaicpid"))
800 pid) 801 pid)
801 (if (file-readable-p pidfile) 802 (if (file-readable-p pidfile)
802 (save-excursion 803 (save-excursion
860 861
861 This function only works for XMosaic version 2.5 or later. You must 862 This function only works for XMosaic version 2.5 or later. You must
862 select `CCI' from XMosaic's File menu, set the CCI Port Address to the 863 select `CCI' from XMosaic's File menu, set the CCI Port Address to the
863 value of variable `browse-url-CCI-port', and enable `Accept requests'. 864 value of variable `browse-url-CCI-port', and enable `Accept requests'.
864 865
865 When called interactively, if variable `browse-url-new-window-p' is 866 When called interactively, if variable `browse-url-new-window-flag' is
866 non-nil, load the document in a new browser window, otherwise use a 867 non-nil, load the document in a new browser window, otherwise use a
867 random existing one. A non-nil interactive prefix argument reverses 868 random existing one. A non-nil interactive prefix argument reverses
868 the effect of `browse-url-new-window-p'. 869 the effect of `browse-url-new-window-flag'.
869 870
870 When called non-interactively, optional second argument NEW-WINDOW is 871 When called non-interactively, optional second argument NEW-WINDOW is
871 used instead of `browse-url-new-window-p'." 872 used instead of `browse-url-new-window-flag'."
872 (interactive (browse-url-interactive-arg "Mosaic URL: ")) 873 (interactive (browse-url-interactive-arg "Mosaic URL: "))
873 (open-network-stream "browse-url" " *browse-url*" 874 (open-network-stream "browse-url" " *browse-url*"
874 browse-url-CCI-host browse-url-CCI-port) 875 browse-url-CCI-host browse-url-CCI-port)
875 ;; Todo: start browser if fails 876 ;; Todo: start browser if fails
876 (process-send-string "browse-url" 877 (process-send-string "browse-url"
898 ;;;###autoload 899 ;;;###autoload
899 (defun browse-url-w3 (url &optional new-window) 900 (defun browse-url-w3 (url &optional new-window)
900 "Ask the w3 WWW browser to load URL. 901 "Ask the w3 WWW browser to load URL.
901 Default to the URL around or before point. 902 Default to the URL around or before point.
902 903
903 When called interactively, if variable `browse-url-new-window-p' is 904 When called interactively, if variable `browse-url-new-window-flag' is
904 non-nil, load the document in a new window. A non-nil interactive 905 non-nil, load the document in a new window. A non-nil interactive
905 prefix argument reverses the effect of `browse-url-new-window-p'. 906 prefix argument reverses the effect of `browse-url-new-window-flag'.
906 907
907 When called non-interactively, optional second argument NEW-WINDOW is 908 When called non-interactively, optional second argument NEW-WINDOW is
908 used instead of `browse-url-new-window-p'." 909 used instead of `browse-url-new-window-flag'."
909 (interactive (browse-url-interactive-arg "W3 URL: ")) 910 (interactive (browse-url-interactive-arg "W3 URL: "))
910 (require 'w3) ; w3-fetch-other-window not autoloaded 911 (require 'w3) ; w3-fetch-other-window not autoloaded
911 (if (browse-url-maybe-new-window new-window) 912 (if (browse-url-maybe-new-window new-window)
912 (w3-fetch-other-window url) 913 (w3-fetch-other-window url)
913 (w3-fetch url))) 914 (w3-fetch url)))
945 (defun browse-url-lynx-emacs (url &optional new-buffer) 946 (defun browse-url-lynx-emacs (url &optional new-buffer)
946 "Ask the Lynx WWW browser to load URL. 947 "Ask the Lynx WWW browser to load URL.
947 Default to the URL around or before point. With a prefix argument, run 948 Default to the URL around or before point. With a prefix argument, run
948 a new Lynx process in a new buffer. 949 a new Lynx process in a new buffer.
949 950
950 When called interactively, if variable `browse-url-new-window-p' is 951 When called interactively, if variable `browse-url-new-window-flag' is
951 non-nil, load the document in a new lynx in a new term window, 952 non-nil, load the document in a new lynx in a new term window,
952 otherwise use any existing one. A non-nil interactive prefix argument 953 otherwise use any existing one. A non-nil interactive prefix argument
953 reverses the effect of `browse-url-new-window-p'. 954 reverses the effect of `browse-url-new-window-flag'.
954 955
955 When called non-interactively, optional second argument NEW-WINDOW is 956 When called non-interactively, optional second argument NEW-WINDOW is
956 used instead of `browse-url-new-window-p'." 957 used instead of `browse-url-new-window-flag'."
957 (interactive (browse-url-interactive-arg "Lynx URL: ")) 958 (interactive (browse-url-interactive-arg "Lynx URL: "))
958 (let* ((system-uses-terminfo t) ; Lynx uses terminfo 959 (let* ((system-uses-terminfo t) ; Lynx uses terminfo
959 ;; (term-term-name "vt100") ; ?? 960 ;; (term-term-name "vt100") ; ??
960 (buf (get-buffer "*lynx*")) 961 (buf (get-buffer "*lynx*"))
961 (proc (and buf (get-buffer-process buf))) 962 (proc (and buf (get-buffer-process buf)))
1032 Default to using the mailto: URL around or before point as the 1033 Default to using the mailto: URL around or before point as the
1033 recipient's address. Supplying a non-nil interactive prefix argument 1034 recipient's address. Supplying a non-nil interactive prefix argument
1034 will cause the mail to be composed in another window rather than the 1035 will cause the mail to be composed in another window rather than the
1035 current one. 1036 current one.
1036 1037
1037 When called interactively, if variable `browse-url-new-window-p' is 1038 When called interactively, if variable `browse-url-new-window-flag' is
1038 non-nil use `compose-mail-other-window', otherwise `compose-mail'. A 1039 non-nil use `compose-mail-other-window', otherwise `compose-mail'. A
1039 non-nil interactive prefix argument reverses the effect of 1040 non-nil interactive prefix argument reverses the effect of
1040 `browse-url-new-window-p'. 1041 `browse-url-new-window-flag'.
1041 1042
1042 When called non-interactively, optional second argument NEW-WINDOW is 1043 When called non-interactively, optional second argument NEW-WINDOW is
1043 used instead of `browse-url-new-window-p'." 1044 used instead of `browse-url-new-window-flag'."
1044 (interactive (browse-url-interactive-arg "Mailto URL: ")) 1045 (interactive (browse-url-interactive-arg "Mailto URL: "))
1045 (save-excursion 1046 (save-excursion
1046 (let ((to (if (string-match "^mailto:" url) 1047 (let ((to (if (string-match "^mailto:" url)
1047 (substring url 7) 1048 (substring url 7)
1048 url))) 1049 url)))