Replaced "w" with "." as default view-raw binding.
[elpher.git] / elpher.el
1 ;;; elpher.el --- A friendly 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.4.7
8 ;; Keywords: comm gopher
9 ;; Homepage: https://github.com/tgvaughan/elpher
10 ;; Package-Requires: ((emacs "26"))
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 practical and friendly gopher client
30 ;; for GNU Emacs.  It supports:
31
32 ;; - intuitive keyboard and mouse-driven browsing,
33 ;; - out-of-the-box compatibility with evil-mode,
34 ;; - clickable web and gopher links *in plain text*,
35 ;; - caching of visited sites,
36 ;; - pleasant and configurable colouring of Gopher directories,
37 ;; - direct visualisation of image files,
38 ;; - a simple bookmark management system,
39 ;; - connections using TLS encryption.
40
41 ;; To launch Elpher, simply use 'M-x elpher'.  This will open a start
42 ;; page containing information on key bindings and suggested starting
43 ;; points for your gopher exploration.
44
45 ;; Full instructions can be found in the Elpher info manual.
46
47 ;; Elpher is under active development.  Any suggestions for
48 ;; improvements are welcome!
49
50 ;;; Code:
51
52 (provide 'elpher)
53
54 ;;; Dependencies
55 ;;
56
57 (require 'seq)
58 (require 'pp)
59 (require 'shr)
60 (require 'url-util)
61
62
63 ;;; Global constants
64 ;;
65
66 (defconst elpher-version "1.4.7"
67   "Current version of elpher.")
68
69 (defconst elpher-margin-width 6
70   "Width of left-hand margin used when rendering indicies.")
71
72
73 (defconst elpher-type-map
74   '((?0 elpher-get-text-node "txt" elpher-text)
75     (?1 elpher-get-index-node "/" elpher-index)
76     (?4 elpher-get-node-download "bin" elpher-binary)
77     (?5 elpher-get-node-download "bin" elpher-binary)
78     (?7 elpher-get-search-node "?" elpher-search)
79     (?8 elpher-get-telnet-node "tel" elpher-telnet)
80     (?9 elpher-get-node-download "bin" elpher-binary)
81     (?g elpher-get-image-node "img" elpher-image)
82     (?p elpher-get-image-node "img" elpher-image)
83     (?I elpher-get-image-node "img" elpher-image)
84     (?d elpher-get-node-download "doc" elpher-binary)
85     (?P elpher-get-node-download "doc" elpher-binary)
86     (?s elpher-get-node-download "snd" elpher-binary)
87     (?h elpher-get-url-node "url" elpher-url)
88     (bookmarks elpher-get-bookmarks-node "#" elpher-index)
89     (start elpher-get-start-node "#" elpher-index))
90   "Association list from types to getters, margin codes and index faces.")
91
92
93 ;;; Customization group
94 ;;
95
96 (defgroup elpher nil
97   "A gopher client."
98   :group 'applications)
99
100 ;; Face customizations
101
102 (defface elpher-index
103   '((t :inherit font-lock-keyword-face))
104   "Face used for directory type directory records.")
105
106 (defface elpher-text
107   '((t :inherit bold))
108   "Face used for text type directory records.")
109
110 (defface elpher-info
111   '((t :inherit default))
112   "Face used for info type directory records.")
113
114 (defface elpher-image
115   '((t :inherit font-lock-string-face))
116   "Face used for image type directory records.")
117
118 (defface elpher-search
119   '((t :inherit warning))
120   "Face used for search type directory records.")
121
122 (defface elpher-url
123   '((t :inherit font-lock-comment-face))
124   "Face used for url type directory records.")
125
126 (defface elpher-telnet
127   '((t :inherit font-lock-function-name-face))
128   "Face used for telnet type directory records.")
129
130 (defface elpher-binary
131   '((t :inherit font-lock-doc-face))
132   "Face used for binary type directory records.")
133
134 (defface elpher-unknown
135   '((t :inherit error))
136   "Face used for directory records with unknown/unsupported types.")
137
138 (defface elpher-margin-key
139   '((t :inherit bold))
140   "Face used for directory margin key.")
141
142 (defface elpher-margin-brackets
143   '((t :inherit shadow))
144   "Face used for brackets around directory margin key.")
145
146 ;; Other customizations
147
148 (defcustom elpher-open-urls-with-eww nil
149   "If non-nil, open URL selectors using eww.
150 Otherwise, use the system browser via the BROWSE-URL function."
151   :type '(boolean))
152
153 (defcustom elpher-buttonify-urls-in-directories nil
154   "If non-nil, turns URLs matched in directories into clickable buttons."
155   :type '(boolean))
156
157 (defcustom elpher-cache-images nil
158   "If non-nil, cache images in memory in the same way as other content."
159   :type '(boolean))
160
161 (defcustom elpher-use-header t
162   "If non-nil, display current node information in buffer header."
163   :type '(boolean))
164
165 (defcustom elpher-auto-disengage-TLS nil
166   "If non-nil, automatically disengage TLS following an unsuccessful connection.
167 While enabling this may seem convenient, it is also potentially dangerous as it
168 allows switching from an encrypted channel back to plain text without user input."
169   :type '(boolean))
170
171
172 ;;; Model
173 ;;
174
175 ;; Address
176
177 (defun elpher-make-address (type &optional selector host port use-tls)
178   "Create an address of a gopher object with TYPE, SELECTOR, HOST and PORT.
179 Although selector host and port are optional, they are only omitted for
180 special address types, such as 'start for the start page.
181
182 Setting the USE-TLS parameter to non-nil causes Elpher to engage TLS mode
183 before attempting to connect to the server."
184   (if use-tls
185       (list type selector host port 'tls)
186     (list type selector host port)))
187
188 (defun elpher-address-type (address)
189   "Retrieve type from ADDRESS."
190   (elt address 0))
191
192 (defun elpher-address-selector (address)
193   "Retrieve selector from ADDRESS."
194   (elt address 1))
195
196 (defun elpher-address-host (address)
197   "Retrieve host from ADDRESS."
198   (elt address 2))
199
200 (defun elpher-address-port (address)
201   "Retrieve port from ADDRESS."
202   (elt address 3))
203
204 (defun elpher-address-use-tls-p (address)
205   "Return non-nil if ADDRESS is marked as needing TLS."
206   (elt address 4))
207
208 (defun elpher-address-special-p (address)
209   "Return non-nil if ADDRESS is special (e.g. start page, bookmarks page)."
210   (not (elpher-address-host address)))
211
212 (defun elpher-get-address-url (address)
213   "Get URL representation of ADDRESS."
214   (let ((type (elpher-address-type address))
215         (selector (elpher-address-selector address))
216         (bare-host (elpher-address-host address))
217         (port (elpher-address-port address)))
218     (url-encode-url
219      (let ((host (if (string-match-p ":" bare-host)
220                      (concat "[" bare-host "]")
221                    bare-host)))
222        (if (and (equal type ?h)
223                 (string-prefix-p "URL:" selector))
224            (elt (split-string selector "URL:") 1)
225          (concat "gopher"
226                  (if (elpher-address-use-tls-p address) "s" "")
227                  "://"
228                  host
229                  (if (equal port 70)
230                      ""
231                    (format ":%d" port))
232                  "/" (string type)
233                  selector))))))
234
235 ;; Node
236
237 (defun elpher-make-node (display-string address &optional parent)
238   "Create a node in the gopher page hierarchy.
239
240 DISPLAY-STRING records the display string used for the page.
241
242 ADDRESS specifies the address of the gopher page.
243
244 The optional PARENT specifies the parent node in the hierarchy.
245 This is set every time the node is visited, so while it forms
246 an important part of the node data there is no need to set it
247 initially."
248   (list display-string address parent))
249
250 (defun elpher-node-display-string (node)
251   "Retrieve the display string of NODE."
252   (elt node 0))
253
254 (defun elpher-node-address (node)
255   "Retrieve the address of NODE."
256   (elt node 1))
257
258 (defun elpher-node-parent (node)
259   "Retrieve the parent node of NODE."
260   (elt node 2))
261
262 (defun elpher-set-node-parent (node parent)
263   "Set the parent node of NODE to be PARENT."
264   (setcar (cdr (cdr node)) parent))
265
266 ;; Cache
267
268 (defvar elpher-content-cache (make-hash-table :test 'equal))
269 (defvar elpher-pos-cache (make-hash-table :test 'equal))
270
271 (defun elpher-get-cached-content (address)
272   "Retrieve the cached content for ADDRESS, or nil if none exists."
273   (gethash address elpher-content-cache))
274
275 (defun elpher-cache-content (address content)
276   "Set the content cache for ADDRESS to CONTENT."
277   (puthash address content elpher-content-cache))
278
279 (defun elpher-get-cached-pos (address)
280   "Retrieve the cached cursor position for ADDRESS, or nil if none exists."
281   (gethash address elpher-pos-cache))
282
283 (defun elpher-cache-pos (address pos)
284   "Set the cursor position cache for ADDRESS to POS."
285   (puthash address pos elpher-pos-cache))
286
287 ;; Node graph traversal
288
289 (defvar elpher-current-node nil)
290
291 (defun elpher-visit-node (node &optional getter preserve-parent)
292   "Visit NODE using its own getter or GETTER, if non-nil.
293 Additionally, set the parent of NODE to `elpher-current-node',
294 unless PRESERVE-PARENT is non-nil."
295   (elpher-save-pos)
296   (elpher-process-cleanup)
297   (unless preserve-parent
298     (if (and (elpher-node-parent elpher-current-node)
299              (equal (elpher-node-address elpher-current-node)
300                     (elpher-node-address node)))
301         (elpher-set-node-parent node (elpher-node-parent elpher-current-node))
302       (elpher-set-node-parent node elpher-current-node)))
303   (setq elpher-current-node node)
304   (if getter
305       (funcall getter)
306     (let* ((address (elpher-node-address node))
307            (type (elpher-address-type address))
308            (type-record (alist-get type elpher-type-map)))
309       (if type-record
310           (funcall (car type-record))
311         (elpher-visit-parent-node)
312         (error "Unsupported gopher selector type '%c'" type)))))
313
314 (defun elpher-visit-parent-node ()
315   "Visit the parent of the current node."
316   (let ((parent-node (elpher-node-parent elpher-current-node)))
317     (when parent-node
318       (elpher-visit-node parent-node nil t))))
319       
320 (defun elpher-reload-current-node ()
321   "Reload the current node, discarding any existing cached content."
322   (elpher-cache-content (elpher-node-address elpher-current-node) nil)
323   (elpher-visit-node elpher-current-node))
324
325 (defun elpher-save-pos ()
326   "Save the current position of point to the current node."
327   (when elpher-current-node
328     (elpher-cache-pos (elpher-node-address elpher-current-node) (point))))
329
330 (defun elpher-restore-pos ()
331   "Restore the position of point to that cached in the current node."
332   (let ((pos (elpher-get-cached-pos (elpher-node-address elpher-current-node))))
333     (if pos
334         (goto-char pos)
335       (goto-char (point-min)))))
336
337
338 ;;; Buffer preparation
339 ;;
340
341 (defun elpher-update-header ()
342   "If `elpher-use-header' is true, display current node info in window header."
343   (if elpher-use-header
344       (setq header-line-format (elpher-node-display-string elpher-current-node))))
345
346 (defmacro elpher-with-clean-buffer (&rest args)
347   "Evaluate ARGS with a clean *elpher* buffer as current."
348   (list 'with-current-buffer "*elpher*"
349         '(elpher-mode)
350         (append (list 'let '((inhibit-read-only t))
351                       '(erase-buffer)
352                       '(elpher-update-header))
353                 args)))
354
355
356 ;;; Text Processing
357 ;;
358
359 (defvar elpher-user-coding-system nil
360   "User-specified coding system to use for decoding text responses.")
361
362 (defun elpher-decode (string)
363   "Decode STRING using autodetected or user-specified coding system."
364   (decode-coding-string string
365                         (if elpher-user-coding-system
366                             elpher-user-coding-system
367                           (detect-coding-string string t))))
368
369 (defun elpher-preprocess-text-response (string)
370   "Preprocess text selector response contained in STRING.
371 This involes decoding the character representation, and clearing
372 away CRs and any terminating period."
373   (elpher-decode (replace-regexp-in-string "\n\.\n$" "\n"
374                                            (replace-regexp-in-string "\r" "" string))))
375
376 ;;; Index rendering
377 ;;
378
379 (defun elpher-insert-index (string)
380   "Insert the index corresponding to STRING into the current buffer."
381   ;; Should be able to split directly on CRLF, but some non-conformant
382   ;; LF-only servers sadly exist, hence the following.
383   (let ((str-processed (elpher-preprocess-text-response string)))
384     (dolist (line (split-string str-processed "\n"))
385       (unless (= (length line) 0)
386         (let* ((type (elt line 0))
387                (fields (split-string (substring line 1) "\t"))
388                (display-string (elt fields 0))
389                (selector (elt fields 1))
390                (host (elt fields 2))
391                (port (if (elt fields 3)
392                          (string-to-number (elt fields 3))
393                        nil))
394                (address (elpher-make-address type selector host port)))
395           (elpher-insert-index-record display-string address))))))
396
397 (defun elpher-insert-margin (&optional type-name)
398   "Insert index margin, optionally containing the TYPE-NAME, into the current buffer."
399   (if type-name
400       (progn
401         (insert (format (concat "%" (number-to-string (- elpher-margin-width 1)) "s")
402                         (concat
403                          (propertize "[" 'face 'elpher-margin-brackets)
404                          (propertize type-name 'face 'elpher-margin-key)
405                          (propertize "]" 'face 'elpher-margin-brackets))))
406         (insert " "))
407     (insert (make-string elpher-margin-width ?\s))))
408
409 (defun elpher-node-button-help (node)
410   "Return a string containing the help text for a button corresponding to NODE."
411   (let ((address (elpher-node-address node)))
412     (if (eq (elpher-address-type address) ?h)
413         (let ((url (cadr (split-string (elpher-address-selector address) "URL:"))))
414           (format "mouse-1, RET: open url '%s'" url))
415       (format "mouse-1, RET: open '%s' on %s port %s"
416               (elpher-address-selector address)
417               (elpher-address-host address)
418               (elpher-address-port address)))))
419
420
421 (defun elpher-insert-index-record (display-string address)
422   "Function to insert an index record into the current buffer.
423 The contents of the record are dictated by DISPLAY-STRING and ADDRESS."
424   (let* ((type (elpher-address-type address))
425          (type-map-entry (alist-get type elpher-type-map)))
426     (if type-map-entry
427         (let* ((margin-code (elt type-map-entry 1))
428                (face (elt type-map-entry 2))
429                (node (elpher-make-node display-string address)))
430           (elpher-insert-margin margin-code)
431           (insert-text-button display-string
432                               'face face
433                               'elpher-node node
434                               'action #'elpher-click-link
435                               'follow-link t
436                               'help-echo (elpher-node-button-help node)))
437       (pcase type
438         (?i ;; Information
439          (elpher-insert-margin)
440          (insert (propertize
441                   (if elpher-buttonify-urls-in-directories
442                       (elpher-buttonify-urls display-string)
443                     display-string)
444                   'face 'elpher-info)))
445         (other ;; Unknown
446          (elpher-insert-margin (concat (char-to-string type) "?"))
447          (insert (propertize display-string
448                              'face 'elpher-unknown)))))
449     (insert "\n")))
450
451 (defun elpher-click-link (button)
452   "Function called when the gopher link BUTTON is activated (via mouse or keypress)."
453   (let ((node (button-get button 'elpher-node)))
454     (elpher-visit-node node)))
455
456
457 ;;; Selector retrieval (all kinds)
458 ;;
459
460 (defun elpher-process-cleanup ()
461   "Immediately shut down any extant elpher process."
462   (let ((p (get-process "elpher-process")))
463     (if p (delete-process p))))
464
465 (defvar elpher-use-tls nil
466   "If non-nil, use TLS to communicate with gopher servers.")
467
468 (defvar elpher-selector-string)
469
470 (defun elpher-get-selector (address after &optional propagate-error)
471   "Retrieve selector specified by ADDRESS, then execute AFTER.
472 The result is stored as a string in the variable â€˜elpher-selector-string’.
473
474 Usually errors result in an error page being displayed.  This is only
475 appropriate if the selector is to be directly viewed.  If PROPAGATE-ERROR
476 is non-nil, this message is not displayed.  Instead, the error propagates
477 up to the calling function."
478   (setq elpher-selector-string "")
479   (when (elpher-address-use-tls-p address)
480       (if (gnutls-available-p)
481           (when (not elpher-use-tls)
482             (setq elpher-use-tls t)
483             (message "Engaging TLS mode."))
484         (error "Cannot retrieve TLS selector: GnuTLS not available")))
485   (condition-case the-error
486       (let* ((kill-buffer-query-functions nil)
487              (proc (open-network-stream "elpher-process"
488                                        nil
489                                        (elpher-address-host address)
490                                        (elpher-address-port address)
491                                        :type (if elpher-use-tls 'tls 'plain))))
492         (set-process-coding-system proc 'binary)
493         (set-process-filter proc
494                             (lambda (proc string)
495                               (setq elpher-selector-string
496                                     (concat elpher-selector-string string))))
497         (set-process-sentinel proc after)
498         (process-send-string proc
499                              (concat (elpher-address-selector address) "\n")))
500     (error
501      (if (and (consp the-error)
502               (eq (car the-error) 'gnutls-error)
503               (not (elpher-address-use-tls-p address))
504               (or elpher-auto-disengage-TLS
505                   (yes-or-no-p "Could not establish encrypted connection.  Disable TLS mode? ")))
506          (progn
507            (message "Disengaging TLS mode.")
508            (setq elpher-use-tls nil)
509            (elpher-get-selector address after))
510        (elpher-process-cleanup)
511        (if propagate-error
512            (error the-error)
513          (elpher-with-clean-buffer
514           (insert (propertize "\n---- ERROR -----\n\n" 'face 'error)
515                   "Failed to connect to " (elpher-get-address-url address) ".\n"
516                   (propertize "\n----------------\n\n" 'face 'error)
517                   "Press 'u' to return to the previous page.")))))))
518
519 ;; Index retrieval
520
521 (defun elpher-get-index-node ()
522   "Getter which retrieves the current node contents as an index."
523   (let* ((address (elpher-node-address elpher-current-node))
524          (content (elpher-get-cached-content address)))
525     (if content
526         (progn
527           (elpher-with-clean-buffer
528            (insert content)
529            (elpher-restore-pos)))
530       (elpher-with-clean-buffer
531        (insert "LOADING DIRECTORY... (use 'u' to cancel)"))
532       (elpher-get-selector address
533                            (lambda (proc event)
534                              (unless (string-prefix-p "deleted" event)
535                                (elpher-with-clean-buffer
536                                 (elpher-insert-index elpher-selector-string)
537                                 (elpher-restore-pos)
538                                 (elpher-cache-content
539                                  (elpher-node-address elpher-current-node)
540                                  (buffer-string)))))))))
541
542 ;; Text retrieval
543
544 (defconst elpher-url-regex
545   "\\([a-zA-Z]+\\)://\\([a-zA-Z0-9.\-]+\\|\[[a-zA-Z0-9:]+\]\\)\\(?3::[0-9]+\\)?\\(?4:/[^ \r\n\t(),]*\\)?"
546   "Regexp used to locate and buttinofy URLs in text files loaded by elpher.")
547
548 (defun elpher-make-node-from-matched-url (&optional string)
549   "Convert most recent `elpher-url-regex' match to a node.
550
551 If STRING is non-nil, this is given as an argument to all `match-string'
552 calls, as is necessary if the match is performed by `string-match'."
553   (let ((url (match-string 0 string))
554         (protocol (downcase (match-string 1 string))))
555     (if (or (string= protocol "gopher")
556             (string= protocol "gophers"))
557         (let* ((bare-host (match-string 2 string))
558                (host (if (string-prefix-p "[" bare-host)
559                          (substring bare-host 1 (- (length bare-host) 1))
560                        bare-host))
561                (port (if (> (length (match-string 3 string))  1)
562                          (string-to-number (substring (match-string 3 string) 1))
563                        70))
564                (type-and-selector (match-string 4 string))
565                (type (if (> (length type-and-selector) 1)
566                          (elt type-and-selector 1)
567                        ?1))
568                (selector (decode-coding-string
569                           (url-unhex-string
570                            (if (> (length type-and-selector) 1)
571                                (substring type-and-selector 2)
572                              "")) 'utf-8))
573                (use-tls (string= protocol "gophers"))
574                (address (elpher-make-address type selector host port use-tls)))
575           (elpher-make-node url address))
576       (let* ((host (match-string 2 string))
577              (port (if (> (length (match-string 3 string)) 1)
578                        (string-to-number (substring (match-string 3 string) 1))
579                      70))
580              (selector (concat "URL:" url))
581              (address (elpher-make-address ?h selector host port)))
582         (elpher-make-node url address)))))
583
584
585 (defun elpher-buttonify-urls (string)
586   "Turn substrings which look like urls in STRING into clickable buttons."
587   (with-temp-buffer
588     (insert string)
589     (goto-char (point-min))
590     (while (re-search-forward elpher-url-regex nil t)
591         (let ((node (elpher-make-node-from-matched-url)))
592           (make-text-button (match-beginning 0)
593                             (match-end 0)
594                             'elpher-node  node
595                             'action #'elpher-click-link
596                             'follow-link t
597                             'help-echo (elpher-node-button-help node))))
598     (buffer-string)))
599
600 (defun elpher-get-text-node ()
601   "Getter which retrieves the current node contents as a text document."
602   (let* ((address (elpher-node-address elpher-current-node))
603          (content (elpher-get-cached-content address)))
604     (if content
605         (progn
606           (elpher-with-clean-buffer
607            (insert content)
608            (elpher-restore-pos)))
609       (progn
610         (elpher-with-clean-buffer
611          (insert "LOADING TEXT... (use 'u' to cancel)"))
612         (elpher-get-selector address
613                               (lambda (proc event)
614                                 (unless (string-prefix-p "deleted" event)
615                                   (elpher-with-clean-buffer
616                                    (insert (elpher-buttonify-urls
617                                             (elpher-preprocess-text-response
618                                              elpher-selector-string)))
619                                    (elpher-restore-pos)
620                                    (elpher-cache-content
621                                     (elpher-node-address elpher-current-node)
622                                     (buffer-string))))))))))
623
624 ;; Image retrieval
625
626 (defun elpher-get-image-node ()
627   "Getter which retrieves the current node contents as an image to view."
628   (let* ((address (elpher-node-address elpher-current-node))
629          (content (elpher-get-cached-content address)))
630     (if content
631         (progn
632           (elpher-with-clean-buffer
633            (insert-image content)
634            (elpher-restore-pos)))
635       (if (display-images-p)
636           (progn
637             (elpher-with-clean-buffer
638              (insert "LOADING IMAGE... (use 'u' to cancel)"))
639             (elpher-get-selector address
640                                  (lambda (proc event)
641                                    (unless (string-prefix-p "deleted" event)
642                                      (let ((image (create-image
643                                                    elpher-selector-string
644                                                    nil t)))
645                                        (elpher-with-clean-buffer
646                                         (insert-image image)
647                                         (elpher-restore-pos))
648                                        (if elpher-cache-images
649                                            (elpher-cache-content
650                                             (elpher-node-address elpher-current-node)
651                                             image)))))))
652         (elpher-get-node-download)))))
653
654 ;; Search retrieval
655
656 (defun elpher-get-search-node ()
657   "Getter which submits a search query to the address of the current node."
658   (let* ((address (elpher-node-address elpher-current-node))
659          (content (elpher-get-cached-content address))
660          (aborted t))
661     (if content
662         (progn
663           (elpher-with-clean-buffer
664            (insert content)
665            (elpher-restore-pos))
666           (message "Displaying cached search results.  Reload to perform a new search."))
667       (unwind-protect
668           (let* ((query-string (read-string "Query: "))
669                  (query-selector (concat (elpher-address-selector address) "\t" query-string))
670                  (search-address (elpher-make-address ?1
671                                                       query-selector
672                                                       (elpher-address-host address)
673                                                       (elpher-address-port address))))
674             (setq aborted nil)
675             (elpher-with-clean-buffer
676              (insert "LOADING RESULTS... (use 'u' to cancel)"))
677             (elpher-get-selector search-address
678                                   (lambda (proc event)
679                                     (unless (string-prefix-p "deleted" event)
680                                       (elpher-with-clean-buffer
681                                        (elpher-insert-index elpher-selector-string))
682                                       (goto-char (point-min))
683                                       (elpher-cache-content
684                                        (elpher-node-address elpher-current-node)
685                                        (buffer-string))))))
686         (if aborted
687             (elpher-visit-parent-node))))))
688
689 ;; Raw server response retrieval
690
691 (defun elpher-get-node-raw ()
692   "Getter which retrieves the raw server response for the current node."
693   (let ((address (elpher-node-address elpher-current-node)))
694     (elpher-with-clean-buffer
695      (insert "LOADING RAW SERVER RESPONSE... (use 'u' to cancel)"))
696     (elpher-get-selector address
697                          (lambda (proc event)
698                            (unless (string-prefix-p "deleted" event)
699                              (elpher-with-clean-buffer
700                               (insert elpher-selector-string)
701                               (goto-char (point-min)))))))
702   (message "Displaying raw server response.  Reload or redraw to return to standard view."))
703  
704 ;; File export retrieval
705
706 (defvar elpher-download-filename)
707
708 (defun elpher-get-node-download ()
709   "Getter which retrieves the current node and writes the result to a file."
710   (let* ((address (elpher-node-address elpher-current-node))
711          (selector (elpher-address-selector address)))
712     (elpher-visit-parent-node) ; Do first in case of non-local exits.
713     (let* ((filename-proposal (file-name-nondirectory selector))
714            (filename (read-file-name "Save file as: "
715                                      nil nil nil
716                                      (if (> (length filename-proposal) 0)
717                                          filename-proposal
718                                        "gopher.file"))))
719       (message "Downloading...")
720       (setq elpher-download-filename filename)
721       (condition-case the-error
722           (elpher-get-selector address
723                                (lambda (proc event)
724                                  (let ((coding-system-for-write 'binary))
725                                    (with-temp-file elpher-download-filename
726                                      (insert elpher-selector-string)
727                                      (message (format "Download complate, saved to file %s."
728                                                       elpher-download-filename)))))
729                                t)
730         (error
731          (error "Error downloading %s" elpher-download-filename))))))
732
733 ;; URL retrieval
734
735 (defun elpher-insert-rendered-html (string)
736   "Use shr to insert rendered view of html STRING into current buffer."
737   (let ((dom (with-temp-buffer
738                (insert string)
739                (libxml-parse-html-region (point-min) (point-max)))))
740     (shr-insert-document dom)))
741
742 (defun elpher-get-url-node ()
743   "Getter which attempts to open the URL specified by the current node."
744   (let* ((address (elpher-node-address elpher-current-node))
745          (selector (elpher-address-selector address)))
746     (let ((url (elt (split-string selector "URL:") 1)))
747       (if url
748           (progn
749             (elpher-visit-parent-node) ; Do first in case of non-local exits.
750             (message "Opening URL...")
751             (if elpher-open-urls-with-eww
752                 (browse-web url)
753               (browse-url url)))
754         (let ((content (elpher-get-cached-content address)))
755           (if content
756               (progn
757                 (elpher-with-clean-buffer
758                  (insert content)
759                  (elpher-restore-pos)))
760             (elpher-with-clean-buffer
761              (insert "LOADING HTML... (use 'u' to cancel)"))
762             (elpher-get-selector address
763                                  (lambda (proc event)
764                                    (unless (string-prefix-p "deleted" event)
765                                      (elpher-with-clean-buffer
766                                       (elpher-insert-rendered-html elpher-selector-string)
767                                       (goto-char (point-min))
768                                       (elpher-cache-content
769                                        (elpher-node-address elpher-current-node)
770                                        (buffer-string))))))))))))
771
772 ;; Telnet node connection
773
774 (defun elpher-get-telnet-node ()
775   "Getter which opens a telnet connection to the server specified by the current node."
776   (let* ((address (elpher-node-address elpher-current-node))
777          (host (elpher-address-host address))
778          (port (elpher-address-port address)))
779     (elpher-visit-parent-node)
780     (telnet host port)))
781
782 ;; Start page node retrieval
783
784 (defun elpher-get-start-node ()
785   "Getter which displays the start page."
786   (elpher-with-clean-buffer
787    (insert "     --------------------------------------------\n"
788            "                Elpher Gopher Client             \n"
789            "                   version " elpher-version "\n"
790            "     --------------------------------------------\n"
791            "\n"
792            "Default bindings:\n"
793            "\n"
794            " - TAB/Shift-TAB: next/prev item on current page\n"
795            " - RET/mouse-1: open item under cursor\n"
796            " - m: select an item on current page by name (autocompletes)\n"
797            " - u: return to previous page\n"
798            " - o/O: visit different selector or the root menu of the current server\n"
799            " - g: go to a particular gopher address\n"
800            " - i/I: info on item under cursor or current page\n"
801            " - c/C: copy URL representation of item under cursor or current page\n"
802            " - a/A: bookmark the item under cursor or current page\n"
803            " - x/X: remove bookmark for item under cursor or current page\n"
804            " - B: visit the bookmarks page\n"
805            " - r: redraw current page (using cached contents if available)\n"
806            " - R: reload current page (regenerates cache)\n"
807            " - T: toggle TLS mode\n"
808            " - d/D: download item under cursor or current page\n"
809            " - w: display the raw server response for the current page\n"
810            " - S: set an explicit character coding system (default is to autodetect)\n"
811            "\n"
812            "Start your exploration of gopher space:\n")
813    (elpher-insert-index-record "Floodgap Systems Gopher Server"
814                                (elpher-make-address ?1 "" "gopher.floodgap.com" 70))
815    (insert "\n"
816            "Alternatively, select the following item and enter some search terms:\n")
817    (elpher-insert-index-record "Veronica-2 Gopher Search Engine"
818                                (elpher-make-address ?7 "/v2/vs" "gopher.floodgap.com" 70))
819    (insert "\n"
820            "** Refer to the ")
821    (let ((help-string "RET,mouse-1: Open Elpher info manual (if available)"))
822      (insert-text-button "Elpher info manual"
823                          'face 'link
824                          'action (lambda (button)
825                                    (interactive)
826                                    (info "(elpher)"))
827                          'follow-link t
828                          'help-echo help-string))
829    (insert " for the full documentation. **\n")
830    (insert (propertize
831             (concat "  (This should be available if you have installed Elpher using\n"
832                     "   MELPA. Otherwise you will have to install the manual yourself.)")
833             'face 'shadow))
834    (elpher-restore-pos)))
835
836 ;; Bookmarks page node retrieval
837
838 (defun elpher-get-bookmarks-node ()
839   "Getter to load and display the current bookmark list."
840   (elpher-with-clean-buffer
841    (insert "---- Bookmark list ----\n\n")
842    (let ((bookmarks (elpher-load-bookmarks)))
843      (if bookmarks
844          (dolist (bookmark bookmarks)
845            (let ((display-string (elpher-bookmark-display-string bookmark))
846                  (address (elpher-bookmark-address bookmark)))
847              (elpher-insert-index-record display-string address)))
848        (insert "No bookmarks found.\n")))
849    (insert "\n-----------------------\n\n"
850            "- u: return to previous page\n"
851            "- x: delete selected bookmark\n"
852            "- a: rename selected bookmark\n\n"
853            "Bookmarks are stored in the file "
854            (locate-user-emacs-file "elpher-bookmarks"))
855    (elpher-restore-pos)))
856   
857
858 ;;; Bookmarks
859 ;;
860
861 (defun elpher-make-bookmark (display-string address)
862   "Make an elpher bookmark.
863 DISPLAY-STRING determines how the bookmark will appear in the
864 bookmark list, while ADDRESS is the address of the entry."
865   (list display-string address))
866   
867 (defun elpher-bookmark-display-string (bookmark)
868   "Get the display string of BOOKMARK."
869   (elt bookmark 0))
870
871 (defun elpher-set-bookmark-display-string (bookmark display-string)
872   "Set the display string of BOOKMARK to DISPLAY-STRING."
873   (setcar bookmark display-string))
874
875 (defun elpher-bookmark-address (bookmark)
876   "Get the address for BOOKMARK."
877   (elt bookmark 1))
878
879 (defun elpher-save-bookmarks (bookmarks)
880   "Record the bookmark list BOOKMARKS to the user's bookmark file.
881 Beware that this completely replaces the existing contents of the file."
882   (with-temp-file (locate-user-emacs-file "elpher-bookmarks")
883     (erase-buffer)
884     (insert "; Elpher gopher bookmarks file\n\n"
885             "; Bookmarks are stored as a list of (label (type selector host port))\n"
886             "; s-expressions, where type is stored as a character (i.e. 49 = ?1).\n"
887             "; Feel free to edit by hand, but ensure this structure remains intact.\n\n")
888     (pp bookmarks (current-buffer))))
889
890 (defun elpher-load-bookmarks ()
891   "Get the list of bookmarks from the users's bookmark file."
892   (with-temp-buffer
893     (ignore-errors
894       (insert-file-contents (locate-user-emacs-file "elpher-bookmarks"))
895       (goto-char (point-min))
896       (read (current-buffer)))))
897
898 (defun elpher-add-address-bookmark (address display-string)
899   "Save a bookmark for ADDRESS with label DISPLAY-STRING.
900 If ADDRESS is already bookmarked, update the label only."
901   (let ((bookmarks (elpher-load-bookmarks)))
902     (let ((existing-bookmark (rassoc (list address) bookmarks)))
903       (if existing-bookmark
904           (elpher-set-bookmark-display-string existing-bookmark display-string)
905         (add-to-list 'bookmarks (elpher-make-bookmark display-string address))))
906     (elpher-save-bookmarks bookmarks)))
907
908 (defun elpher-remove-address-bookmark (address)
909   "Remove any bookmark to ADDRESS."
910     (elpher-save-bookmarks
911      (seq-filter (lambda (bookmark)
912                    (not (equal (elpher-bookmark-address bookmark) address)))
913                  (elpher-load-bookmarks))))
914
915
916 ;;; Interactive procedures
917 ;;
918
919 (defun elpher-next-link ()
920   "Move point to the next link on the current page."
921   (interactive)
922   (forward-button 1))
923
924 (defun elpher-prev-link ()
925   "Move point to the previous link on the current page."
926   (interactive)
927   (backward-button 1))
928
929 (defun elpher-follow-current-link ()
930   "Open the link or url at point."
931   (interactive)
932   (push-button))
933
934 (defun elpher-go ()
935   "Go to a particular gopher site read from the minibuffer.
936 The site may be specified via a URL or explicitly in terms of
937 host, selector and port."
938   (interactive)
939   (let ((node
940          (let ((host-or-url (read-string "Gopher host or URL: ")))
941            (if (string-match elpher-url-regex host-or-url)
942                (elpher-make-node-from-matched-url host-or-url)
943              (let ((selector (read-string "Selector (default none): " nil nil ""))
944                    (port-string (read-string "Port (default 70): " nil nil "70")))
945                (elpher-make-node (concat "gopher://" host-or-url
946                                          ":" port-string
947                                          "/1" selector)
948                                  (elpher-make-address ?1 selector host-or-url
949                                                       (string-to-number port-string))))))))
950     (switch-to-buffer "*elpher*")
951     (elpher-visit-node node)))
952
953 (defun elpher-go-current ()
954   "Go to a particular site read from the minibuffer, initialized with the current URL."
955   (interactive)
956   (let ((address (elpher-node-address elpher-current-node)))
957     (if (elpher-address-special-p address)
958         (error "Command not valid for this page")
959       (let ((url (read-string "URL: " (elpher-get-address-url address))))
960         (if (string-match elpher-url-regex url)
961             (let ((new-node (elpher-make-node-from-matched-url url)))
962               (unless (equal (elpher-node-address new-node) address)
963                 (elpher-visit-node new-node)))
964           (error "Could not parse URL %s" url))))))
965
966 (defun elpher-redraw ()
967   "Redraw current page."
968   (interactive)
969   (if elpher-current-node
970       (elpher-visit-node elpher-current-node)
971     (message "No current site.")))
972
973 (defun elpher-reload ()
974   "Reload current page."
975   (interactive)
976   (if elpher-current-node
977       (elpher-reload-current-node)
978     (message "No current site.")))
979
980 (defun elpher-toggle-tls ()
981   "Toggle TLS encryption mode."
982   (interactive)
983   (setq elpher-use-tls (not elpher-use-tls))
984   (if elpher-use-tls
985       (if (gnutls-available-p)
986           (message "TLS mode enabled.  (Will not affect current page until reload.)")
987         (setq elpher-use-tls nil)
988         (error "Cannot enable TLS mode: GnuTLS not available"))
989     (message "TLS mode disabled.  (Will not affect current page until reload.)")))
990
991 (defun elpher-view-raw ()
992   "View raw server response for current page."
993   (interactive)
994   (if elpher-current-node
995       (if (elpher-address-special-p (elpher-node-address elpher-current-node))
996           (error "This page was not generated by a server")
997         (elpher-visit-node elpher-current-node
998                            #'elpher-get-node-raw))
999     (message "No current site.")))
1000
1001 (defun elpher-back ()
1002   "Go to previous site."
1003   (interactive)
1004   (if (elpher-node-parent elpher-current-node)
1005       (elpher-visit-parent-node)
1006     (error "No previous site")))
1007
1008 (defun elpher-download ()
1009   "Download the link at point."
1010   (interactive)
1011   (let ((button (button-at (point))))
1012     (if button
1013         (let ((node (button-get button 'elpher-node)))
1014           (if (elpher-address-special-p (elpher-node-address node))
1015               (error "Cannot download this link")
1016             (elpher-visit-node (button-get button 'elpher-node)
1017                                #'elpher-get-node-download)))
1018       (error "No link selected"))))
1019
1020 (defun elpher-download-current ()
1021   "Download the current page."
1022   (interactive)
1023   (if (elpher-address-special-p (elpher-node-address elpher-current-node))
1024       (error "Cannot download this page")
1025     (elpher-visit-node (elpher-make-node
1026                         (elpher-node-display-string elpher-current-node)
1027                         (elpher-node-address elpher-current-node)
1028                         elpher-current-node)
1029                        #'elpher-get-node-download
1030                        t)))
1031
1032 (defun elpher-build-link-map ()
1033   "Build alist mapping link names to destination nodes in current buffer."
1034   (let ((link-map nil)
1035         (b (next-button (point-min) t)))
1036     (while b
1037       (add-to-list 'link-map (cons (button-label b) b))
1038       (setq b (next-button (button-start b))))
1039     link-map))
1040
1041 (defun elpher-jump ()
1042   "Select a directory entry by name.  Similar to the info browser (m)enu command."
1043   (interactive)
1044   (let* ((link-map (elpher-build-link-map)))
1045     (if link-map
1046         (let ((key (let ((completion-ignore-case t))
1047                      (completing-read "Directory item/link: "
1048                                       link-map nil t))))
1049           (if (and key (> (length key) 0))
1050               (let ((b (cdr (assoc key link-map))))
1051                 (goto-char (button-start b))
1052                 (button-activate b)))))))
1053
1054 (defun elpher-root-dir ()
1055   "Visit root of current server."
1056   (interactive)
1057   (let* ((address (elpher-node-address elpher-current-node))
1058          (host (elpher-address-host address)))
1059     (if host
1060         (let ((host (elpher-address-host address))
1061               (selector (elpher-address-selector address))
1062               (port (elpher-address-port address)))
1063           (if (> (length selector) 0)
1064               (let ((root-address (elpher-make-address ?1 "" host port)))
1065                 (elpher-visit-node
1066                  (elpher-make-node (concat "gopher://" host
1067                                            ":" (number-to-string port)
1068                                            "/1/")
1069                                    root-address)))
1070             (error "Already at root directory of current server")))
1071       (error "Command invalid for this page"))))
1072
1073 (defun elpher-bookmarks-current-p ()
1074   "Return non-nil if current node is a bookmarks page."
1075   (eq (elpher-address-type (elpher-node-address elpher-current-node)) 'bookmarks))
1076
1077 (defun elpher-reload-bookmarks ()
1078   "Reload bookmarks if current node is a bookmarks page."
1079   (if (elpher-bookmarks-current-p)
1080       (elpher-reload-current-node)))
1081
1082 (defun elpher-bookmark-current ()
1083   "Bookmark the current node."
1084   (interactive)
1085   (let ((address (elpher-node-address elpher-current-node))
1086         (display-string (elpher-node-display-string elpher-current-node)))
1087     (if (not (elpher-address-special-p address))
1088         (let ((bookmark-display-string (read-string "Bookmark display string: "
1089                                                     display-string)))
1090           (elpher-add-address-bookmark address bookmark-display-string)
1091           (message "Bookmark added."))
1092       (error "Cannot bookmark %s" display-string))))
1093
1094 (defun elpher-bookmark-link ()
1095   "Bookmark the link at point."
1096   (interactive)
1097   (let ((button (button-at (point))))
1098     (if button
1099         (let* ((node (button-get button 'elpher-node))
1100                (address (elpher-node-address node))
1101                (display-string (elpher-node-display-string node)))
1102           (if (not (elpher-address-special-p address))
1103               (let ((bookmark-display-string (read-string "Bookmark display string: "
1104                                                           display-string)))
1105                 (elpher-add-address-bookmark address bookmark-display-string)
1106                 (elpher-reload-bookmarks)
1107                 (message "Bookmark added."))
1108             (error "Cannot bookmark %s" display-string)))
1109       (error "No link selected"))))
1110
1111 (defun elpher-unbookmark-current ()
1112   "Remove bookmark for the current node."
1113   (interactive)
1114   (let ((address (elpher-node-address elpher-current-node)))
1115     (unless (elpher-address-special-p address)
1116       (elpher-remove-address-bookmark address)
1117       (message "Bookmark removed."))))
1118
1119 (defun elpher-unbookmark-link ()
1120   "Remove bookmark for the link at point."
1121   (interactive)
1122   (let ((button (button-at (point))))
1123     (if button
1124         (let ((node (button-get button 'elpher-node)))
1125           (elpher-remove-address-bookmark (elpher-node-address node))
1126           (elpher-reload-bookmarks)
1127           (message "Bookmark removed."))
1128       (error "No link selected"))))
1129
1130 (defun elpher-bookmarks ()
1131   "Visit bookmarks page."
1132   (interactive)
1133   (switch-to-buffer "*elpher*")
1134   (elpher-visit-node
1135    (elpher-make-node "Bookmarks Page" (elpher-make-address 'bookmarks))))
1136
1137 (defun elpher-info-node (node)
1138   "Display information on NODE."
1139   (let ((display-string (elpher-node-display-string node))
1140         (address (elpher-node-address node)))
1141     (if (not (elpher-address-special-p address))
1142         (message "`%s' on %s port %s"
1143                 (elpher-address-selector address)
1144                 (elpher-address-host address)
1145                 (elpher-address-port address))
1146       (message "%s" display-string))))
1147
1148 (defun elpher-info-link ()
1149   "Display information on node corresponding to link at point."
1150   (interactive)
1151   (let ((button (button-at (point))))
1152     (if button
1153         (elpher-info-node (button-get button 'elpher-node))
1154       (error "No item selected"))))
1155   
1156 (defun elpher-info-current ()
1157   "Display information on current node."
1158   (interactive)
1159   (elpher-info-node elpher-current-node))
1160
1161 (defun elpher-copy-node-url (node)
1162   "Copy URL representation of address of NODE to `kill-ring'."
1163   (let ((address (elpher-node-address node)))
1164     (if (elpher-address-special-p address)
1165         (error (format "Cannot represent %s as URL" (elpher-node-display-string node)))
1166       (let ((url (elpher-get-address-url address)))
1167         (message "Copied \"%s\" to kill-ring/clipboard." url)
1168         (kill-new url)))))
1169
1170 (defun elpher-copy-link-url ()
1171   "Copy URL of item at point to `kill-ring'."
1172   (interactive)
1173   (let ((button (button-at (point))))
1174     (if button
1175         (elpher-copy-node-url (button-get button 'elpher-node))
1176       (error "No item selected"))))
1177
1178 (defun elpher-copy-current-url ()
1179   "Copy URL of current node to `kill-ring'."
1180   (interactive)
1181   (elpher-copy-node-url elpher-current-node))
1182
1183 (defun elpher-set-coding-system ()
1184   "Specify an explicit character coding system."
1185   (interactive)
1186   (let ((system (read-coding-system "Set coding system to use (default is to autodetect): " nil)))
1187     (setq elpher-user-coding-system system)
1188     (if system
1189         (message "Coding system fixed to %s. (Reload to see effect)." system)
1190       (message "Coding system set to autodetect. (Reload to see effect)."))))
1191
1192
1193 ;;; Mode and keymap
1194 ;;
1195
1196 (defvar elpher-mode-map
1197   (let ((map (make-sparse-keymap)))
1198     (define-key map (kbd "TAB") 'elpher-next-link)
1199     (define-key map (kbd "<backtab>") 'elpher-prev-link)
1200     (define-key map (kbd "u") 'elpher-back)
1201     (define-key map (kbd "O") 'elpher-root-dir)
1202     (define-key map (kbd "g") 'elpher-go)
1203     (define-key map (kbd "o") 'elpher-go-current)
1204     (define-key map (kbd "r") 'elpher-redraw)
1205     (define-key map (kbd "R") 'elpher-reload)
1206     (define-key map (kbd "T") 'elpher-toggle-tls)
1207     (define-key map (kbd ".") 'elpher-view-raw)
1208     (define-key map (kbd "d") 'elpher-download)
1209     (define-key map (kbd "D") 'elpher-download-current)
1210     (define-key map (kbd "m") 'elpher-jump)
1211     (define-key map (kbd "i") 'elpher-info-link)
1212     (define-key map (kbd "I") 'elpher-info-current)
1213     (define-key map (kbd "c") 'elpher-copy-link-url)
1214     (define-key map (kbd "C") 'elpher-copy-current-url)
1215     (define-key map (kbd "a") 'elpher-bookmark-link)
1216     (define-key map (kbd "A") 'elpher-bookmark-current)
1217     (define-key map (kbd "x") 'elpher-unbookmark-link)
1218     (define-key map (kbd "X") 'elpher-unbookmark-current)
1219     (define-key map (kbd "B") 'elpher-bookmarks)
1220     (define-key map (kbd "S") 'elpher-set-coding-system)
1221     (when (fboundp 'evil-define-key)
1222       (evil-define-key 'motion map
1223         (kbd "TAB") 'elpher-next-link
1224         (kbd "C-]") 'elpher-follow-current-link
1225         (kbd "C-t") 'elpher-back
1226         (kbd "u") 'elpher-back
1227         (kbd "O") 'elpher-root-dir
1228         (kbd "g") 'elpher-go
1229         (kbd "o") 'elpher-go-current
1230         (kbd "r") 'elpher-redraw
1231         (kbd "R") 'elpher-reload
1232         (kbd "T") 'elpher-toggle-tls
1233         (kbd ".") 'elpher-view-raw
1234         (kbd "d") 'elpher-download
1235         (kbd "D") 'elpher-download-current
1236         (kbd "m") 'elpher-jump
1237         (kbd "i") 'elpher-info-link
1238         (kbd "I") 'elpher-info-current
1239         (kbd "c") 'elpher-copy-link-url
1240         (kbd "C") 'elpher-copy-current-url
1241         (kbd "a") 'elpher-bookmark-link
1242         (kbd "A") 'elpher-bookmark-current
1243         (kbd "x") 'elpher-unbookmark-link
1244         (kbd "X") 'elpher-unbookmark-current
1245         (kbd "B") 'elpher-bookmarks
1246         (kbd "S") 'elpher-set-coding-system))
1247     map)
1248   "Keymap for gopher client.")
1249
1250 (define-derived-mode elpher-mode special-mode "elpher"
1251   "Major mode for elpher, an elisp gopher client.
1252
1253 This mode is automatically enabled by the interactive
1254 functions which initialize the gopher client, namely
1255 `elpher', `elpher-go' and `elpher-bookmarks'.")
1256
1257 (when (fboundp 'evil-set-initial-state)
1258   (evil-set-initial-state 'elpher-mode 'motion))
1259
1260
1261 ;;; Main start procedure
1262 ;;
1263
1264 ;;;###autoload
1265 (defun elpher ()
1266   "Start elpher with default landing page."
1267   (interactive)
1268   (if (get-buffer "*elpher*")
1269       (switch-to-buffer "*elpher*")
1270     (switch-to-buffer "*elpher*")
1271     (setq elpher-current-node nil)
1272     (let ((start-node (elpher-make-node "Elpher Start Page"
1273                                         (elpher-make-address 'start))))
1274       (elpher-visit-node start-node)))
1275   "Started Elpher.") ; Otherwise (elpher) evaluates to start page string.
1276
1277 ;;; elpher.el ends here