~michel-slm/elpher

3 3

get raw text of gopher page

Details
Message ID
<86zg7zqj4u.fsf@mailbox.org>
DKIM signature
missing
Download raw message
What is the best way to use elpher to get the text of a gopher menu or
file, in an elisp program?  I do this thing where I do elpher-go,
sit-for a bunch of seconds, and then elpher-view-raw.  It was the best
I could figure out, but I wonder if there's a better way.
Details
Message ID
<87pm8udeuw.fsf@the-brannons.com>
In-Reply-To
<86zg7zqj4u.fsf@mailbox.org> (view parent)
DKIM signature
missing
Download raw message
joneworlds@mailbox.org writes:

> What is the best way to use elpher to get the text of a gopher menu or
> file, in an elisp program?  I do this thing where I do elpher-go,
> sit-for a bunch of seconds, and then elpher-view-raw.  It was the best
> I could figure out, but I wonder if there's a better way.

I don't have an answer, but I was wondering the same thing the other
day.  Ideally emacs's built-in url package should be extended to
retrieve gopher and gemini URIs, I think.  I wonder if emacs's url
package has any mechanisms to allow third-party libraries to add new URI handlers.

-- Chris
Details
Message ID
<87o7oe8igv.fsf@thelambdalab.xyz>
In-Reply-To
<87pm8udeuw.fsf@the-brannons.com> (view parent)
DKIM signature
missing
Download raw message
Hi both,

Chris Brannon <chris@the-brannons.com> writes:
> joneworlds@mailbox.org writes:
>
>> What is the best way to use elpher to get the text of a gopher menu or
>> file, in an elisp program?  I do this thing where I do elpher-go,
>> sit-for a bunch of seconds, and then elpher-view-raw.  It was the best
>> I could figure out, but I wonder if there's a better way.

Funny, I was just now wondering the same thing.  It wouldn't be hard to
write a short function to do this, given that elpher exposes "getter"
functions for each of the protocols it supports.  The only reason the
existing functions probably aren't ideal is just that, due to the
asyncronous nature of network processes, they require a callback to
process the retrieved data, so you'd probably want a wrapper around
that.

> I don't have an answer, but I was wondering the same thing the other
> day.  Ideally emacs's built-in url package should be extended to
> retrieve gopher and gemini URIs, I think.  I wonder if emacs's url
> package has any mechanisms to allow third-party libraries to add new URI handlers.

I would _love_ to be able to simply add relevant functions to a table
there so that URL retrieval could be handled in a uniform way across all
of emacs.  There's so much wheel-reinvention happening in elpher as the
result of not taking this approach. The limit of that approach might
even be to make elpher completely obsolete by incorporating
gopher/gemini/whatever browsing into eww or something similar.

I vaguely remember looking at this a couple of years ago and not
finding an easy way to do this though.  And now, at least for elpher
itself, I'd say it's too late.  (I don't plan any future massive elpher
refactors.)

Tim
Details
Message ID
<86bkilxznc.fsf@mailbox.org>
In-Reply-To
<87o7oe8igv.fsf@thelambdalab.xyz> (view parent)
DKIM signature
missing
Download raw message
This program copied at the end this message is about as good as I can
do for fetching gopher text using elpher, and waiting until it's done.
I test it like this, and it seems to go:

(switch-to-buffer
 (jw-get-gopher
  "gopher://republic.circumlunar.space/0/~joneworlds/uj-3-riding-the-bus.txt"))


On url, I figured out that defining one function named "url-gopher" is
all I would need to make this work: (url-retrieve-synchronously "gopher://republic.circumlunar.space")

My url-gopher does not do anything, but it does get run.  So filling it in
with all the stuff to do a network connection would be enough to make
it work, I think.

(defun url-gopher (url) 
  (message "gopher got it")
  (let ((b (get-buffer-create "*gopher-retrieval*")))
    (with-current-buffer b
      (erase-buffer)
      (insert "done"))
    b))





(defun jw-get-gopher (url)
  (elpher-process-cleanup)
  (get-buffer-create "*elpher*")
  (let* ((cleaned-url (string-trim url))
         (address (elpher-address-from-url cleaned-url)))
    (setq jw-gopher-ready nil)
    (with-current-buffer (get-buffer-create "*jw-get-gopher*")
      (erase-buffer))
    (elpher-get-host-response address 70
                              (concat
                               (elpher-gopher-address-selector address)
                               "\r\n")
                              (lambda (s)
                                (with-current-buffer
                                    (get-buffer-create "*jw-get-gopher*")
                                  (erase-buffer)
                                  (insert s)
                                  (replace-string (char-to-string 13) ""
                                                  nil (point-max) (point-min))
                                  (setq jw-gopher-ready t))))
    (let ((how-long 0)
          (too-long 10))
      (while (and (not jw-gopher-ready) (< how-long too-long))
        (sit-for 0.25)
        (setq how-long (+ how-long 0.25))))
    (get-buffer-create "*jw-get-gopher*")))
Reply to thread Export thread (mbox)