+(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))))
+