Updated notes.
[elpher.git] / elpher.el
index 25d8238..531b2da 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -4,7 +4,7 @@
 
 ;; Author: Tim Vaughan <tgvaughan@gmail.com>
 ;; Created: 11 April 2019
-;; Version: 1.1.0
+;; Version: 1.2.0
 ;; Keywords: comm gopher
 ;; Homepage: https://github.com/tgvaughan/elpher
 ;; Package-Requires: ((emacs "25"))
@@ -55,7 +55,7 @@
 ;;; Global constants
 ;;
 
-(defconst elpher-version "1.1.0"
+(defconst elpher-version "1.2.0"
   "Current version of elpher.")
 
 (defconst elpher-margin-width 6
@@ -216,6 +216,9 @@ special address types, such as 'start for the start page."
   "Retrieve port from ADDRESS."
   (elt address 3))
 
+(defun elpher-address-special-p (address)
+  (not (elpher-address-host address)))
+
 ;; Node
 
 (defun elpher-make-node (display-string parent address)
@@ -373,7 +376,7 @@ 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* ((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)
@@ -674,8 +677,7 @@ calls, as is necessary if the match is performed by `string-match'."
 (defun elpher-get-bookmarks-node ()
   "Getter which loads and displays the current bookmark list."
   (elpher-with-clean-buffer
-   (insert "Use 'u' to return to the previous page.\n\n"
-           "---- Bookmark list ----\n\n")
+   (insert "---- Bookmark list ----\n\n")
    (let ((bookmarks (elpher-load-bookmarks)))
      (if bookmarks
          (dolist (bookmark bookmarks)
@@ -687,7 +689,10 @@ calls, as is necessary if the match is performed by `string-match'."
                                          (elpher-address-host address)
                                          (elpher-address-port address))))
        (insert "No bookmarks found.\n")))
-   (insert "\n-----------------------")
+   (insert "\n-----------------------\n\n"
+           "u: return to previous page.\n"
+           "x: delete selected bookmark.\n"
+           "a: rename selected bookmark.\n")
    (elpher-restore-pos)))
   
 
@@ -763,7 +768,9 @@ If ADDRESS is already bookmarked, update the label only."
   (push-button))
 
 (defun elpher-go ()
-  "Go to a particular gopher site."
+  "Go to a particular gopher site read from the minibuffer.
+The site may be specified via a URL or explicitly in terms of
+host, selector and port."
   (interactive)
   (let ((node
          (let ((host-or-url (read-string "Gopher host or URL: ")))
@@ -796,11 +803,13 @@ If ADDRESS is already bookmarked, update the label only."
     (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 ()
@@ -816,10 +825,10 @@ If ADDRESS is already bookmarked, update the label only."
   (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")))
+          (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 ()
@@ -837,7 +846,7 @@ If ADDRESS is already bookmarked, update the label only."
   (let* ((link-map (elpher-build-link-map)))
     (if link-map
         (let ((key (let ((completion-ignore-case t))
-                     (completing-read "Directory entry/link (tab to autocomplete): "
+                     (completing-read "Directory item/link: "
                                       link-map nil t))))
           (if (and key (> (length key) 0))
               (let ((b (cdr (assoc key link-map))))
@@ -876,11 +885,12 @@ If ADDRESS is already bookmarked, update the label only."
 (defun elpher-bookmark-current ()
   "Bookmark the current node."
   (interactive)
-  (if (not (elpher-bookmarks-current-p))
+  (unless (elpher-bookmarks-current-p)
       (let ((address (elpher-node-address elpher-current-node))
             (display-string (read-string "Bookmark display string: "
                                          (elpher-node-display-string elpher-current-node))))
-        (elpher-add-address-bookmark address display-string))))
+        (elpher-add-address-bookmark address display-string)
+        (message "Bookmark added."))))
 
 (defun elpher-bookmark-link ()
   "Bookmark the link at point."
@@ -892,14 +902,16 @@ If ADDRESS is already bookmarked, update the label only."
                (display-string (read-string "Bookmark display string: "
                                             (elpher-node-display-string node))))
           (elpher-add-address-bookmark address display-string)
-          (elpher-reload-bookmarks))
+          (elpher-reload-bookmarks)
+          (message "Bookmark added."))
       (error "No link selected"))))
 
 (defun elpher-unbookmark-current ()
   "Remove bookmark for the current node."
   (interactive)
-  (if (not (elpher-bookmarks-current-p))
-      (elpher-remove-address-bookmark (elpher-node-address elpher-current-node))))
+  (unless (elpher-bookmarks-current-p)
+    (elpher-remove-address-bookmark (elpher-node-address elpher-current-node))
+    (message "Bookmark removed.")))
 
 (defun elpher-unbookmark-link ()
   "Remove bookmark for the link at point."
@@ -908,7 +920,8 @@ If ADDRESS is already bookmarked, update the label only."
     (if button
         (let ((node (button-get button 'elpher-node)))
           (elpher-remove-address-bookmark (elpher-node-address node))
-          (elpher-reload-bookmarks))
+          (elpher-reload-bookmarks)
+          (message "Bookmark removed."))
       (error "No link selected"))))
 
 (defun elpher-bookmarks ()