~michel-slm/elpher

3 2

Opening binary files with program instead of downloading them

Troels Henriksen <athas@sigkill.dk>
Details
Message ID
<87mt76o45a.fsf@sigkill.dk>
DKIM signature
missing
Download raw message
I spend a lot of time on the hip and modern part of Gopherspace where
people host various forms of multimedia (videos, images, sounds).  When
following a link to these resources, Elpher will download it to my file
system, and I must then go to a shell, open the file, and delete it when
I am done watching it.  This is somewhat tedious.  I would much rather
Elpher create a temporary file, ask me which program to use for viewing
it (e.g imv, mpv), run it, and automatically delete it when the program
terminates.  I cooked up a small function for doing this:

(defun elpher-render-download-or-view (data &optional _mime-type-string)
  "Save DATA or show with other program. MIME-TYPE-STRING is unused."
  (if (not data)
      nil
    (let* ((address (elpher-page-address elpher-current-page))
           (selector (if (elpher-address-gopher-p address)
                         (elpher-gopher-address-selector address)
                       (elpher-address-filename address))))
      (if (y-or-n-p (format "%s: 'y' to save to disk, 'n' to open in other program."
                            (file-name-nondirectory selector)))
          (elpher-render-download data)
        (elpher-visit-previous-page) ; Do first in case of non-local exits.
        (let ((program (read-from-minibuffer "Program: "))
              (tmp (make-temp-file "elpher-download" nil (file-name-nondirectory selector))))
          (let ((coding-system-for-write 'binary))
            (with-temp-file tmp (insert data)))
          (make-process :name "Elpher-viewer"
                        :buffer nil
                        :command (list program tmp)
                        :noquery t
                        :sentinel (lambda (p s)
                                    ;; Most messages (and likely all
                                    ;; that we will receive here) mean
                                    ;; that the process is dead, or
                                    ;; dead enough that we can delete
                                    ;; the file.
                                    (delete-file tmp))))))))

By replacing most/all uses of elpher-render-download with
elpher-render-download-or-view, I get pretty much the experience I'm
looking for.  I'm sure the user interface can be improved (using
y-or-n-p feels a bit hacky, and a second prompt is also a bit clumsy),
but I think this idea is sound.  An alternative idea is for
elpher-render-download to allow one to press a magic keychord while
asking for the filename to instead switch to view-mode.

Any suggestions for how to progress with this?  I do not care overmuch
about the specifics, but I'd really like functionality similar to this
to make it into Elpher.
Details
Message ID
<87fscytapk.fsf@thelambdalab.xyz>
In-Reply-To
<87mt76o45a.fsf@sigkill.dk> (view parent)
DKIM signature
missing
Download raw message
Hi Troels,

Troels Henriksen <athas@sigkill.dk> writes:
> Any suggestions for how to progress with this?  I do not care overmuch
> about the specifics, but I'd really like functionality similar to this
> to make it into Elpher.

While this sounds like a great idea, I do prefer the current behaviour for
downloads.  I think the correct way to implement "open [blah] in
external file" would be to modify elpher-render-gemini to use a
data-directed programming style, in the same way that the
elpher-visit-page already does.  In other words, mime type-specific
behaviour should be directed by a table similar to elpher-type-map
rather than hard-coded conditionals. This would allow users to specify
precisely how different mime types should be handled, and allow certain
types to be opened using external programs.

Not to say that your current solution isn't good, it's just not the
approach I'd like to incorporate directly into elpher.

If you'd like to still share it around, you could post it to emacs wiki
in the meantime.

All the best for the new year!

Tim
Troels Henriksen <athas@sigkill.dk>
Details
Message ID
<87fscy2jmx.fsf@sigkill.dk>
In-Reply-To
<87fscytapk.fsf@thelambdalab.xyz> (view parent)
DKIM signature
missing
Download raw message
plugd <plugd@thelambdalab.xyz> writes:

> I think the correct way to implement "open [blah] in external file"
> would be to modify elpher-render-gemini to use a data-directed
> programming style, in the same way that the elpher-visit-page already
> does.

I use this for Gopher, not Elpher.  How would I find the mime type?
Does Emacs have a convenient function for mapping an extension to a mime
type?

-- 
\  Troels
/\ Henriksen
Details
Message ID
<87o7rhmjro.fsf@thelambdalab.xyz>
In-Reply-To
<87fscy2jmx.fsf@sigkill.dk> (view parent)
DKIM signature
missing
Download raw message
Hi Troels,

Troels Henriksen <athas@sigkill.dk> writes:
> plugd <plugd@thelambdalab.xyz> writes:
> I use this for Gopher, not Elpher.  How would I find the mime type?
> Does Emacs have a convenient function for mapping an extension to a mime
> type?

Sorry, I misread your original email.  (Somehow my brain autocorrected
"hip, media-centric" into geminispace.)

Indeed, there's no mime types for gopher documents, and your approach
is likely the most parsimonious. I'll take another look at it.

Sorry again for the reading comprehension fail.

Regards,
Tim
Reply to thread Export thread (mbox)