1 ;;; elpher.el --- Full-featured gopher client.
3 ;; Copyright (C) 2019 Tim Vaughan
5 ;; Author: Tim Vaughan <tgvaughan@gmail.com>
6 ;; Created: 11 April 2019
8 ;; Keywords: comm gopher
9 ;; Homepage: https://github.com/tgvaughan/elpher
10 ;; Package-Requires: ((emacs "25"))
12 ;; This file is not part of GNU Emacs.
14 ;; This program is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this file. If not, see <http://www.gnu.org/licenses/>.
29 ;; Elpher aims to provide a full-featured gopher client for GNU Emacs.
32 ;; - intuitive keyboard and mouse-driven browsing,
33 ;; - caching of visited sites (both content and cursor position),
34 ;; - pleasant and configurable colouring of Gopher directories,
35 ;; - direct visualisation of image files,
36 ;; - (m)enu key support, similar to Emacs' info browser,
37 ;; - clickable web and gopher links in plain text.
39 ;; Visited pages are stored as a hierarchy rather than a linear history,
40 ;; meaning that navigation between these pages is quick and easy.
42 ;; To launch Elpher, simply use 'M-x elpher'. This will open a start
43 ;; page containing information on key bindings and suggested starting
44 ;; points for your gopher exploration.
46 ;; Faces, caching options and start page can be configured via
47 ;; the Elpher customization group in Applications.
58 (defconst elpher-version "1.1.0"
59 "Current version of elpher.")
61 (defconst elpher-margin-width 6
62 "Width of left-hand margin used when rendering indicies.")
64 (defconst elpher-start-index
67 (list "i\tfake\tfake\t1"
68 "i --------------------------------------------\tfake\tfake\t1"
69 "i Elpher Gopher Client \tfake\tfake\t1"
70 (format "i version %s\tfake\tfake\t1" elpher-version)
71 "i --------------------------------------------\tfake\tfake\t1"
73 "iUsage:\tfake\tfake\t1"
75 "i - tab/shift-tab: next/prev directory entry on current page\tfake\tfake\t1"
76 "i - RET/mouse-1: open directory entry under cursor\tfake\tfake\t1"
77 "i - m: select a directory entry by name (autocompletes)\tfake\tfake\t1"
78 "i - u: return to parent directory entry\tfake\tfake\t1"
79 "i - O: visit the root directory of the current server\tfake\tfake\t1"
80 "i - g: go to a particular page\tfake\tfake\t1"
81 "i - r: redraw current page (using cached contents if available)\tfake\tfake\t1"
82 "i - R: reload current page (regenerates cache)\tfake\tfake\t1"
83 "i - d: download directory entry under cursor\tfake\tfake\t1"
84 "i - w: display the raw server response for the current page\tfake\tfake\t1"
86 "iPlaces to start exploring Gopherspace:\tfake\tfake\t1"
88 "1Floodgap Systems Gopher Server\t\tgopher.floodgap.com\t70"
90 "iAlternatively, select the following item and enter some\tfake\tfake\t1"
91 "isearch terms:\tfake\tfake\t1"
93 "7Veronica-2 Gopher Search Engine\t/v2/vs\tgopher.floodgap.com\t70"
96 "Source for elpher start page.")
98 (defconst elpher-type-map
99 '((?0 elpher-get-text-node "T" elpher-text)
100 (?1 elpher-get-index-node "/" elpher-index)
101 (?g elpher-get-image-node "im" elpher-image)
102 (?p elpher-get-image-node "im" elpher-image)
103 (?I elpher-get-image-node "im" elpher-image)
104 (?4 elpher-get-node-download "B" elpher-binary)
105 (?5 elpher-get-node-download "B" elpher-binary)
106 (?9 elpher-get-node-download "B" elpher-binary)
107 (?7 elpher-get-search-node "?" elpher-search))
108 "Association list from types to getters, margin codes and index faces.")
111 ;;; Customization group
116 :group 'applications)
118 ;; Face customizations
120 (defface elpher-index
121 '((t :inherit org-drawer))
122 "Face used for directory type directory records.")
125 '((t :inherit org-tag))
126 "Face used for text type directory records.")
129 '((t :inherit org-default))
130 "Face used for info type directory records.")
132 (defface elpher-image
133 '((t :inherit org-level-4))
134 "Face used for image type directory records.")
136 (defface elpher-search
137 '((t :inherit org-level-5))
138 "Face used for search type directory records.")
141 '((t :inherit org-level-6))
142 "Face used for url type directory records.")
144 (defface elpher-binary
145 '((t :inherit org-level-7))
146 "Face used for binary type directory records.")
148 (defface elpher-unknown
149 '((t :inherit org-warning))
150 "Face used for directory records with unknown/unsupported types.")
152 (defface elpher-margin-key
153 '((t :inherit org-tag))
154 "Face used for directory margin key.")
156 (defface elpher-margin-brackets
157 '((t :inherit org-special-keyword))
158 "Face used for brackets around directory margin key.")
160 ;; Other customizations
162 (defcustom elpher-open-urls-with-eww nil
163 "If non-nil, open URL selectors using eww.
164 Otherwise, use the system browser via the BROWSE-URL function."
167 (defcustom elpher-buttonify-urls-in-directories nil
168 "If non-nil, turns URLs matched in directories into clickable buttons."
171 (defcustom elpher-cache-images nil
172 "If non-nil, cache images in memory in the same way as other content."
175 (defcustom elpher-start-address nil
176 "If nil, the default start directory is shown when Elpher is started.
177 Otherwise, a list containing the selector, host and port of a directory to
178 use as the start page."
179 :type '(list string string integer))
187 (defun elpher-make-address (selector host port)
188 "Create an address of a gopher object with SELECTOR, HOST and PORT."
189 (list selector host port))
191 (defun elpher-address-selector (address)
192 "Retrieve selector from ADDRESS."
195 (defun elpher-address-host (address)
196 "Retrieve host from ADDRESS."
199 (defun elpher-address-port (address)
200 "Retrieve port from ADDRESS."
205 (defun elpher-make-node (parent address getter &optional content pos)
206 "Create a node in the gopher page hierarchy.
208 PARENT specifies the parent of the node, ADDRESS specifies the address of
209 the gopher page, GETTER provides the getter function used to obtain this
212 The optional arguments CONTENT and POS can be used to fill the cached
213 content and cursor position fields of the node."
214 (list parent address getter content pos))
216 (defun elpher-node-parent (node)
217 "Retrieve the parent node of NODE."
220 (defun elpher-node-address (node)
221 "Retrieve the address of NODE."
224 (defun elpher-node-getter (node)
225 "Retrieve the preferred getter function of NODE."
228 (defun elpher-node-content (node)
229 "Retrieve the cached content of NODE, or nil if none exists."
232 (defun elpher-node-pos (node)
233 "Retrieve the cached cursor position for NODE, or nil if none exists."
236 (defun elpher-set-node-content (node content)
237 "Set the content cache of NODE to CONTENT."
238 (setcar (nthcdr 3 node) content))
240 (defun elpher-set-node-pos (node pos)
241 "Set the cursor position cache of NODE to POS."
242 (setcar (nthcdr 4 node) pos))
244 ;; Node graph traversal
246 (defvar elpher-current-node nil)
248 (defun elpher-visit-node (node &optional getter)
249 "Visit NODE using its own getter or GETTER, if non-nil."
251 (elpher-process-cleanup)
252 (setq elpher-current-node node)
255 (funcall (elpher-node-getter node))))
257 (defun elpher-visit-parent-node ()
258 "Visit the parent of the current node."
259 (let ((parent-node (elpher-node-parent elpher-current-node)))
261 (elpher-visit-node parent-node))))
263 (defun elpher-reload-current-node ()
264 "Reload the current node, discarding any existing cached content."
265 (elpher-set-node-content elpher-current-node nil)
266 (elpher-visit-node elpher-current-node))
268 (defun elpher-save-pos ()
269 "Save the current position of point to the current node."
270 (when elpher-current-node
271 (elpher-set-node-pos elpher-current-node (point))))
273 (defun elpher-restore-pos ()
274 "Restore the position of point to that cached in the current node."
275 (let ((pos (elpher-node-pos elpher-current-node)))
278 (goto-char (point-min)))))
281 ;;; Buffer preparation
284 (defmacro elpher-with-clean-buffer (&rest args)
285 "Evaluate ARGS with a clean *elpher* buffer as current."
286 (list 'with-current-buffer "*elpher*"
288 (append (list 'let '((inhibit-read-only t))
296 (defun elpher-insert-index (string)
297 "Insert the index corresponding to STRING into the current buffer."
298 ;; Should be able to split directly on CRLF, but some non-conformant
299 ;; LF-only servers sadly exist, hence the following.
300 (let* ((str-no-period (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string))
301 (str-no-cr (replace-regexp-in-string "\r" "" str-no-period)))
302 (dolist (line (split-string str-no-cr "\n"))
303 (unless (= (length line) 0)
304 (elpher-insert-index-record line)))))
306 (defun elpher-insert-margin (&optional type-name)
307 "Insert index margin, optionally containing the TYPE-NAME, into the current buffer."
310 (insert (format (concat "%" (number-to-string (- elpher-margin-width 1)) "s")
312 (propertize "[" 'face 'elpher-margin-brackets)
313 (propertize type-name 'face 'elpher-margin-key)
314 (propertize "]" 'face 'elpher-margin-brackets))))
316 (insert (make-string elpher-margin-width ?\s))))
318 (defun elpher-insert-index-record (line)
319 "Insert the index record corresponding to LINE into the current buffer."
320 (let* ((type (elt line 0))
321 (fields (split-string (substring line 1) "\t"))
322 (display-string (elt fields 0))
323 (selector (elt fields 1))
324 (host (elt fields 2))
325 (port (elt fields 3)))
326 (elpher-insert-index-record-helper type display-string selector host port)))
328 (defun elpher-insert-index-record-helper (type display-string selector host port)
329 (let ((address (elpher-make-address selector host port))
330 (type-map-entry (alist-get type elpher-type-map)))
332 (let ((getter (car type-map-entry))
333 (margin-code (cadr type-map-entry))
334 (face (caddr type-map-entry)))
335 (elpher-insert-margin margin-code)
336 (insert-text-button display-string
338 'elpher-node (elpher-make-node elpher-current-node
341 'elpher-node-type type
342 'action #'elpher-click-link
344 'help-echo (format "mouse-1, RET: open '%s' on %s port %s"
345 selector host port)))
347 (?i (elpher-insert-margin) ;; Information
349 (if elpher-buttonify-urls-in-directories
350 (elpher-buttonify-urls display-string)
352 'face 'elpher-info)))
353 (?h (elpher-insert-margin "W") ;; Web link
354 (let ((url (elt (split-string selector "URL:") 1)))
355 (insert-text-button display-string
358 'action #'elpher-click-url
360 'help-echo (format "mouse-1, RET: open url %s" url))))
361 (tp (elpher-insert-margin (concat (char-to-string tp) "?"))
362 (insert (propertize display-string
363 'face 'elpher-unknown-face)))))
366 (defun elpher-click-link (button)
367 "Function called when the gopher link BUTTON is activated (via mouse or keypress)."
368 (let ((node (button-get button 'elpher-node)))
369 (elpher-visit-node node)))
371 (defun elpher-click-url (button)
372 "Function called when the url link BUTTON is activated (via mouse or keypress)."
373 (let ((url (button-get button 'elpher-url)))
374 (if elpher-open-urls-with-eww
379 ;;; Selector retrieval (all kinds)
382 (defun elpher-process-cleanup ()
383 "Immediately shut down any extant elpher process."
384 (let ((p (get-process "elpher-process")))
385 (if p (delete-process p))))
387 (defvar elpher-selector-string)
389 (defun elpher-get-selector (address after)
390 "Retrieve selector specified by ADDRESS, then execute AFTER.
391 The result is stored as a string in the variable ‘elpher-selector-string’."
392 (setq elpher-selector-string "")
393 (make-network-process
394 :name "elpher-process"
395 :host (elpher-address-host address)
396 :service (elpher-address-port address)
397 :filter (lambda (proc string)
398 (setq elpher-selector-string (concat elpher-selector-string string)))
400 (process-send-string "elpher-process"
401 (concat (elpher-address-selector address) "\n")))
405 (defun elpher-get-index-node ()
406 "Getter which retrieves the current node contents as an index."
407 (let ((content (elpher-node-content elpher-current-node))
408 (address (elpher-node-address elpher-current-node)))
411 (elpher-with-clean-buffer
413 (elpher-restore-pos)))
416 (elpher-with-clean-buffer
417 (insert "LOADING DIRECTORY..."))
418 (elpher-get-selector address
420 (unless (string-prefix-p "deleted" event)
421 (elpher-with-clean-buffer
422 (elpher-insert-index elpher-selector-string)
424 (elpher-set-node-content elpher-current-node
425 (buffer-string)))))))
427 (elpher-with-clean-buffer
428 (elpher-insert-index elpher-start-index)
430 (elpher-set-node-content elpher-current-node
431 (buffer-string))))))))
435 (defconst elpher-url-regex
436 "\\(https?\\|gopher\\)://\\([a-zA-Z0-9.\-]+\\)\\(?3::[0-9]+\\)?\\(?4:/[^ \r\n\t(),]*\\)?"
437 "Regexp used to locate and buttinofy URLs in text files loaded by elpher.")
439 (defun elpher-buttonify-urls (string)
440 "Turn substrings which look like urls in STRING into clickable buttons."
443 (goto-char (point-min))
444 (while (re-search-forward elpher-url-regex nil t)
445 (let ((url (match-string 0))
446 (protocol (downcase (match-string 1))))
447 (if (string= protocol "gopher")
448 (let* ((host (match-string 2))
450 (type-and-selector (match-string 4))
451 (type (if (> (length type-and-selector) 1)
452 (elt type-and-selector 1)
454 (selector (if (> (length type-and-selector) 1)
455 (substring type-and-selector 2)
457 (address (elpher-make-address selector host port))
458 (getter (car (alist-get type elpher-type-map))))
459 (make-text-button (match-beginning 0)
461 'elpher-node (elpher-make-node elpher-current-node
464 'action #'elpher-click-link
466 'help-echo (format "mouse-1, RET: open '%s' on %s port %s"
467 selector host port)))
468 (make-text-button (match-beginning 0)
471 'action #'elpher-click-url
473 'help-echo (format "mouse-1, RET: open url %s" url)))))
476 (defun elpher-process-text (string)
477 "Remove CRs and trailing period from the gopher text document STRING."
478 (let* ((chopped-str (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string))
479 (cleaned-str (replace-regexp-in-string "\r" "" chopped-str)))
480 (elpher-buttonify-urls cleaned-str)))
482 (defun elpher-get-text-node ()
483 "Getter which retrieves the current node contents as a text document."
484 (let ((content (elpher-node-content elpher-current-node))
485 (address (elpher-node-address elpher-current-node)))
488 (elpher-with-clean-buffer
490 (elpher-restore-pos)))
492 (elpher-with-clean-buffer
493 (insert "LOADING TEXT..."))
494 (elpher-get-selector address
496 (unless (string-prefix-p "deleted" event)
497 (elpher-with-clean-buffer
498 (insert (elpher-process-text elpher-selector-string))
500 (elpher-set-node-content elpher-current-node
501 (buffer-string))))))))))
505 (defun elpher-get-image-node ()
506 "Getter which retrieves the current node contents as an image to view."
507 (let ((content (elpher-node-content elpher-current-node))
508 (address (elpher-node-address elpher-current-node)))
511 (elpher-with-clean-buffer
512 (insert-image content)
513 (elpher-restore-pos)))
514 (if (display-images-p)
516 (elpher-with-clean-buffer
517 (insert "LOADING IMAGE..."))
518 (elpher-get-selector address
520 (unless (string-prefix-p "deleted" event)
521 (let ((image (create-image
522 (encode-coding-string elpher-selector-string
525 (elpher-with-clean-buffer
527 (elpher-restore-pos))
528 (if elpher-cache-images
529 (elpher-set-node-content elpher-current-node
531 (elpher-get-node-download)))))
535 (defun elpher-get-search-node ()
536 "Getter which submits a search query to the address of the current node."
537 (let ((content (elpher-node-content elpher-current-node))
538 (address (elpher-node-address elpher-current-node))
542 (elpher-with-clean-buffer
544 (elpher-restore-pos))
545 (message "Displaying cached search results. Reload to perform a new search."))
547 (let* ((query-string (read-string "Query: "))
548 (query-selector (concat (elpher-address-selector address) "\t" query-string))
549 (search-address (elpher-make-address query-selector
550 (elpher-address-host address)
551 (elpher-address-port address))))
553 (elpher-with-clean-buffer
554 (insert "LOADING RESULTS..."))
555 (elpher-get-selector search-address
557 (unless (string-prefix-p "deleted" event)
558 (elpher-with-clean-buffer
559 (elpher-insert-index elpher-selector-string))
560 (goto-char (point-min))
561 (elpher-set-node-content elpher-current-node
564 (elpher-visit-parent-node))))))
566 ;; Raw server response retrieval
568 (defun elpher-get-node-raw ()
569 "Getter which retrieves the raw server response for the current node."
570 (let* ((content (elpher-node-content elpher-current-node))
571 (address (elpher-node-address elpher-current-node)))
572 (elpher-with-clean-buffer
573 (insert "LOADING RAW SERVER RESPONSE..."))
575 (elpher-get-selector address
577 (unless (string-prefix-p "deleted" event)
578 (elpher-with-clean-buffer
579 (insert elpher-selector-string)
580 (goto-char (point-min))))))
582 (elpher-with-clean-buffer
583 (insert elpher-start-index))
584 (goto-char (point-min)))))
585 (message "Displaying raw server response. Reload or redraw to return to standard view."))
587 ;; File export retrieval
589 (defvar elpher-download-filename)
591 (defun elpher-get-node-download ()
592 "Getter which retrieves the current node and writes the result to a file."
593 (let* ((address (elpher-node-address elpher-current-node))
594 (selector (elpher-address-selector address)))
595 (elpher-visit-parent-node) ; Do first in case of non-local exits.
596 (let* ((filename-proposal (file-name-nondirectory selector))
597 (filename (read-file-name "Save file as: "
599 (if (> (length filename-proposal) 0)
602 (message "Downloading...")
603 (setq elpher-download-filename filename)
604 (elpher-get-selector address
606 (let ((coding-system-for-write 'binary))
607 (with-temp-file elpher-download-filename
608 (insert elpher-selector-string)
609 (message (format "Download complate, saved to file %s."
610 elpher-download-filename)))))))))
615 (defun elpher-make-bookmark (type display-string address)
616 (list type display-string address))
618 (defun elpher-bookmark-type (bookmark)
621 (defun elpher-bookmark-display-string (bookmark)
624 (defun elpher-bookmark-address (bookmark)
627 (defun elpher-save-bookmarks (bookmarks)
628 (with-temp-file (locate-user-emacs-file "elpher-bookmarks")
630 (pp bookmarks (current-buffer))))
632 (defun elpher-load-bookmarks ()
635 (insert-file-contents (locate-user-emacs-file "elpher-bookmarks"))
636 (goto-char (point-min))
637 (read (current-buffer)))))
639 (defun elpher-add-bookmark (bookmark)
640 (let ((bookmarks (elpher-load-bookmarks)))
641 (add-to-list 'bookmarks bookmark)
642 (elpher-save-bookmarks bookmarks)))
644 (defun elpher-remove-bookmark (bookmark)
645 (elpher-save-bookmarks
646 (seq-filter (lambda (this-bookmark)
647 (not (equal bookmark this-bookmark)))
648 (elpher-load-bookmarks))))
650 (defun elpher-display-bookmarks ()
652 (elpher-with-clean-buffer
654 "Use 'u' to return to the previous page.\n\n"
655 "---- Bookmark list ----\n\n")
656 (let ((bookmarks (elpher-load-bookmarks)))
658 (dolist (bookmark (elpher-load-bookmarks))
659 (let ((type (elpher-bookmark-type bookmark))
660 (display-string (elpher-bookmark-display-string bookmark))
661 (address (elpher-bookmark-address bookmark)))
662 (elpher-insert-index-record-helper type display-string
663 (elpher-address-selector address)
664 (elpher-address-host address)
665 (elpher-address-port address))))
666 (insert "No bookmarks found.\n")))
667 (insert "\n-----------------------")
668 (goto-char (point-min))
671 (defun elpher-bookmark-link ()
672 "Bookmark the link at point."
674 (let ((button (button-at (point))))
676 (let ((node (button-get button 'elpher-node))
677 (type (button-get button 'elpher-node-type))
678 (label (button-label button)))
682 (elpher-make-bookmark type
684 (elpher-node-address node)))
685 (message "Bookmarked \"%s\"" label))
686 (error "Can only bookmark gopher links, not general URLs.")))
687 (error "No link selected."))))
689 (defun elpher-unbookmark-link ()
690 "Remove bookmark for the link at point."
692 (let ((button (button-at (point))))
694 (let ((node (button-get button 'elpher-node))
695 (type (button-get button 'elpher-node-type)))
697 (elpher-remove-bookmark
698 (elpher-make-bookmark type
699 (button-label button)
700 (elpher-node-address node)))
701 (error "Can only bookmark gopher links, not general URLs.")))
702 (error "No link selected."))))
704 ;;; Interactive navigation procedures
707 (defun elpher-next-link ()
708 "Move point to the next link on the current page."
712 (defun elpher-prev-link ()
713 "Move point to the previous link on the current page."
717 (defun elpher-follow-current-link ()
718 "Open the link or url at point."
723 "Go to a particular gopher site."
725 (switch-to-buffer "*elpher*")
727 (hostname (read-string "Gopher host: "))
728 (selector (read-string "Selector (default none): " nil nil ""))
729 (port (read-string "Port (default 70): " nil nil 70))
730 (address (list selector hostname port)))
732 (elpher-make-node elpher-current-node
734 #'elpher-get-index-node))))
736 (defun elpher-redraw ()
737 "Redraw current page."
739 (if elpher-current-node
740 (elpher-visit-node elpher-current-node)
741 (message "No current site.")))
743 (defun elpher-reload ()
744 "Reload current page."
746 (if elpher-current-node
747 (elpher-reload-current-node)
748 (message "No current site.")))
750 (defun elpher-view-raw ()
751 "View current page as plain text."
753 (if elpher-current-node
754 (elpher-visit-node elpher-current-node
755 #'elpher-get-node-raw)
756 (message "No current site.")))
758 (defun elpher-back ()
759 "Go to previous site."
761 (if (elpher-node-parent elpher-current-node)
762 (elpher-visit-parent-node)
763 (error "No previous site.")))
765 (defun elpher-download ()
766 "Download the link at point."
768 (let ((button (button-at (point))))
770 (let ((node (button-get button 'elpher-node)))
772 (elpher-visit-node (button-get button 'elpher-node)
773 #'elpher-get-node-download)
774 (error "Can only download gopher links, not general URLs.")))
775 (error "No link selected."))))
777 (defun elpher-build-link-map ()
778 "Build alist mapping link names to destination nodes in current buffer."
780 (b (next-button (point-min) t)))
782 (add-to-list 'link-map (cons (button-label b) b))
783 (setq b (next-button (button-start b))))
786 (defun elpher-menu ()
787 "Select a directory entry by name. Similar to the info browser (m)enu command."
789 (let* ((link-map (elpher-build-link-map)))
791 (let ((key (let ((completion-ignore-case t))
792 (completing-read "Directory entry/link (tab to autocomplete): "
794 (if (and key (> (length key) 0))
795 (let ((b (cdr (assoc key link-map))))
796 (goto-char (button-start b))
797 (button-activate b)))))))
799 (defun elpher-root-dir ()
800 "Visit root of current server."
802 (let ((address (elpher-node-address elpher-current-node)))
804 (let ((host (elpher-address-host address))
805 (selector (elpher-address-selector address))
806 (port (elpher-address-port address)))
807 (if (> (length selector) 0)
808 (let ((root-address (elpher-make-address "" host port)))
809 (elpher-visit-node (elpher-make-node elpher-current-node
811 #'elpher-get-index-node)))
812 (error "Already at root directory of current server.")))
813 (error "Command invalid for Elpher start page."))))
819 (defvar elpher-mode-map
820 (let ((map (make-sparse-keymap)))
821 (define-key map (kbd "TAB") 'elpher-next-link)
822 (define-key map (kbd "<backtab>") 'elpher-prev-link)
823 (define-key map (kbd "u") 'elpher-back)
824 (define-key map (kbd "O") 'elpher-root-dir)
825 (define-key map (kbd "g") 'elpher-go)
826 (define-key map (kbd "r") 'elpher-redraw)
827 (define-key map (kbd "R") 'elpher-reload)
828 (define-key map (kbd "w") 'elpher-view-raw)
829 (define-key map (kbd "d") 'elpher-download)
830 (define-key map (kbd "m") 'elpher-menu)
831 (when (fboundp 'evil-define-key)
832 (add-to-list 'evil-motion-state-modes 'elpher-mode)
833 (evil-define-key 'motion map
834 (kbd "TAB") 'elpher-next-link
835 (kbd "C-]") 'elpher-follow-current-link
836 (kbd "C-t") 'elpher-back
837 (kbd "u") 'elpher-back
838 (kbd "O") 'elpher-root-dir
840 (kbd "r") 'elpher-redraw
841 (kbd "R") 'elpher-reload
842 (kbd "w") 'elpher-view-raw
843 (kbd "d") 'elpher-download
844 (kbd "m") 'elpher-menu
845 (kbd "a") 'elpher-bookmark-link
846 (kbd "x") 'elpher-unbookmark-link
847 (kbd "B") 'elpher-display-bookmarks))
849 "Keymap for gopher client.")
851 (define-derived-mode elpher-mode special-mode "elpher"
852 "Major mode for elpher, an elisp gopher client.")
855 ;;; Main start procedure
860 "Start elpher with default landing page."
862 (if (get-buffer "*elpher*")
863 (switch-to-buffer "*elpher*")
864 (switch-to-buffer "*elpher*")
865 (setq elpher-current-node nil)
866 (let ((start-node (elpher-make-node nil
868 #'elpher-get-index-node)))
869 (elpher-visit-node start-node)))
870 "Started Elpher.") ; Otherwise (elpher) evaluates to start page string.
872 ;;; elpher.el ends here