Fleshed out commentry.
[elpher.git] / elpher.el
1 ;;; elpher.el --- Full-featured gopher client.
2
3 ;; Copyright (C) 2019 Tim Vaughan
4
5 ;; Author: Tim Vaughan <tgvaughan@gmail.com>
6 ;; Created: 11 April 2019
7 ;; Version: 1.0.0
8 ;; Keywords: comm gopher
9 ;; Homepage: https://github.com/tgvaughan/elpher
10 ;; Package-Requires: ((emacs "25"))
11
12 ;; This file is not part of GNU Emacs.
13
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.
18
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.
23
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/>.
26
27 ;;; Commentary:
28
29 ;; Elpher aims to provide a full-featured gopher client for GNU Emacs.
30 ;; It supports:
31
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 ;; - clickable web and gopher links in plain text.
37
38 ;; The caching mechanism works by maintaining a hierarchy of visited
39 ;; pages rather than a linear history, meaning that it is quick and
40 ;; easy to navigate this history.
41
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.
45
46 ;;; Code:
47
48 (provide 'elpher)
49
50 ;;; Global constants
51 ;;
52
53 (defconst elpher-version "1.0.0"
54   "Current version of elpher.")
55
56 (defconst elpher-margin-width 6
57   "Width of left-hand margin used when rendering indicies.")
58
59 (defconst elpher-start-index
60   (mapconcat
61    'identity
62    (list "i\tfake\tfake\t1"
63          "i--------------------------------------------\tfake\tfake\t1"
64          "i           Elpher Gopher Client             \tfake\tfake\t1"
65          (format "i              version %s\tfake\tfake\t1" elpher-version)
66          "i--------------------------------------------\tfake\tfake\t1"
67          "i\tfake\tfake\t1"
68          "iBasic usage:\tfake\tfake\t1"
69          "i\tfake\tfake\t1"
70          "i - tab/shift-tab: next/prev directory entry on current page\tfake\tfake\t1"
71          "i - RET/mouse-1: open directory entry under cursor\tfake\tfake\t1"
72          "i - u: return to parent directory entry\tfake\tfake\t1"
73          "i - g: go to a particular page\tfake\tfake\t1"
74          "i - r: redraw current page (using cached contents if available)\tfake\tfake\t1"
75          "i - R: reload current page (regenerates cache)\tfake\tfake\t1"
76          "i - d: download directory entry under cursor\tfake\tfake\t1"
77          "i - w: display the raw server response for the current page\tfake\tfake\t1"
78          "i\tfake\tfake\t1"
79          "iPlaces to start exploring Gopherspace:\tfake\tfake\t1"
80          "i\tfake\tfake\t1"
81          "1Floodgap Systems Gopher Server\t\tgopher.floodgap.com\t70"
82          "i\tfake\tfake\t1"
83          "iAlternatively, select the following item and enter some\tfake\tfake\t1"
84          "isearch terms:\tfake\tfake\t1"
85          "i\tfake\tfake\t1"
86          "7Veronica-2 Gopher Search Engine\t/v2/vs\tgopher.floodgap.com\t70"
87          ".")
88    "\r\n")
89   "Source for elpher start page.")
90
91 (defconst elpher-type-map
92   '((?0 elpher-get-text-node "T" elpher-text)
93     (?1 elpher-get-index-node "/" elpher-index)
94     (?g elpher-get-image-node "im" elpher-image)
95     (?p elpher-get-image-node "im" elpher-image)
96     (?I elpher-get-image-node "im" elpher-image)
97     (?4 elpher-get-node-download "B" elpher-binary)
98     (?5 elpher-get-node-download "B" elpher-binary)
99     (?9 elpher-get-node-download "B" elpher-binary)
100     (?7 elpher-get-search-node "?" elpher-search))
101   "Association list from types to getters, margin codes and index faces.")
102
103
104 ;;; Customization group
105 ;;
106
107 (defgroup elpher nil
108   "A gopher client."
109   :group 'applications)
110
111 (defface elpher-index
112   '((((background dark)) :foreground "deep sky blue")
113     (((background light)) :foreground "blue"))
114   "Face used for index records.")
115
116 (defface elpher-text
117   '((((background dark)) :foreground "white")
118     (((background light)) :weight bold))
119   "Face used for text records.")
120
121 (defface elpher-info '()
122   "Face used for info records.")
123
124 (defface elpher-image
125   '((((background dark)) :foreground "green")
126     (t :foreground "dark green"))
127   "Face used for image records.")
128
129 (defface elpher-search
130   '((((background light)) :foreground "orange")
131     (((background dark)) :foreground "dark orange"))
132   "Face used for search records.")
133
134 (defface elpher-url
135   '((((background dark)) :foreground "yellow")
136     (((background light)) :foreground "dark red"))
137   "Face used for url records.")
138
139 (defface elpher-binary
140   '((t :foreground "magenta"))
141   "Face used for binary records.")
142
143 (defface elpher-unknown
144   '((t :foreground "red"))
145   "Face used for unknown record types.")
146
147 (defface elpher-margin-key
148   '((((background dark)) :foreground "white"))
149   "Face used for margin key.")
150
151 (defface elpher-margin-brackets
152   '((t :foreground "blue"))
153   "Face used for brackets around margin key.")
154
155 (defcustom elpher-open-urls-with-eww nil
156   "If non-nil, open URL selectors using eww.
157 Otherwise, use the system browser via the BROWSE-URL function."
158   :type '(boolean))
159
160 (defcustom elpher-cache-images nil
161   "If non-nil, cache images in memory in the same way as other content."
162   :type '(boolean))
163
164 ;;; Model
165 ;;
166
167 ;; Address
168
169 (defun elpher-make-address (selector host port)
170   "Create an address of a gopher object with SELECTOR, HOST and PORT."
171   (list selector host port))
172
173 (defun elpher-address-selector (address)
174   "Retrieve selector from ADDRESS."
175   (car address))
176
177 (defun elpher-address-host (address)
178   "Retrieve host from ADDRESS."
179   (cadr address))
180
181 (defun elpher-address-port (address)
182   "Retrieve port from ADDRESS."
183   (caddr address))
184
185 ;; Node
186
187 (defun elpher-make-node (parent address getter &optional content pos)
188   "Create a node in the gopher page hierarchy.
189
190 PARENT specifies the parent of the node, ADDRESS specifies the address of
191 the gopher page, GETTER provides the getter function used to obtain this
192 page.
193
194 The optional arguments CONTENT and POS can be used to fill the cached
195 content and cursor position fields of the node."
196   (list parent address getter content pos))
197
198 (defun elpher-node-parent (node)
199   "Retrieve the parent node of NODE."
200   (elt node 0))
201
202 (defun elpher-node-address (node)
203   "Retrieve the address of NODE."
204   (elt node 1))
205
206 (defun elpher-node-getter (node)
207   "Retrieve the preferred getter function of NODE."
208   (elt node 2))
209
210 (defun elpher-node-content (node)
211   "Retrieve the cached content of NODE, or nil if none exists."
212   (elt node 3))
213
214 (defun elpher-node-pos (node)
215   "Retrieve the cached cursor position for NODE, or nil if none exists."
216   (elt node 4))
217
218 (defun elpher-set-node-content (node content)
219   "Set the content cache of NODE to CONTENT."
220   (setcar (nthcdr 3 node) content))
221
222 (defun elpher-set-node-pos (node pos)
223   "Set the cursor position cache of NODE to POS."
224   (setcar (nthcdr 4 node) pos))
225
226 ;; Node graph traversal
227
228 (defvar elpher-current-node)
229
230 (defun elpher-visit-node (node &optional getter)
231   "Visit NODE using its own getter or GETTER, if non-nil."
232   (elpher-save-pos)
233   (elpher-process-cleanup)
234   (setq elpher-current-node node)
235   (if getter
236       (funcall getter)
237     (funcall (elpher-node-getter node))))
238
239 (defun elpher-visit-parent-node ()
240   "Visit the parent of the current node."
241   (let ((parent-node (elpher-node-parent elpher-current-node)))
242     (when parent-node
243       (elpher-visit-node parent-node))))
244       
245 (defun elpher-reload-current-node ()
246   "Reload the current node, discarding any existing cached content."
247   (elpher-set-node-content elpher-current-node nil)
248   (elpher-visit-node elpher-current-node))
249
250 (defun elpher-save-pos ()
251   "Save the current position of point to the current node."
252   (when elpher-current-node
253     (elpher-set-node-pos elpher-current-node (point))))
254
255 (defun elpher-restore-pos ()
256   "Restore the position of point to that cached in the current node."
257   (let ((pos (elpher-node-pos elpher-current-node)))
258     (if pos
259         (goto-char pos)
260       (goto-char (point-min)))))
261
262 ;;; Buffer preparation
263 ;;
264
265 (defmacro elpher-with-clean-buffer (&rest args)
266   "Evaluate ARGS with a clean *elpher* buffer as current."
267   (list 'progn
268         '(switch-to-buffer "*elpher*")
269         '(elpher-mode)
270         (append (list 'let '((inhibit-read-only t))
271                       '(erase-buffer))
272                 args)))
273
274 ;;; Index rendering
275 ;;
276
277 (defun elpher-insert-index (string)
278   "Insert the index corresponding to STRING into the current buffer."
279   (dolist (line (split-string string "\r\n"))
280     (unless (= (length line) 0)
281       (elpher-insert-index-record line))))
282
283 (defun elpher-insert-margin (&optional type-name)
284   "Insert index margin, optionally containing the TYPE-NAME, into the current buffer."
285   (if type-name
286       (progn
287         (insert (format (concat "%" (number-to-string (- elpher-margin-width 1)) "s")
288                         (concat
289                          (propertize "[" 'face 'elpher-margin-brackets)
290                          (propertize type-name 'face 'elpher-margin-key)
291                          (propertize "]" 'face 'elpher-margin-brackets))))
292         (insert " "))
293     (insert (make-string elpher-margin-width ?\s))))
294
295 (defun elpher-insert-index-record (line)
296   "Insert the index record corresponding to LINE into the current buffer."
297   (let* ((type (elt line 0))
298          (fields (split-string (substring line 1) "\t"))
299          (display-string (elt fields 0))
300          (selector (elt fields 1))
301          (host (elt fields 2))
302          (port (elt fields 3))
303          (address (elpher-make-address selector host port))
304          (type-map-entry (alist-get type elpher-type-map)))
305     (if type-map-entry
306         (let ((getter (car type-map-entry))
307               (margin-code (cadr type-map-entry))
308               (face (caddr type-map-entry)))
309           (elpher-insert-margin margin-code)
310           (insert-text-button display-string
311                               'face face
312                               'elpher-node (elpher-make-node elpher-current-node
313                                                                address
314                                                                getter)
315                               'action #'elpher-click-link
316                               'follow-link t
317                               'help-echo (format "mouse-1, RET: open %s on %s port %s"
318                                                  selector host port)))
319       (pcase type
320         (?i (elpher-insert-margin) ; Information
321             (insert (propertize display-string
322                                 'face 'elpher-info)))
323         (?h (elpher-insert-margin "W") ; Web link
324             (let ((url (elt (split-string selector "URL:") 1)))
325               (insert-text-button display-string
326                                   'face 'elpher-url
327                                   'elpher-url url
328                                   'action #'elpher-click-url
329                                   'follow-link t
330                                   'help-echo (format "mouse-1, RET: open url %s" url))))
331         (?.) ; Occurs at end of index, can safely ignore.
332         (tp (elpher-insert-margin (concat (char-to-string tp) "?"))
333             (insert (propertize display-string
334                                 'face 'elpher-unknown-face)))))
335     (insert "\n")))
336
337
338 ;;; Selector retrieval (all kinds)
339 ;;
340
341 (defun elpher-process-cleanup ()
342   "Immediately shut down any extant elpher process."
343   (let ((p (get-process "elpher-process")))
344     (if p (delete-process p))))
345
346 (defvar elpher-selector-string)
347
348 (defun elpher-get-selector (address after)
349   "Retrieve selector specified by ADDRESS, then execute AFTER.
350 The result is stored as a string in the variable â€˜elpher-selector-string’."
351   (setq elpher-selector-string "")
352   (make-network-process
353    :name "elpher-process"
354    :host (elpher-address-host address)
355    :service (elpher-address-port address)
356    :filter (lambda (proc string)
357              (setq elpher-selector-string (concat elpher-selector-string string)))
358    :sentinel after)
359   (process-send-string "elpher-process"
360                        (concat (elpher-address-selector address) "\n")))
361
362 ;; Index retrieval
363
364 (defun elpher-get-index-node ()
365   "Getter which retrieves the current node contents as an index."
366   (let ((content (elpher-node-content elpher-current-node))
367         (address (elpher-node-address elpher-current-node)))
368     (if content
369         (progn
370           (elpher-with-clean-buffer
371            (insert content))
372           (elpher-restore-pos))
373       (if address
374           (progn
375             (elpher-with-clean-buffer
376              (insert "LOADING DIRECTORY..."))
377             (elpher-get-selector address
378                                   (lambda (proc event)
379                                     (unless (string-prefix-p "deleted" event)
380                                       (elpher-with-clean-buffer
381                                        (elpher-insert-index elpher-selector-string))
382                                       (elpher-restore-pos)
383                                       (elpher-set-node-content elpher-current-node
384                                                                 (buffer-string))))))
385         (progn
386           (elpher-with-clean-buffer
387            (elpher-insert-index elpher-start-index))
388           (elpher-restore-pos)
389           (elpher-set-node-content elpher-current-node
390                                     (buffer-string)))))))
391
392 ;; Text retrieval
393
394 (defconst elpher-url-regex
395   "\\(https?\\|gopher\\)://\\([a-zA-Z0-9.\-]+\\)\\(?3::[0-9]+\\)?\\(?4:/[^ \r\n\t(),]*\\)?"
396   "Regexp used to locate and buttinofy URLs in text files loaded by elpher.")
397
398 (defun elpher-buttonify-urls (string)
399   "Turn substrings which look like urls in STRING into clickable buttons."
400   (with-temp-buffer
401     (insert string)
402     (goto-char (point-min))
403     (while (re-search-forward elpher-url-regex nil t)
404       (let ((url (match-string 0))
405             (protocol (downcase (match-string 1))))
406         (if (string= protocol "gopher")
407             (let* ((host (match-string 2))
408                    (port 70)
409                    (type-and-selector (match-string 4))
410                    (type (if (> (length type-and-selector) 1)
411                              (elt type-and-selector 1)
412                            ?1))
413                    (selector (if (> (length type-and-selector) 1)
414                                  (substring type-and-selector 2)
415                                ""))
416                    (address (elpher-make-address selector host port))
417                    (getter (car (alist-get type elpher-type-map))))
418               (make-text-button (match-beginning 0)
419                                 (match-end 0)
420                                 'elpher-node (elpher-make-node elpher-current-node
421                                                                  address
422                                                                  getter)
423                                 'action #'elpher-click-link
424                                 'follow-link t
425                                 'help-echo (format "mouse-1, RET: open %s on %s port %s"
426                                                    selector host port)))
427           (make-text-button (match-beginning 0)
428                             (match-end 0)
429                             'elpher-url url
430                             'action #'elpher-click-url
431                             'follow-link t
432                             'help-echo (format "mouse-1, RET: open url %s" url)))))
433     (buffer-string)))
434
435 (defun elpher-process-text (string)
436   "Remove CRs and trailing period from the gopher text document STRING."
437   (let* ((chopped-str (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string))
438          (cleaned-str (replace-regexp-in-string "\r" "" chopped-str)))
439     (elpher-buttonify-urls cleaned-str)))
440
441 (defun elpher-get-text-node ()
442   "Getter which retrieves the current node contents as a text document."
443   (let ((content (elpher-node-content elpher-current-node))
444         (address (elpher-node-address elpher-current-node)))
445     (if content
446         (progn
447           (elpher-with-clean-buffer
448            (insert content))
449           (elpher-restore-pos))
450       (progn
451         (elpher-with-clean-buffer
452          (insert "LOADING TEXT..."))
453         (elpher-get-selector address
454                               (lambda (proc event)
455                                 (unless (string-prefix-p "deleted" event)
456                                   (elpher-with-clean-buffer
457                                    (insert (elpher-process-text elpher-selector-string)))
458                                   (elpher-restore-pos)
459                                   (elpher-set-node-content elpher-current-node
460                                                             (buffer-string)))))))))
461
462 ;; Image retrieval
463
464 (defun elpher-get-image-node ()
465   "Getter which retrieves the current node contents as an image to view."
466   (let ((content (elpher-node-content elpher-current-node))
467         (address (elpher-node-address elpher-current-node)))
468     (if content
469         (progn
470           (elpher-with-clean-buffer
471            (insert-image content))
472           (setq cursor-type nil)
473           (elpher-restore-pos))
474       (if (display-images-p)
475           (progn
476             (elpher-with-clean-buffer
477              (insert "LOADING IMAGE..."))
478             (elpher-get-selector address
479                                  (lambda (proc event)
480                                    (unless (string-prefix-p "deleted" event)
481                                      (let ((image (create-image
482                                                    (encode-coding-string elpher-selector-string
483                                                                          'no-conversion)
484                                                    nil t)))
485                                        (elpher-with-clean-buffer
486                                         (insert-image image))
487                                        (setq cursor-type nil)
488                                        (elpher-restore-pos)
489                                        (if elpher-cache-images
490                                            (elpher-set-node-content elpher-current-node
491                                                                     image)))))))
492         (elpher-get-node-download)))))
493
494 ;; Search retrieval
495
496 (defun elpher-get-search-node ()
497   "Getter which submits a search query to the address of the current node."
498   (let ((content (elpher-node-content elpher-current-node))
499         (address (elpher-node-address elpher-current-node))
500         (aborted t))
501     (if content
502         (progn
503           (elpher-with-clean-buffer
504            (insert content))
505           (elpher-restore-pos)
506           (message "Displaying cached search results.  Reload to perform a new search."))
507       (unwind-protect
508           (let* ((query-string (read-string "Query: "))
509                  (query-selector (concat (elpher-address-selector address) "\t" query-string))
510                  (search-address (elpher-make-address query-selector
511                                                        (elpher-address-host address)
512                                                        (elpher-address-port address))))
513             (setq aborted nil)
514             (elpher-with-clean-buffer
515              (insert "LOADING RESULTS..."))
516             (elpher-get-selector search-address
517                                   (lambda (proc event)
518                                     (unless (string-prefix-p "deleted" event)
519                                       (elpher-with-clean-buffer
520                                        (elpher-insert-index elpher-selector-string))
521                                       (goto-char (point-min))
522                                       (elpher-set-node-content elpher-current-node
523                                                                 (buffer-string))))))
524         (if aborted
525             (elpher-visit-parent-node))))))
526
527 ;; Raw server response retrieval
528
529 (defun elpher-get-node-raw ()
530   "Getter which retrieves the raw server response for the current node."
531   (let* ((content (elpher-node-content elpher-current-node))
532          (address (elpher-node-address elpher-current-node)))
533     (elpher-with-clean-buffer
534      (insert "LOADING RAW SERVER RESPONSE..."))
535     (if address
536         (elpher-get-selector address
537                               (lambda (proc event)
538                                 (unless (string-prefix-p "deleted" event)
539                                   (elpher-with-clean-buffer
540                                    (insert elpher-selector-string))
541                                   (goto-char (point-min)))))
542       (progn
543         (elpher-with-clean-buffer
544          (insert elpher-start-index))
545         (goto-char (point-min)))))
546   (message "Displaying raw server response.  Reload or redraw to return to standard view."))
547  
548 ;; File export retrieval
549
550 (defvar elpher-download-filename)
551
552 (defun elpher-get-node-download ()
553   "Getter which retrieves the current node and writes the result to a file."
554   (let* ((address (elpher-node-address elpher-current-node))
555          (selector (elpher-address-selector address)))
556     (elpher-visit-parent-node) ; Do first in case of non-local exits.
557     (let* ((filename-proposal (file-name-nondirectory selector))
558            (filename (read-file-name "Save file as: "
559                                      nil nil nil
560                                      (if (> (length filename-proposal) 0)
561                                          filename-proposal
562                                        "gopher.file"))))
563       (message "Downloading...")
564       (setq elpher-download-filename filename)
565       (elpher-get-selector address
566                             (lambda (proc event)
567                               (let ((coding-system-for-write 'binary))
568                                 (with-temp-file elpher-download-filename
569                                   (insert elpher-selector-string)
570                                   (message (format "Download complate, saved to file %s."
571                                                    elpher-download-filename)))))))))
572
573
574 ;;; Navigation procedures
575 ;;
576
577 (defun elpher-next-link ()
578   "Move point to the next link on the current page."
579   (interactive)
580   (forward-button 1))
581
582 (defun elpher-prev-link ()
583   "Move point to the previous link on the current page."
584   (interactive)
585   (backward-button 1))
586
587 (defun elpher-click-link (button)
588   "Function called when the gopher link BUTTON is activated (via mouse or keypress)."
589   (let ((node (button-get button 'elpher-node)))
590     (elpher-visit-node node)))
591
592 (defun elpher-click-url (button)
593   "Function called when the url link BUTTON is activated (via mouse or keypress)."
594   (let ((url (button-get button 'elpher-url)))
595     (if elpher-open-urls-with-eww
596         (browse-web url)
597       (browse-url url))))
598
599 (defun elpher-follow-current-link ()
600   "Open the link or url at point."
601   (interactive)
602   (push-button))
603
604 (defun elpher-go ()
605   "Go to a particular gopher site."
606   (interactive)
607   (let* (
608          (hostname (read-string "Gopher host: "))
609          (selector (read-string "Selector (default none): " nil nil ""))
610          (port (read-string "Port (default 70): " nil nil 70))
611          (address (list selector hostname port)))
612     (elpher-visit-node
613      (elpher-make-node elpher-current-node
614                         address
615                         #'elpher-get-index-node))))
616
617 (defun  elpher-redraw ()
618   "Redraw current page."
619   (interactive)
620   (elpher-visit-node elpher-current-node))
621
622 (defun  elpher-reload ()
623   "Reload current page."
624   (interactive)
625   (elpher-reload-current-node))
626
627 (defun elpher-view-raw ()
628   "View current page as plain text."
629   (interactive)
630   (elpher-visit-node elpher-current-node
631                       #'elpher-get-node-raw))
632
633 (defun elpher-back ()
634   "Go to previous site."
635   (interactive)
636   (if (elpher-node-parent elpher-current-node)
637       (elpher-visit-parent-node)
638     (message "No previous site.")))
639
640 (defun elpher-download ()
641   "Download the link at point."
642   (interactive)
643   (let ((button (button-at (point))))
644     (if button
645         (let ((node (button-get button 'elpher-node)))
646           (if node
647               (elpher-visit-node (button-get button 'elpher-node)
648                                  #'elpher-get-node-download)
649             (message "Can only download gopher links, not general URLs.")))
650       (message "No link selected."))))
651
652 ;;; Mode and keymap
653 ;;
654
655 (defvar elpher-mode-map
656   (let ((map (make-sparse-keymap)))
657     (define-key map (kbd "TAB") 'elpher-next-link)
658     (define-key map (kbd "<backtab>") 'elpher-prev-link)
659     (define-key map (kbd "u") 'elpher-back)
660     (define-key map (kbd "g") 'elpher-go)
661     (define-key map (kbd "r") 'elpher-redraw)
662     (define-key map (kbd "R") 'elpher-reload)
663     (define-key map (kbd "w") 'elpher-view-raw)
664     (define-key map (kbd "d") 'elpher-download)
665     (when (fboundp 'evil-define-key)
666       (evil-define-key 'normal map
667         (kbd "TAB") 'elpher-next-link
668         (kbd "C-]") 'elpher-follow-current-link
669         (kbd "C-t") 'elpher-back
670         (kbd "u") 'elpher-back
671         (kbd "g") 'elpher-go
672         (kbd "r") 'elpher-redraw
673         (kbd "R") 'elpher-reload
674         (kbd "w") 'elpher-view-raw
675         (kbd "d") 'elpher-download))
676     map)
677   "Keymap for gopher client.")
678
679 (define-derived-mode elpher-mode special-mode "elpher"
680   "Major mode for elpher, an elisp gopher client.")
681
682
683 ;;; Main start procedure
684 ;;
685
686 ;;;###autoload
687 (defun elpher ()
688   "Start elpher with default landing page."
689   (interactive)
690   (setq elpher-current-node nil)
691   (let ((start-node (elpher-make-node nil nil #'elpher-get-index-node)))
692     (elpher-visit-node start-node))
693   "Started Elpher.") ; Otherwise (elpher) evaluates to start page string.
694
695 ;;; elpher.el ends here