Would it be possible to treat URLs as read-only filenames? Perhaps!

I started work on an elpher-file-handler, but there is definitely a lot more to do. Having all these primites return something useful is harder than it looks. 😒

;;; Treating URLs as files
;;

;;;###autload
(defun elpher-file-handler (operation &rest args)
  ;; First check for the specific operations
  ;; that we have special handling for.
  (cond ((eq operation 'expand-file-name) (car args))
	((eq operation 'load) (elpher-go (car args)))
	((eq operation 'file-remote-p) t)
	((eq operation 'verify-visited-file-modtime) nil)
	((eq operation 'file-exists-p) t)
	((eq operation 'file-readable-p) t)
	((eq operation 'file-writable-p) nil)
	((eq operation 'file-directory-p) nil)
	((eq operation 'file-directory-file-name) nil)
	((eq operation 'file-name-directory) nil)
	((eq operation 'directory-file-name) "")
	((eq operation 'file-name-nondirectory) (car args))
	((eq operation 'file-truename) (car args))
	((eq operation 'file-attributes) nil)
	((eq operation 'file-name-case-insensitive-p) nil)
	((eq operation 'vc-registered) nil)
	((eq operation 'get-file-buffer) nil);; possibly!
	((eq operation 'insert-file-contents) (elpher-insert-contents (car args)))
	;; ... add more?
        ;; Handle any operation we don’t know about.
        (t (let ((inhibit-file-name-handlers
                  (cons 'elpher-file-handler
                        (and (eq inhibit-file-name-operation operation)
                             inhibit-file-name-handlers)))
                 (inhibit-file-name-operation operation))
	     (message "elpher-file-handler doesn't handle %S" operation)
             (apply operation args)))))

(add-to-list
 'file-name-handler-alist
 '("^\\(gopher\\|finger\\|gemini\\)://" . elpher-file-handler))

;;;###autoload
(defun elpher-insert-contents (host-or-url)
  "Insert the rendered content of HOST-OR-URL."
  (interactive "sGopher or Gemini URL: ")
  (let* ((cleaned-host-or-url (string-trim host-or-url))
         (address (elpher-address-from-url cleaned-host-or-url))
         (page (elpher-make-page cleaned-host-or-url address)))
    (elpher-visit-page page)))