I’m often annoyed when browsers have different keybindings. Info navigates this way, dired that way, eww the other way, and when I find myself using w3m, or lynx, the pain continues.
One simple solution would be to have Elpher handle HTTP and HTTPS links as well.
(defface elpher-http '((t :inherit font-lock-comment-face)) "Face used for HTTP/HTTPS type directory records.") ;; add the HTTP entry after the Gemini entry to `elpher-type-map' (unless (assq 'http elpher-type-map) (let ((cell (memq (assq 'gemini elpher-type-map) elpher-type-map))) (setcdr cell (cons '(http elpher-get-http-page elpher-render-http "http" elpher-http) (cdr cell))))) (defun elpher-http-remove-redundant-ports (orig address &rest args) "Handle HTTP/HTTPS ports." (setq address (apply orig address args)) (when (and (not (elpher-address-special-p address)) (eq (url-portspec address) (pcase (url-type address) ("http" 80) ("https" 443) (_ -1)))) (setf (url-portspec address) nil)) address) (advice-add 'elpher-remove-redundant-ports :around #'elpher-http-remove-redundant-ports) ;; (url-portspec (elpher-remove-redundant-ports (url-generic-parse-url "https://alexschroeder.ch:443"))) → nil ;; (url-portspec (elpher-remove-redundant-ports (url-generic-parse-url "https://transjovian.org:1965"))) → 1965 (defun elpher-http-address-type (orig address &rest args) "Handle HTTP/HTTPS scheme." (let ((type (apply orig address args))) (if (eq type 'other-url) (let ((protocol (url-type address))) (cond ((equal protocol "http") 'http) ((equal protocol "https") 'http) (t type))) type))) (advice-add 'elpher-address-type :around #'elpher-http-address-type) ;; (elpher-address-type (url-generic-parse-url "http://alexschroeder.ch")) ;; HTTP/HTTPS (defun elpher-get-http-page (renderer) "Opens a HTTP/HTTPS connection to the current page address." (let* ((address (elpher-page-address elpher-current-page)) (content (elpher-get-cached-content address))) (if (and content (funcall renderer nil)) (elpher-with-clean-buffer (insert content) (elpher-restore-pos)) (elpher-with-clean-buffer (insert "LOADING... (use 'u' to cancel)\n")) (condition-case the-error (let* ((kill-buffer-query-functions nil) (host (elpher-address-host address)) (port (elpher-address-port address)) (path (elpher-address-filename address)) (tls (string= (elpher-address-protocol address) "https")) ;; say HTTP/1.0 so that we don't get chunked encoding back (request (concat "GET " path " HTTP/1.0")) (header (concat "Host: " host)) (message (string-join (list request header "\r\n") "\r\n"))) (elpher-get-host-response address 443 message renderer tls)) (error (elpher-network-error address the-error)))))) (defun elpher-render-http (data &optional _mime-type-string) "Render DATA as HTML using shr. MIME-TYPE-STRING is unused." (with-current-buffer (get-buffer-create "*elpher response*") (erase-buffer) (insert data)) (elpher-with-clean-buffer (if (not data) t (let ((dom (with-temp-buffer (insert data) (goto-char (point-min)) ;; decode based on header (save-excursion (when (re-search-forward "^Content-Type: text/html; charset=\\(.*\\)\r\n" nil t) (let ((coding-system (coding-system-from-name (match-string 1)))) (search-forward "\r\n\r\n" nil t) (decode-coding-region (point) (point-max) coding-system)))) (search-forward "\r\n\r\n" nil t) ;; or decode based on meta tags in the body (let* ((d (libxml-parse-html-region (point) (point-max))) (node (dom-search d (lambda (node) (and (equal (dom-tag node) 'meta) (dom-attr node 'charset))))) (coding-system (coding-system-from-name (dom-attr node 'charset)))) (when coding-system ;; this is why I hate the web… (decode-coding-region (point) (point-max) coding-system) (setq d (libxml-parse-html-region (point) (point-max)))) d)))) ;; assuming content-type text/html (shr-insert-document dom)))))
More: