-;;; elpher.el --- a friendly gopher client.
+;;; elpher.el --- A friendly gopher client.
;; Copyright (C) 2019 Tim Vaughan
;; page containing information on key bindings and suggested starting
;; points for your gopher exploration.
-;; Faces, caching options and start page can be configured via
+;; Faces, caching and other options can be configured via
;; the Elpher customization group in Applications.
;;; Code:
(provide 'elpher)
(require 'seq)
(require 'pp)
+(require 'shr)
;;; Global constants
;;
(?g elpher-get-image-node "im" elpher-image)
(?p elpher-get-image-node "im" elpher-image)
(?I elpher-get-image-node "im" elpher-image)
+ (?d elpher-get-node-download "d" elpher-binary)
(?h elpher-get-url-node "W" elpher-url)
(bookmarks elpher-get-bookmarks-node "#" elpher-index)
(start elpher-get-start-node "#" elpher-index))
(elt address 3))
(defun elpher-address-special-p (address)
+ "Return non-nil if ADDRESS is special (e.g. start page, bookmarks page)."
(not (elpher-address-host address)))
;; Node
;; URL retrieval
+(defun elpher-insert-rendered-html (string)
+ "Use shr to insert rendered view of html STRING into current buffer."
+ (let ((dom (with-temp-buffer
+ (insert string)
+ (libxml-parse-html-region (point-min) (point-max)))))
+ (shr-insert-document dom)))
+
(defun elpher-get-url-node ()
"Getter which attempts to open the URL specified by the current node."
(let* ((address (elpher-node-address elpher-current-node))
(selector (elpher-address-selector address)))
- (elpher-visit-parent-node) ; Do first in case of non-local exits.
(let ((url (elt (split-string selector "URL:") 1)))
- (if elpher-open-urls-with-eww
- (browse-web url)
- (browse-url url)))))
+ (if url
+ (progn
+ (elpher-visit-parent-node) ; Do first in case of non-local exits.
+ (message "Opening URL...")
+ (if elpher-open-urls-with-eww
+ (browse-web url)
+ (browse-url url)))
+ (let ((content (elpher-get-cached-content address)))
+ (if content
+ (progn
+ (elpher-with-clean-buffer
+ (insert content)
+ (elpher-restore-pos)))
+ (elpher-with-clean-buffer
+ (insert "LOADING HTML... (use 'u' to cancel)"))
+ (elpher-get-selector address
+ (lambda (proc event)
+ (unless (string-prefix-p "deleted" event)
+ (elpher-with-clean-buffer
+ (elpher-insert-rendered-html elpher-selector-string)
+ (goto-char (point-min))
+ (elpher-cache-content
+ (elpher-node-address elpher-current-node)
+ (buffer-string))))))))))))
;; Telnet node connection
;; Bookmarks page node retrieval
(defun elpher-get-bookmarks-node ()
- "Getter which loads and displays the current bookmark list."
+ "Getter to load and display the current bookmark list."
(elpher-with-clean-buffer
(insert "---- Bookmark list ----\n\n")
(let ((bookmarks (elpher-load-bookmarks)))
"- x: delete selected bookmark\n"
"- a: rename selected bookmark\n\n"
"Bookmarks are stored in the file "
- (locate-user-emacs-file "elpher-bookmarks"))
+ (locate-user-emacs-file "elpher-bookmarks"))
(elpher-restore-pos)))
(interactive)
(if elpher-current-node
(if (elpher-address-special-p (elpher-node-address elpher-current-node))
- (error "This page was not generated by a server.")
+ (error "This page was not generated by a server")
(elpher-visit-node elpher-current-node
#'elpher-get-node-raw))
(message "No current site.")))