+ (let* ((system-uses-terminfo t) ; Lynx uses terminfo
+ ;; (term-term-name "vt100") ; ??
+ (buf (get-buffer "*lynx*"))
+ (proc (and buf (get-buffer-process buf)))
+ (n browse-url-lynx-input-attempts))
+ (if (and (browse-url-maybe-new-window new-buffer) buf)
+ ;; Rename away the OLD buffer. This isn't very polite, but
+ ;; term insists on working in a buffer named *lynx* and would
+ ;; choke on *lynx*<1>
+ (progn (set-buffer buf)
+ (rename-uniquely)))
+ (if (or (browse-url-maybe-new-window new-buffer)
+ (not buf)
+ (not proc)
+ (not (memq (process-status proc) '(run stop))))
+ ;; start a new lynx
+ (progn
+ (setq buf
+ (apply #'make-term
+ `("lynx" "lynx" nil ,@browse-url-lynx-emacs-args ,url)))
+ (switch-to-buffer buf)
+ (term-char-mode)
+ (set-process-sentinel
+ (get-buffer-process buf)
+ ;; Don't leave around a dead one (especially because of its
+ ;; munged keymap.)
+ (lambda (process event)
+ (if (not (memq (process-status process) '(run stop)))
+ (let ((buf (process-buffer process)))
+ (if buf (kill-buffer buf)))))))
+ ;; send the url to lynx in the old buffer
+ (let ((win (get-buffer-window buf t)))
+ (if win
+ (select-window win)
+ (switch-to-buffer buf)))
+ (if (eq (following-char) ?_)
+ (cond ((eq browse-url-lynx-input-field 'warn)
+ (error "Please move out of the input field first."))
+ ((eq browse-url-lynx-input-field 'avoid)
+ (while (and (eq (following-char) ?_) (> n 0))
+ (term-send-down) ; down arrow
+ (sit-for browse-url-lynx-input-delay))
+ (if (eq (following-char) ?_)
+ (error "Cannot move out of the input field, sorry.")))))
+ (term-send-string proc (concat "g" ; goto
+ "\C-u" ; kill default url
+ url
+ "\r")))))
+
+;; --- MMM ---
+
+;;;###autoload
+(defun browse-url-mmm (url &optional new-window)
+ "Ask the MMM WWW browser to load URL.
+Default to the URL around or before point."
+ (interactive (browse-url-interactive-arg "MMM URL: "))
+ (message "Sending URL to MMM...")
+ (save-excursion
+ (set-buffer (get-buffer-create " *Shell Command Output*"))
+ (erase-buffer)
+ ;; mmm_remote just SEGVs if the file isn't there...
+ (if (or (file-exists-p (expand-file-name "~/.mmm_remote"))
+ ;; location in v 0.4:
+ (file-exists-p (expand-file-name "~/.mmm/remote")))
+ (call-process "mmm_remote" nil 0 nil url)
+ (call-process "mmm" nil 0 nil "-external" url))
+ (message "Sending URL to MMM... done")))
+
+;; --- mailto ---
+
+;;;###autoload
+(defun browse-url-mail (url &optional new-window)
+ "Open a new mail message buffer within Emacs.
+Default to using the mailto: URL around or before point as the
+recipient's address. Supplying a non-nil interactive prefix argument
+will cause the mail to be composed in another window rather than the
+current one.
+
+When called interactively, if variable `browse-url-new-window-p' is
+non-nil use `compose-mail-other-window', otherwise `compose-mail'. A
+non-nil interactive prefix argument reverses the effect of
+`browse-url-new-window-p'.
+
+When called non-interactively, optional second argument NEW-WINDOW is
+used instead of `browse-url-new-window-p'."
+ (interactive (browse-url-interactive-arg "Mailto URL: "))
+ (save-excursion
+ (let ((func (if (browse-url-maybe-new-window new-window)
+ 'compose-mail-other-window
+ 'compose-mail))
+ (to (if (string-match "^mailto:" url)
+ (substring url 7)
+ url)))
+ (apply func
+ (list to nil nil nil nil nil (cons 'insert-buffer
+ (current-buffer)))))))
+
+;; --- Random browser ---
+
+;;;###autoload
+(defun browse-url-generic (url &optional new-window)
+ ;; new-window ignored
+ "Ask the WWW browser defined by `browse-url-generic-program' to load URL.
+Default to the URL around or before point. A fresh copy of the
+browser is started up in a new process with possible additional arguments
+`browse-url-generic-args'. This is appropriate for browsers which
+don't offer a form of remote control."
+ (interactive (browse-url-interactive-arg "URL: "))
+ (if (not browse-url-generic-program)
+ (error "No browser defined (`browse-url-generic-program')"))
+ (apply 'start-process (concat browse-url-generic-program url) nil
+ browse-url-generic-program
+ (append browse-url-generic-args (list url))))