+ (let ((root-address (elpher-make-address ?1 "" host port)))
+ (elpher-visit-node
+ (elpher-make-node (concat "gopher://" host
+ ":" (number-to-string port)
+ "/1/")
+ root-address)))
+ (error "Already at root directory of current server")))
+ (error "Command invalid for this page"))))
+
+(defun elpher-bookmarks-current-p ()
+ "Return non-nil if current node is a bookmarks page."
+ (eq (elpher-address-type (elpher-node-address elpher-current-node)) 'bookmarks))
+
+(defun elpher-reload-bookmarks ()
+ "Reload bookmarks if current node is a bookmarks page."
+ (if (elpher-bookmarks-current-p)
+ (elpher-reload-current-node)))
+
+(defun elpher-bookmark-current ()
+ "Bookmark the current node."
+ (interactive)
+ (let ((address (elpher-node-address elpher-current-node))
+ (display-string (elpher-node-display-string elpher-current-node)))
+ (if (not (elpher-address-special-p address))
+ (let ((bookmark-display-string (read-string "Bookmark display string: "
+ display-string)))
+ (elpher-add-address-bookmark address bookmark-display-string)
+ (message "Bookmark added."))
+ (error "Cannot bookmark %s" display-string))))
+
+(defun elpher-bookmark-link ()
+ "Bookmark the link at point."
+ (interactive)
+ (let ((button (button-at (point))))
+ (if button
+ (let* ((node (button-get button 'elpher-node))
+ (address (elpher-node-address node))
+ (display-string (elpher-node-display-string node)))
+ (if (not (elpher-address-special-p address))
+ (let ((bookmark-display-string (read-string "Bookmark display string: "
+ display-string)))
+ (elpher-add-address-bookmark address bookmark-display-string)
+ (elpher-reload-bookmarks)
+ (message "Bookmark added."))
+ (error "Cannot bookmark %s" display-string)))
+ (error "No link selected"))))
+
+(defun elpher-unbookmark-current ()
+ "Remove bookmark for the current node."
+ (interactive)
+ (let ((address (elpher-node-address elpher-current-node)))
+ (unless (elpher-address-special-p address)
+ (elpher-remove-address-bookmark address)
+ (message "Bookmark removed."))))
+
+(defun elpher-unbookmark-link ()
+ "Remove bookmark for the link at point."
+ (interactive)
+ (let ((button (button-at (point))))
+ (if button
+ (let ((node (button-get button 'elpher-node)))
+ (elpher-remove-address-bookmark (elpher-node-address node))
+ (elpher-reload-bookmarks)
+ (message "Bookmark removed."))
+ (error "No link selected"))))
+
+(defun elpher-bookmarks ()
+ "Visit bookmarks."
+ (interactive)
+ (switch-to-buffer "*elpher*")
+ (elpher-visit-node
+ (elpher-make-node "Bookmarks Page" (elpher-make-address 'bookmarks))))
+
+(defun elpher-info-node (node)
+ "Display information on NODE."
+ (let ((display-string (elpher-node-display-string node))
+ (address (elpher-node-address node)))
+ (if (not (elpher-address-special-p address))
+ (message "`%s' on %s port %s"
+ (elpher-address-selector address)
+ (elpher-address-host address)
+ (elpher-address-port address))
+ (message "%s" display-string))))
+
+(defun elpher-info-link ()
+ "Display information on node corresponding to link at point."
+ (interactive)
+ (let ((button (button-at (point))))
+ (if button
+ (elpher-info-node (button-get button 'elpher-node))
+ (error "No item selected"))))
+
+(defun elpher-info-current ()
+ "Display information on current node."
+ (interactive)
+ (elpher-info-node elpher-current-node))
+
+(defun elpher-get-address-url (address)
+ "Get URL representation of ADDRESS."
+ (let ((type (elpher-address-type address))
+ (selector (elpher-address-selector address))
+ (host (elpher-address-host address))
+ (port (elpher-address-port address)))
+ (if (and (equal type ?h)
+ (string-prefix-p "URL:" selector))
+ (elt (split-string selector "URL:") 1)
+ (concat "gopher"
+ (if (elpher-address-use-tls-p address) "s" "")
+ "://"
+ host
+ (if (equal port 70)
+ ""
+ (format ":%d" port))
+ "/" (string type)
+ selector))))
+
+(defun elpher-copy-node-url (node)
+ "Copy URL representation of address of NODE to `kill-ring'."
+ (let ((address (elpher-node-address node)))
+ (if (elpher-address-special-p address)
+ (error (format "Cannot represent %s as URL" (elpher-node-display-string node)))
+ (let ((url (elpher-get-address-url address)))
+ (message "Copied \"%s\" to kill-ring/clipboard." url)
+ (kill-new url)))))
+
+(defun elpher-copy-link-url ()
+ "Copy URL of item at point to `kill-ring'."
+ (interactive)
+ (let ((button (button-at (point))))
+ (if button
+ (elpher-copy-node-url (button-get button 'elpher-node))
+ (error "No item selected"))))
+
+(defun elpher-copy-current-url ()
+ "Copy URL of current node to `kill-ring'."
+ (interactive)
+ (elpher-copy-node-url elpher-current-node))
+
+(defun elpher-set-coding-system ()
+ "Specify an explicit character coding system."
+ (interactive)
+ (let ((system (read-coding-system "Set coding system to use (default is to autodetect): " nil)))
+ (setq elpher-user-coding-system system)
+ (if system
+ (message "Coding system fixed to %s. (Reload to see effect)." system)
+ (message "Coding system set to autodetect. (Reload to see effect)."))))