(defun browse-url-text-browser-emacs (url generic &optional new-buffer) "Ask for a Web address and an arbitrary text browser. When called interactively, if variable `browse-url-new-window-flag' is non-nil, load the document in a new text browser in a new term window, otherwise use any existing one. A non-nil interactive prefix argument reverses the effect of `browse-url-new-window-flag'. When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'." (interactive "MWeb address: \nMBrowser: ") (let* ((system-uses-terminfo t) ; Text browsers use terminfo? (buf (get-buffer "*text-browser*")) (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 text browser (progn (setq buf (apply #'make-term `("text-browser" ,generic 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 the text-browser 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"))))) (defun browse-url-lynx-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls Lynx." (interactive (browse-url-interactive-arg "URL for Lynx: ")) (browse-url-text-browser-emacs url "lynx" new-buffer)) (defun browse-url-elinks-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls Elinks." (interactive (browse-url-interactive-arg "URL for Elinks: ")) (browse-url-text-browser-emacs url "elinks" new-buffer)) (defun browse-url-links-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls Links." (interactive (browse-url-interactive-arg "URL for Links: ")) (browse-url-text-browser-emacs url "links" new-buffer)) (defun browse-url-links2-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls Links2." (interactive (browse-url-interactive-arg "URL for Links2: ")) (browse-url-text-browser-emacs url "links2" new-buffer)) (defun browse-url-netrik-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls Netrik." (interactive (browse-url-interactive-arg "URL for Netrik: ")) (browse-url-text-browser-emacs url "netrik" new-buffer)) (defun browse-url-w3m-emacs (url &optional new-buffer) "Specializes browse-url-text-browser-emacs so it calls w3m." (interactive (browse-url-interactive-arg "URL for w3m: ")) (browse-url-text-browser-emacs url "w3m" new-buffer))