Package: emacs-snapshot
Version: 1:20061123-1
Severity: wishlist
The file browse-url.el provides a large number of options for calling
an external web browser to view specified URLs (indeed, perhaps too
many - the Grail browser, for instance, has been abandoned for more
than 7 years now). Anyway, the browse-url-lynx-emacs function, which
lets you run the text browser lynx inside an Emacs terminal window, is
especially awesome, except it only works for lynx. That is, no elinks,
which is my text browser of choice.
I'd like to have elinks so available (specifically I would like
"browse-url-elinks-emacs" and "browse-url-elinks-term" functions added
to Emacs and browse-url.el), since it's one of the two or three most
common text browsers. I do have a solution of sorts beyond this
general feature request: I went into browse-url.el, copied out the
relevant function and necessary helper functions and variables and got
something which works alright (currently doesn't seem to work in an
Emacs running on the console, but I don't know whether that's a bug or
by design); a simple search and replace seemed to do the trick, elinks
and lynx are so similar (although I'm sure this could be cleaned up -
maybe a more general function for running text browsers in Emacs, like
"browse-url-generic-text-browser-emacs"?). So right now I have the
following code in my .emacs:
;;;;;;This section rewrites the browse-url-lynx-emacs command to use elinks
(defun browse-url-elinks-emacs (url &optional new-buffer)
"Ask the Elinks WWW browser to load URL.
Default to the URL around or before point. With a prefix argument, run
a new Elinks process in a new buffer.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new elinks 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 (browse-url-interactive-arg "Elinks URL: "))
(let* ((system-uses-terminfo t) ; Elinks uses terminfo
;; (term-term-name "vt100") ; ??
(buf (get-buffer "*elinks*"))
(proc (and buf (get-buffer-process buf)))
(n
browse-url-elinks-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 *elinks* and would
;; choke on *elinks*<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 elinks
(progn
(setq buf
(apply #'make-term
`("elinks" "elinks" nil ,@browse-url-elinks-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 elinks 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-elinks-input-field 'warn)
(error "Please move out of the input field first"))
((eq browse-url-elinks-input-field 'avoid)
(while (and (eq (following-char) ?_) (> n 0))
(term-send-down) ; down arrow
(sit-for browse-url-elinks-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")))))
(defcustom browse-url-elinks-input-field 'avoid
"*Action on selecting an existing Elinks buffer at an input field.
What to do when sending a new URL to an existing Elinks buffer in Emacs
if the Elinks cursor is on an input field (in which case the `g' command
would be entered as data). Such fields are recognized by the
underlines ____. Allowed values: nil: disregard it, 'warn: warn the
user and don't emit the URL, 'avoid: try to avoid the field by moving
down (this *won't* always work)."
:type '(choice (const :tag "Move to try to avoid field" :value avoid)
(const :tag "Disregard" :value nil)
(const :tag "Warn, don't emit URL" :value warn))
:version "20.3"
:group 'browse-url)
(defcustom browse-url-elinks-input-attempts 10
"*How many times to try to move down from a series of elinks input fields."
:type 'integer
:group 'browse-url)
(defcustom browse-url-elinks-input-delay 0.2
"*How many seconds to wait for elinks between moves down from an input field."
:type 'number
:group 'browse-url)
(defcustom browse-url-elinks-emacs-args (and (not window-system)
'("-show_cursor"))
"*A list of strings defining options for Elinks in an Emacs buffer.
The default is none in a window system, otherwise `-show_cursor' to
indicate the position of the current link in the absence of
highlighting, assuming the normal default for showing the cursor."
:type '(repeat (string :tag "Argument"))
:version "20.3"
:group 'browse-url)
~maru
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]