From: Tim Vaughan Date: Fri, 14 Jun 2019 11:52:13 +0000 (+0200) Subject: Merge. X-Git-Tag: v1.2.0~1 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=14f8d5cd99838da14b292fe4992ed0a4aa70af41;p=elpher.git Merge. --- 14f8d5cd99838da14b292fe4992ed0a4aa70af41 diff --cc elpher.el index a24d056,b21dca5..531b2da --- a/elpher.el +++ b/elpher.el @@@ -214,22 -195,20 +214,25 @@@ special address types, such as 'start f (defun elpher-address-port (address) "Retrieve port from ADDRESS." - (elt address 2)) + (elt address 3)) + ++(defun elpher-address-special-p (address) ++ (not (elpher-address-host address))) + ;; Node -(defun elpher-make-node (parent address getter &optional content pos) +(defun elpher-make-node (display-string parent address) "Create a node in the gopher page hierarchy. -PARENT specifies the parent of the node, ADDRESS specifies the address of -the gopher page, GETTER provides the getter function used to obtain this -page. +DISPLAY-STRING records the display string used for the page. + +PARENT specifies the parent of the node, and ADDRESS specifies the +address of the gopher page." + (list display-string parent address)) -The optional arguments CONTENT and POS can be used to fill the cached -content and cursor position fields of the node." - (list parent address getter content pos)) +(defun elpher-node-display-string (node) + "Retrieve the display string of NODE." + (elt node 0)) (defun elpher-node-parent (node) "Retrieve the parent node of NODE." @@@ -355,27 -310,20 +358,27 @@@ (insert " ")) (insert (make-string elpher-margin-width ?\s)))) -(defun elpher-insert-index-record (line) - "Insert the index record corresponding to LINE into the current buffer." - (let* ((type (elt line 0)) - (fields (split-string (substring line 1) "\t")) - (display-string (elt fields 0)) - (selector (elt fields 1)) - (host (elt fields 2)) - (port (elt fields 3)) - (address (elpher-make-address selector host port)) - (type-map-entry (alist-get type elpher-type-map))) +(defun elpher-node-button-help (node) + "Return a string containing the help text for a button corresponding to NODE." + (let ((address (elpher-node-address node))) + (if (eq (elpher-address-type address) ?h) + (let ((url (cadr (split-string (elpher-address-selector address) "URL:")))) + (format "mouse-1, RET: open url '%s'" url)) + (format "mouse-1, RET: open '%s' on %s port %s" + (elpher-address-selector address) + (elpher-address-host address) + (elpher-address-port address))))) + +(defun elpher-insert-index-record (display-string type selector host port) + "Function to insert an index record into the current buffer. +The contents of the record are dictated by TYPE, DISPLAY-STRING, SELECTOR, HOST +and PORT." + (let ((address (elpher-make-address type selector host port)) + (type-map-entry (alist-get type elpher-type-map))) (if type-map-entry - (let* ((margin-code (cadr type-map-entry)) - (let ((getter (car type-map-entry)) - (margin-code (cadr type-map-entry)) - (face (elt type-map-entry 2))) ++ (let* ((margin-code (elt type-map-entry 1)) + (face (elt type-map-entry 2)) + (node (elpher-make-node display-string elpher-current-node address))) (elpher-insert-margin margin-code) (insert-text-button display-string 'face face @@@ -798,11 -671,11 +803,13 @@@ host, selector and port. (message "No current site."))) (defun elpher-view-raw () -- "View current page as plain text." ++ "View raw server response for current page." (interactive) (if elpher-current-node -- (elpher-visit-node elpher-current-node -- #'elpher-get-node-raw) ++ (if (elpher-address-special-p (elpher-node-address elpher-current-node)) ++ (error "This page was not generated by a server.") ++ (elpher-visit-node elpher-current-node ++ #'elpher-get-node-raw)) (message "No current site."))) (defun elpher-back () @@@ -818,11 -691,11 +825,11 @@@ (let ((button (button-at (point)))) (if button (let ((node (button-get button 'elpher-node))) -- (if node -- (elpher-visit-node (button-get button 'elpher-node) -- #'elpher-get-node-download) - (error "Can only download gopher links, not general URLs"))) - (message "Can only download gopher links, not general URLs."))) - (message "No link selected.")))) ++ (if (elpher-address-special-p (elpher-node-address node)) ++ (error "Cannot download this link") ++ (elpher-visit-node (button-get button 'elpher-node) ++ #'elpher-get-node-download))) + (error "No link selected")))) (defun elpher-build-link-map () "Build alist mapping link names to destination nodes in current buffer."