Added URI percent decoding/encoding.
[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.6
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.6"
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       (funcall (car (alist-get type elpher-type-map))))))
309
310 (defun elpher-visit-parent-node ()
311   "Visit the parent of the current node."
312   (let ((parent-node (elpher-node-parent elpher-current-node)))
313     (when parent-node
314       (elpher-visit-node parent-node nil t))))
315       
316 (defun elpher-reload-current-node ()
317   "Reload the current node, discarding any existing cached content."
318   (elpher-cache-content (elpher-node-address elpher-current-node) nil)
319   (elpher-visit-node elpher-current-node))
320
321 (defun elpher-save-pos ()
322   "Save the current position of point to the current node."
323   (when elpher-current-node
324     (elpher-cache-pos (elpher-node-address elpher-current-node) (point))))
325
326 (defun elpher-restore-pos ()
327   "Restore the position of point to that cached in the current node."
328   (let ((pos (elpher-get-cached-pos (elpher-node-address elpher-current-node))))
329     (if pos
330         (goto-char pos)
331       (goto-char (point-min)))))
332
333
334 ;;; Buffer preparation
335 ;;
336
337 (defun elpher-update-header ()
338   "If `elpher-use-header' is true, display current node info in window header."
339   (if elpher-use-header
340       (setq header-line-format (elpher-node-display-string elpher-current-node))))
341
342 (defmacro elpher-with-clean-buffer (&rest args)
343   "Evaluate ARGS with a clean *elpher* buffer as current."
344   (list 'with-current-buffer "*elpher*"
345         '(elpher-mode)
346         (append (list 'let '((inhibit-read-only t))
347                       '(erase-buffer)
348                       '(elpher-update-header))
349                 args)))
350
351
352 ;;; Text Processing
353 ;;
354
355 (defvar elpher-user-coding-system nil
356   "User-specified coding system to use for decoding text responses.")
357
358 (defun elpher-decode (string)
359   "Decode STRING using autodetected or user-specified coding system."
360   (decode-coding-string string
361                         (if elpher-user-coding-system
362                             elpher-user-coding-system
363                           (detect-coding-string string t))))
364
365 (defun elpher-preprocess-text-response (string)
366   "Preprocess text selector response contained in STRING.
367 This involes decoding the character representation, and clearing
368 away CRs and any terminating period."
369   (elpher-decode (replace-regexp-in-string "\n\.\n$" "\n"
370                                            (replace-regexp-in-string "\r" "" string))))
371
372 ;;; Index rendering
373 ;;
374
375 (defun elpher-insert-index (string)
376   "Insert the index corresponding to STRING into the current buffer."
377   ;; Should be able to split directly on CRLF, but some non-conformant
378   ;; LF-only servers sadly exist, hence the following.
379   (let ((str-processed (elpher-preprocess-text-response string)))
380     (dolist (line (split-string str-processed "\n"))
381       (unless (= (length line) 0)
382         (let* ((type (elt line 0))
383                (fields (split-string (substring line 1) "\t"))
384                (display-string (elt fields 0))
385                (selector (elt fields 1))
386                (host (elt fields 2))
387                (port (if (elt fields 3)
388                          (string-to-number (elt fields 3))
389                        nil))
390                (address (elpher-make-address type selector host port)))
391           (elpher-insert-index-record display-string address))))))
392
393 (defun elpher-insert-margin (&optional type-name)
394   "Insert index margin, optionally containing the TYPE-NAME, into the current buffer."
395   (if type-name
396       (progn
397         (insert (format (concat "%" (number-to-string (- elpher-margin-width 1)) "s")
398                         (concat
399                          (propertize "[" 'face 'elpher-margin-brackets)
400                          (propertize type-name 'face 'elpher-margin-key)
401                          (propertize "]" 'face 'elpher-margin-brackets))))
402         (insert " "))
403     (insert (make-string elpher-margin-width ?\s))))
404
405 (defun elpher-node-button-help (node)
406   "Return a string containing the help text for a button corresponding to NODE."
407   (let ((address (elpher-node-address node)))
408     (if (eq (elpher-address-type address) ?h)
409         (let ((url (cadr (split-string (elpher-address-selector address) "URL:"))))
410           (format "mouse-1, RET: open url '%s'" url))
411       (format "mouse-1, RET: open '%s' on %s port %s"
412               (elpher-address-selector address)
413               (elpher-address-host address)
414               (elpher-address-port address)))))
415
416
417 (defun elpher-insert-index-record (display-string address)
418   "Function to insert an index record into the current buffer.
419 The contents of the record are dictated by DISPLAY-STRING and ADDRESS."
420   (let* ((type (elpher-address-type address))
421          (type-map-entry (alist-get type elpher-type-map)))
422     (if type-map-entry
423         (let* ((margin-code (elt type-map-entry 1))
424                (face (elt type-map-entry 2))
425                (node (elpher-make-node display-string address)))
426           (elpher-insert-margin margin-code)
427           (insert-text-button display-string
428                               'face face
429                               'elpher-node node
430                               'action #'elpher-click-link
431                               'follow-link t
432                               'help-echo (elpher-node-button-help node)))
433       (pcase type
434         (?i ;; Information
435          (elpher-insert-margin)
436          (insert (propertize
437                   (if elpher-buttonify-urls-in-directories
438                       (elpher-buttonify-urls display-string)
439                     display-string)
440                   'face 'elpher-info)))
441         (other ;; Unknown
442          (elpher-insert-margin (concat (char-to-string type) "?"))
443          (insert (propertize display-string
444                              'face 'elpher-unknown)))))
445     (insert "\n")))
446
447 (defun elpher-click-link (button)
448   "Function called when the gopher link BUTTON is activated (via mouse or keypress)."
449   (let ((node (button-get button 'elpher-node)))
450     (elpher-visit-node node)))
451
452
453 ;;; Selector retrieval (all kinds)
454 ;;
455
456 (defun elpher-process-cleanup ()
457   "Immediately shut down any extant elpher process."
458   (let ((p (get-process "elpher-process")))
459     (if p (delete-process p))))
460
461 (defvar elpher-use-tls nil
462   "If non-nil, use TLS to communicate with gopher servers.")
463
464 (defvar elpher-selector-string)
465
466 (defun elpher-get-selector (address after &optional propagate-error)
467   "Retrieve selector specified by ADDRESS, then execute AFTER.
468 The result is stored as a string in the variable â€˜elpher-selector-string’.
469
470 Usually errors result in an error page being displayed.  This is only
471 appropriate if the selector is to be directly viewed.  If PROPAGATE-ERROR
472 is non-nil, this message is not displayed.  Instead, the error propagates
473 up to the calling function."
474   (setq elpher-selector-string "")
475   (when (elpher-address-use-tls-p address)
476       (if (gnutls-available-p)
477           (when (not elpher-use-tls)
478             (setq elpher-use-tls t)
479             (message "Engaging TLS mode."))
480         (error "Cannot retrieve TLS selector: GnuTLS not available")))
481   (condition-case the-error
482       (let* ((kill-buffer-query-functions nil)
483              (proc (open-network-stream "elpher-process"
484                                        nil
485                                        (elpher-address-host address)
486                                        (elpher-address-port address)
487                                        :type (if elpher-use-tls 'tls 'plain))))
488         (set-process-coding-system proc 'binary)
489         (set-process-filter proc
490                             (lambda (proc string)
491                               (setq elpher-selector-string
492                                     (concat elpher-selector-string string))))
493         (set-process-sentinel proc after)
494         (process-send-string proc
495                              (concat (elpher-address-selector address) "\n")))
496     (error
497      (if (and (consp the-error)
498               (eq (car the-error) 'gnutls-error)
499               (not (elpher-address-use-tls-p address))
500               (or elpher-auto-disengage-TLS
501                   (yes-or-no-p "Could not establish encrypted connection.  Disable TLS mode? ")))
502          (progn
503            (message "Disengaging TLS mode.")
504            (setq elpher-use-tls nil)
505            (elpher-get-selector address after))
506        (elpher-process-cleanup)
507        (if propagate-error
508            (error the-error)
509          (elpher-with-clean-buffer
510           (insert (propertize "\n---- ERROR -----\n\n" 'face 'error)
511                   "Failed to connect to " (elpher-get-address-url address) ".\n"
512                   (propertize "\n----------------\n\n" 'face 'error)
513                   "Press 'u' to return to the previous page.")))))))
514
515 ;; Index retrieval
516
517 (defun elpher-get-index-node ()
518   "Getter which retrieves the current node contents as an index."
519   (let* ((address (elpher-node-address elpher-current-node))
520          (content (elpher-get-cached-content address)))
521     (if content
522         (progn
523           (elpher-with-clean-buffer
524            (insert content)
525            (elpher-restore-pos)))
526       (elpher-with-clean-buffer
527        (insert "LOADING DIRECTORY... (use 'u' to cancel)"))
528       (elpher-get-selector address
529                            (lambda (proc event)
530                              (unless (string-prefix-p "deleted" event)
531                                (elpher-with-clean-buffer
532                                 (elpher-insert-index elpher-selector-string)
533                                 (elpher-restore-pos)
534                                 (elpher-cache-content
535                                  (elpher-node-address elpher-current-node)
536                                  (buffer-string)))))))))
537
538 ;; Text retrieval
539
540 (defconst elpher-url-regex
541   "\\([a-zA-Z]+\\)://\\([a-zA-Z0-9.\-]+\\|\[[a-zA-Z0-9:]+\]\\)\\(?3::[0-9]+\\)?\\(?4:/[^ \r\n\t(),]*\\)?"
542   "Regexp used to locate and buttinofy URLs in text files loaded by elpher.")
543
544 (defun elpher-make-node-from-matched-url (&optional string)
545   "Convert most recent `elpher-url-regex' match to a node.
546
547 If STRING is non-nil, this is given as an argument to all `match-string'
548 calls, as is necessary if the match is performed by `string-match'."
549   (let ((url (match-string 0 string))
550         (protocol (downcase (match-string 1 string))))
551     (if (or (string= protocol "gopher")
552             (string= protocol "gophers"))
553         (let* ((bare-host (match-string 2 string))
554                (host (if (string-prefix-p "[" bare-host)
555                          (substring bare-host 1 (- (length bare-host) 1))
556                        bare-host))
557                (port (if (> (length (match-string 3 string))  1)
558                          (string-to-number (substring (match-string 3 string) 1))
559                        70))
560                (type-and-selector (match-string 4 string))
561                (type (if (> (length type-and-selector) 1)
562                          (elt type-and-selector 1)
563                        ?1))
564                (selector (decode-coding-string
565                           (url-unhex-string
566                            (if (> (length type-and-selector) 1)
567                                (substring type-and-selector 2)
568                              "")) 'utf-8))
569                (use-tls (string= protocol "gophers"))
570                (address (elpher-make-address type selector host port use-tls)))
571           (elpher-make-node url address))
572       (let* ((host (match-string 2 string))
573              (port (if (> (length (match-string 3 string)) 1)
574                        (string-to-number (substring (match-string 3 string) 1))
575                      70))
576              (selector (concat "URL:" url))
577              (address (elpher-make-address ?h selector host port)))
578         (elpher-make-node url address)))))
579
580
581 (defun elpher-buttonify-urls (string)
582   "Turn substrings which look like urls in STRING into clickable buttons."
583   (with-temp-buffer
584     (insert string)
585     (goto-char (point-min))
586     (while (re-search-forward elpher-url-regex nil t)
587         (let ((node (elpher-make-node-from-matched-url)))
588           (make-text-button (match-beginning 0)
589                             (match-end 0)
590                             'elpher-node  node
591                             'action #'elpher-click-link
592                             'follow-link t
593                             'help-echo (elpher-node-button-help node))))
594     (buffer-string)))
595
596 (defun elpher-get-text-node ()
597   "Getter which retrieves the current node contents as a text document."
598   (let* ((address (elpher-node-address elpher-current-node))
599          (content (elpher-get-cached-content address)))
600     (if content
601         (progn
602           (elpher-with-clean-buffer
603            (insert content)
604            (elpher-restore-pos)))
605       (progn
606         (elpher-with-clean-buffer
607          (insert "LOADING TEXT... (use 'u' to cancel)"))
608         (elpher-get-selector address
609                               (lambda (proc event)
610                                 (unless (string-prefix-p "deleted" event)
611                                   (elpher-with-clean-buffer
612                                    (insert (elpher-buttonify-urls
613                                             (elpher-preprocess-text-response
614                                              elpher-selector-string)))
615                                    (elpher-restore-pos)
616                                    (elpher-cache-content
617                                     (elpher-node-address elpher-current-node)
618                                     (buffer-string))))))))))
619
620 ;; Image retrieval
621
622 (defun elpher-get-image-node ()
623   "Getter which retrieves the current node contents as an image to view."
624   (let* ((address (elpher-node-address elpher-current-node))
625          (content (elpher-get-cached-content address)))
626     (if content
627         (progn
628           (elpher-with-clean-buffer
629            (insert-image content)
630            (elpher-restore-pos)))
631       (if (display-images-p)
632           (progn
633             (elpher-with-clean-buffer
634              (insert "LOADING IMAGE... (use 'u' to cancel)"))
635             (elpher-get-selector address
636                                  (lambda (proc event)
637                                    (unless (string-prefix-p "deleted" event)
638                                      (let ((image (create-image
639                                                    elpher-selector-string
640                                                    nil t)))
641                                        (elpher-with-clean-buffer
642                                         (insert-image image)
643                                         (elpher-restore-pos))
644                                        (if elpher-cache-images
645                                            (elpher-cache-content
646                                             (elpher-node-address elpher-current-node)
647                                             image)))))))
648         (elpher-get-node-download)))))
649
650 ;; Search retrieval
651
652 (defun elpher-get-search-node ()
653   "Getter which submits a search query to the address of the current node."
654   (let* ((address (elpher-node-address elpher-current-node))
655          (content (elpher-get-cached-content address))
656          (aborted t))
657     (if content
658         (progn
659           (elpher-with-clean-buffer
660            (insert content)
661            (elpher-restore-pos))
662           (message "Displaying cached search results.  Reload to perform a new search."))
663       (unwind-protect
664           (let* ((query-string (read-string "Query: "))
665                  (query-selector (concat (elpher-address-selector address) "\t" query-string))
666                  (search-address (elpher-make-address ?1
667                                                       query-selector
668                                                       (elpher-address-host address)
669                                                       (elpher-address-port address))))
670             (setq aborted nil)
671             (elpher-with-clean-buffer
672              (insert "LOADING RESULTS... (use 'u' to cancel)"))
673             (elpher-get-selector search-address
674                                   (lambda (proc event)
675                                     (unless (string-prefix-p "deleted" event)
676                                       (elpher-with-clean-buffer
677                                        (elpher-insert-index elpher-selector-string))
678                                       (goto-char (point-min))
679                                       (elpher-cache-content
680                                        (elpher-node-address elpher-current-node)
681                                        (buffer-string))))))
682         (if aborted
683             (elpher-visit-parent-node))))))
684
685 ;; Raw server response retrieval
686
687 (defun elpher-get-node-raw ()
688   "Getter which retrieves the raw server response for the current node."
689   (let ((address (elpher-node-address elpher-current-node)))
690     (elpher-with-clean-buffer
691      (insert "LOADING RAW SERVER RESPONSE... (use 'u' to cancel)"))
692     (elpher-get-selector address
693                          (lambda (proc event)
694                            (unless (string-prefix-p "deleted" event)
695                              (elpher-with-clean-buffer
696                               (insert elpher-selector-string)
697                               (goto-char (point-min)))))))
698   (message "Displaying raw server response.  Reload or redraw to return to standard view."))
699  
700 ;; File export retrieval
701
702 (defvar elpher-download-filename)
703
704 (defun elpher-get-node-download ()
705   "Getter which retrieves the current node and writes the result to a file."
706   (let* ((address (elpher-node-address elpher-current-node))
707          (selector (elpher-address-selector address)))
708     (elpher-visit-parent-node) ; Do first in case of non-local exits.
709     (let* ((filename-proposal (file-name-nondirectory selector))
710            (filename (read-file-name "Save file as: "
711                                      nil nil nil
712                                      (if (> (length filename-proposal) 0)
713                                          filename-proposal
714                                        "gopher.file"))))
715       (message "Downloading...")
716       (setq elpher-download-filename filename)
717       (condition-case the-error
718           (elpher-get-selector address
719                                (lambda (proc event)
720                                  (let ((coding-system-for-write 'binary))
721                                    (with-temp-file elpher-download-filename
722                                      (insert elpher-selector-string)
723                                      (message (format "Download complate, saved to file %s."
724                                                       elpher-download-filename)))))
725                                t)
726         (error
727          (error "Error downloading %s" elpher-download-filename))))))
728
729 ;; URL retrieval
730
731 (defun elpher-insert-rendered-html (string)
732   "Use shr to insert rendered view of html STRING into current buffer."
733   (let ((dom (with-temp-buffer
734                (insert string)
735                (libxml-parse-html-region (point-min) (point-max)))))
736     (shr-insert-document dom)))
737
738 (defun elpher-get-url-node ()
739   "Getter which attempts to open the URL specified by the current node."
740   (let* ((address (elpher-node-address elpher-current-node))
741          (selector (elpher-address-selector address)))
742     (let ((url (elt (split-string selector "URL:") 1)))
743       (if url
744           (progn
745             (elpher-visit-parent-node) ; Do first in case of non-local exits.
746             (message "Opening URL...")
747             (if elpher-open-urls-with-eww
748                 (browse-web url)
749               (browse-url url)))
750         (let ((content (elpher-get-cached-content address)))
751           (if content
752               (progn
753                 (elpher-with-clean-buffer
754                  (insert content)
755                  (elpher-restore-pos)))
756             (elpher-with-clean-buffer
757              (insert "LOADING HTML... (use 'u' to cancel)"))
758             (elpher-get-selector address
759                                  (lambda (proc event)
760                                    (unless (string-prefix-p "deleted" event)
761                                      (elpher-with-clean-buffer
762                                       (elpher-insert-rendered-html elpher-selector-string)
763                                       (goto-char (point-min))
764                                       (elpher-cache-content
765                                        (elpher-node-address elpher-current-node)
766                                        (buffer-string))))))))))))
767
768 ;; Telnet node connection
769
770 (defun elpher-get-telnet-node ()
771   "Getter which opens a telnet connection to the server specified by the current node."
772   (let* ((address (elpher-node-address elpher-current-node))
773          (host (elpher-address-host address))
774          (port (elpher-address-port address)))
775     (elpher-visit-parent-node)
776     (telnet host port)))
777
778 ;; Start page node retrieval
779
780 (defun elpher-get-start-node ()
781   "Getter which displays the start page."
782   (elpher-with-clean-buffer
783    (insert "     --------------------------------------------\n"
784            "                Elpher Gopher Client             \n"
785            "                   version " elpher-version "\n"
786            "     --------------------------------------------\n"
787            "\n"
788            "Default bindings:\n"
789            "\n"
790            " - TAB/Shift-TAB: next/prev item on current page\n"
791            " - RET/mouse-1: open item under cursor\n"
792            " - m: select an item on current page by name (autocompletes)\n"
793            " - u: return to previous page\n"
794            " - o/O: visit different selector or the root menu of the current server\n"
795            " - g: go to a particular gopher address\n"
796            " - i/I: info on item under cursor or current page\n"
797            " - c/C: copy URL representation of item under cursor or current page\n"
798            " - a/A: bookmark the item under cursor or current page\n"
799            " - x/X: remove bookmark for item under cursor or current page\n"
800            " - B: visit the bookmarks page\n"
801            " - r: redraw current page (using cached contents if available)\n"
802            " - R: reload current page (regenerates cache)\n"
803            " - T: toggle TLS mode\n"
804            " - d/D: download item under cursor or current page\n"
805            " - w: display the raw server response for the current page\n"
806            " - S: set an explicit character coding system (default is to autodetect)\n"
807            "\n"
808            "Start your exploration of gopher space:\n")
809    (elpher-insert-index-record "Floodgap Systems Gopher Server"
810                                (elpher-make-address ?1 "" "gopher.floodgap.com" 70))
811    (insert "\n"
812            "Alternatively, select the following item and enter some search terms:\n")
813    (elpher-insert-index-record "Veronica-2 Gopher Search Engine"
814                                (elpher-make-address ?7 "/v2/vs" "gopher.floodgap.com" 70))
815    (insert "\n"
816            "** Refer to the ")
817    (let ((help-string "RET,mouse-1: Open Elpher info manual (if available)"))
818      (insert-text-button "Elpher info manual"
819                          'face 'link
820                          'action (lambda (button)
821                                    (interactive)
822                                    (info "(elpher)"))
823                          'follow-link t
824                          'help-echo help-string))
825    (insert " for the full documentation. **\n")
826    (insert (propertize
827             (concat "  (This should be available if you have installed Elpher using\n"
828                     "   MELPA. Otherwise you will have to install the manual yourself.)")
829             'face 'shadow))
830    (elpher-restore-pos)))
831
832 ;; Bookmarks page node retrieval
833
834 (defun elpher-get-bookmarks-node ()
835   "Getter to load and display the current bookmark list."
836   (elpher-with-clean-buffer
837    (insert "---- Bookmark list ----\n\n")
838    (let ((bookmarks (elpher-load-bookmarks)))
839      (if bookmarks
840          (dolist (bookmark bookmarks)
841            (let ((display-string (elpher-bookmark-display-string bookmark))
842                  (address (elpher-bookmark-address bookmark)))
843              (elpher-insert-index-record display-string address)))
844        (insert "No bookmarks found.\n")))
845    (insert "\n-----------------------\n\n"
846            "- u: return to previous page\n"
847            "- x: delete selected bookmark\n"
848            "- a: rename selected bookmark\n\n"
849            "Bookmarks are stored in the file "
850            (locate-user-emacs-file "elpher-bookmarks"))
851    (elpher-restore-pos)))
852   
853
854 ;;; Bookmarks
855 ;;
856
857 (defun elpher-make-bookmark (display-string address)
858   "Make an elpher bookmark.
859 DISPLAY-STRING determines how the bookmark will appear in the
860 bookmark list, while ADDRESS is the address of the entry."
861   (list display-string address))
862   
863 (defun elpher-bookmark-display-string (bookmark)
864   "Get the display string of BOOKMARK."
865   (elt bookmark 0))
866
867 (defun elpher-set-bookmark-display-string (bookmark display-string)
868   "Set the display string of BOOKMARK to DISPLAY-STRING."
869   (setcar bookmark display-string))
870
871 (defun elpher-bookmark-address (bookmark)
872   "Get the address for BOOKMARK."
873   (elt bookmark 1))
874
875 (defun elpher-save-bookmarks (bookmarks)
876   "Record the bookmark list BOOKMARKS to the user's bookmark file.
877 Beware that this completely replaces the existing contents of the file."
878   (with-temp-file (locate-user-emacs-file "elpher-bookmarks")
879     (erase-buffer)
880     (insert "; Elpher gopher bookmarks file\n\n"
881             "; Bookmarks are stored as a list of (label (type selector host port))\n"
882             "; s-expressions, where type is stored as a character (i.e. 49 = ?1).\n"
883             "; Feel free to edit by hand, but ensure this structure remains intact.\n\n")
884     (pp bookmarks (current-buffer))))
885
886 (defun elpher-load-bookmarks ()
887   "Get the list of bookmarks from the users's bookmark file."
888   (with-temp-buffer
889     (ignore-errors
890       (insert-file-contents (locate-user-emacs-file "elpher-bookmarks"))
891       (goto-char (point-min))
892       (read (current-buffer)))))
893
894 (defun elpher-add-address-bookmark (address display-string)
895   "Save a bookmark for ADDRESS with label DISPLAY-STRING.
896 If ADDRESS is already bookmarked, update the label only."
897   (let ((bookmarks (elpher-load-bookmarks)))
898     (let ((existing-bookmark (rassoc (list address) bookmarks)))
899       (if existing-bookmark
900           (elpher-set-bookmark-display-string existing-bookmark display-string)
901         (add-to-list 'bookmarks (elpher-make-bookmark display-string address))))
902     (elpher-save-bookmarks bookmarks)))
903
904 (defun elpher-remove-address-bookmark (address)
905   "Remove any bookmark to ADDRESS."
906     (elpher-save-bookmarks
907      (seq-filter (lambda (bookmark)
908                    (not (equal (elpher-bookmark-address bookmark) address)))
909                  (elpher-load-bookmarks))))
910
911
912 ;;; Interactive procedures
913 ;;
914
915 (defun elpher-next-link ()
916   "Move point to the next link on the current page."
917   (interactive)
918   (forward-button 1))
919
920 (defun elpher-prev-link ()
921   "Move point to the previous link on the current page."
922   (interactive)
923   (backward-button 1))
924
925 (defun elpher-follow-current-link ()
926   "Open the link or url at point."
927   (interactive)
928   (push-button))
929
930 (defun elpher-go ()
931   "Go to a particular gopher site read from the minibuffer.
932 The site may be specified via a URL or explicitly in terms of
933 host, selector and port."
934   (interactive)
935   (let ((node
936          (let ((host-or-url (read-string "Gopher host or URL: ")))
937            (if (string-match elpher-url-regex host-or-url)
938                (elpher-make-node-from-matched-url host-or-url)
939              (let ((selector (read-string "Selector (default none): " nil nil ""))
940                    (port-string (read-string "Port (default 70): " nil nil "70")))
941                (elpher-make-node (concat "gopher://" host-or-url
942                                          ":" port-string
943                                          "/1" selector)
944                                  (elpher-make-address ?1 selector host-or-url
945                                                       (string-to-number port-string))))))))
946     (switch-to-buffer "*elpher*")
947     (elpher-visit-node node)))
948
949 (defun elpher-go-current ()
950   "Go to a particular site read from the minibuffer, initialized with the current URL."
951   (interactive)
952   (let ((address (elpher-node-address elpher-current-node)))
953     (if (elpher-address-special-p address)
954         (error "Command not valid for this page")
955       (let ((url (read-string "URL: " (elpher-get-address-url address))))
956         (if (string-match elpher-url-regex url)
957             (let ((new-node (elpher-make-node-from-matched-url url)))
958               (unless (equal (elpher-node-address new-node) address)
959                 (elpher-visit-node new-node)))
960           (error "Could not parse URL %s" url))))))
961
962 (defun elpher-redraw ()
963   "Redraw current page."
964   (interactive)
965   (if elpher-current-node
966       (elpher-visit-node elpher-current-node)
967     (message "No current site.")))
968
969 (defun elpher-reload ()
970   "Reload current page."
971   (interactive)
972   (if elpher-current-node
973       (elpher-reload-current-node)
974     (message "No current site.")))
975
976 (defun elpher-toggle-tls ()
977   "Toggle TLS encryption mode."
978   (interactive)
979   (setq elpher-use-tls (not elpher-use-tls))
980   (if elpher-use-tls
981       (if (gnutls-available-p)
982           (message "TLS mode enabled.  (Will not affect current page until reload.)")
983         (setq elpher-use-tls nil)
984         (error "Cannot enable TLS mode: GnuTLS not available"))
985     (message "TLS mode disabled.  (Will not affect current page until reload.)")))
986
987 (defun elpher-view-raw ()
988   "View raw server response for current page."
989   (interactive)
990   (if elpher-current-node
991       (if (elpher-address-special-p (elpher-node-address elpher-current-node))
992           (error "This page was not generated by a server")
993         (elpher-visit-node elpher-current-node
994                            #'elpher-get-node-raw))
995     (message "No current site.")))
996
997 (defun elpher-back ()
998   "Go to previous site."
999   (interactive)
1000   (if (elpher-node-parent elpher-current-node)
1001       (elpher-visit-parent-node)
1002     (error "No previous site")))
1003
1004 (defun elpher-download ()
1005   "Download the link at point."
1006   (interactive)
1007   (let ((button (button-at (point))))
1008     (if button
1009         (let ((node (button-get button 'elpher-node)))
1010           (if (elpher-address-special-p (elpher-node-address node))
1011               (error "Cannot download this link")
1012             (elpher-visit-node (button-get button 'elpher-node)
1013                                #'elpher-get-node-download)))
1014       (error "No link selected"))))
1015
1016 (defun elpher-download-current ()
1017   "Download the current page."
1018   (interactive)
1019   (if (elpher-address-special-p (elpher-node-address elpher-current-node))
1020       (error "Cannot download this page")
1021     (elpher-visit-node (elpher-make-node
1022                         (elpher-node-display-string elpher-current-node)
1023                         (elpher-node-address elpher-current-node)
1024                         elpher-current-node)
1025                        #'elpher-get-node-download
1026                        t)))
1027
1028 (defun elpher-build-link-map ()
1029   "Build alist mapping link names to destination nodes in current buffer."
1030   (let ((link-map nil)
1031         (b (next-button (point-min) t)))
1032     (while b
1033       (add-to-list 'link-map (cons (button-label b) b))
1034       (setq b (next-button (button-start b))))
1035     link-map))
1036
1037 (defun elpher-jump ()
1038   "Select a directory entry by name.  Similar to the info browser (m)enu command."
1039   (interactive)
1040   (let* ((link-map (elpher-build-link-map)))
1041     (if link-map
1042         (let ((key (let ((completion-ignore-case t))
1043                      (completing-read "Directory item/link: "
1044                                       link-map nil t))))
1045           (if (and key (> (length key) 0))
1046               (let ((b (cdr (assoc key link-map))))
1047                 (goto-char (button-start b))
1048                 (button-activate b)))))))
1049
1050 (defun elpher-root-dir ()
1051   "Visit root of current server."
1052   (interactive)
1053   (let* ((address (elpher-node-address elpher-current-node))
1054          (host (elpher-address-host address)))
1055     (if host
1056         (let ((host (elpher-address-host address))
1057               (selector (elpher-address-selector address))
1058               (port (elpher-address-port address)))
1059           (if (> (length selector) 0)
1060               (let ((root-address (elpher-make-address ?1 "" host port)))
1061                 (elpher-visit-node
1062                  (elpher-make-node (concat "gopher://" host
1063                                            ":" (number-to-string port)
1064                                            "/1/")
1065                                    root-address)))
1066             (error "Already at root directory of current server")))
1067       (error "Command invalid for this page"))))
1068
1069 (defun elpher-bookmarks-current-p ()
1070   "Return non-nil if current node is a bookmarks page."
1071   (eq (elpher-address-type (elpher-node-address elpher-current-node)) 'bookmarks))
1072
1073 (defun elpher-reload-bookmarks ()
1074   "Reload bookmarks if current node is a bookmarks page."
1075   (if (elpher-bookmarks-current-p)
1076       (elpher-reload-current-node)))
1077
1078 (defun elpher-bookmark-current ()
1079   "Bookmark the current node."
1080   (interactive)
1081   (let ((address (elpher-node-address elpher-current-node))
1082         (display-string (elpher-node-display-string elpher-current-node)))
1083     (if (not (elpher-address-special-p address))
1084         (let ((bookmark-display-string (read-string "Bookmark display string: "
1085                                                     display-string)))
1086           (elpher-add-address-bookmark address bookmark-display-string)
1087           (message "Bookmark added."))
1088       (error "Cannot bookmark %s" display-string))))
1089
1090 (defun elpher-bookmark-link ()
1091   "Bookmark the link at point."
1092   (interactive)
1093   (let ((button (button-at (point))))
1094     (if button
1095         (let* ((node (button-get button 'elpher-node))
1096                (address (elpher-node-address node))
1097                (display-string (elpher-node-display-string node)))
1098           (if (not (elpher-address-special-p address))
1099               (let ((bookmark-display-string (read-string "Bookmark display string: "
1100                                                           display-string)))
1101                 (elpher-add-address-bookmark address bookmark-display-string)
1102                 (elpher-reload-bookmarks)
1103                 (message "Bookmark added."))
1104             (error "Cannot bookmark %s" display-string)))
1105       (error "No link selected"))))
1106
1107 (defun elpher-unbookmark-current ()
1108   "Remove bookmark for the current node."
1109   (interactive)
1110   (let ((address (elpher-node-address elpher-current-node)))
1111     (unless (elpher-address-special-p address)
1112       (elpher-remove-address-bookmark address)
1113       (message "Bookmark removed."))))
1114
1115 (defun elpher-unbookmark-link ()
1116   "Remove bookmark for the link at point."
1117   (interactive)
1118   (let ((button (button-at (point))))
1119     (if button
1120         (let ((node (button-get button 'elpher-node)))
1121           (elpher-remove-address-bookmark (elpher-node-address node))
1122           (elpher-reload-bookmarks)
1123           (message "Bookmark removed."))
1124       (error "No link selected"))))
1125
1126 (defun elpher-bookmarks ()
1127   "Visit bookmarks page."
1128   (interactive)
1129   (switch-to-buffer "*elpher*")
1130   (elpher-visit-node
1131    (elpher-make-node "Bookmarks Page" (elpher-make-address 'bookmarks))))
1132
1133 (defun elpher-info-node (node)
1134   "Display information on NODE."
1135   (let ((display-string (elpher-node-display-string node))
1136         (address (elpher-node-address node)))
1137     (if (not (elpher-address-special-p address))
1138         (message "`%s' on %s port %s"
1139                 (elpher-address-selector address)
1140                 (elpher-address-host address)
1141                 (elpher-address-port address))
1142       (message "%s" display-string))))
1143
1144 (defun elpher-info-link ()
1145   "Display information on node corresponding to link at point."
1146   (interactive)
1147   (let ((button (button-at (point))))
1148     (if button
1149         (elpher-info-node (button-get button 'elpher-node))
1150       (error "No item selected"))))
1151   
1152 (defun elpher-info-current ()
1153   "Display information on current node."
1154   (interactive)
1155   (elpher-info-node elpher-current-node))
1156
1157 (defun elpher-copy-node-url (node)
1158   "Copy URL representation of address of NODE to `kill-ring'."
1159   (let ((address (elpher-node-address node)))
1160     (if (elpher-address-special-p address)
1161         (error (format "Cannot represent %s as URL" (elpher-node-display-string node)))
1162       (let ((url (elpher-get-address-url address)))
1163         (message "Copied \"%s\" to kill-ring/clipboard." url)
1164         (kill-new url)))))
1165
1166 (defun elpher-copy-link-url ()
1167   "Copy URL of item at point to `kill-ring'."
1168   (interactive)
1169   (let ((button (button-at (point))))
1170     (if button
1171         (elpher-copy-node-url (button-get button 'elpher-node))
1172       (error "No item selected"))))
1173
1174 (defun elpher-copy-current-url ()
1175   "Copy URL of current node to `kill-ring'."
1176   (interactive)
1177   (elpher-copy-node-url elpher-current-node))
1178
1179 (defun elpher-set-coding-system ()
1180   "Specify an explicit character coding system."
1181   (interactive)
1182   (let ((system (read-coding-system "Set coding system to use (default is to autodetect): " nil)))
1183     (setq elpher-user-coding-system system)
1184     (if system
1185         (message "Coding system fixed to %s. (Reload to see effect)." system)
1186       (message "Coding system set to autodetect. (Reload to see effect)."))))
1187
1188
1189 ;;; Mode and keymap
1190 ;;
1191
1192 (defvar elpher-mode-map
1193   (let ((map (make-sparse-keymap)))
1194     (define-key map (kbd "TAB") 'elpher-next-link)
1195     (define-key map (kbd "<backtab>") 'elpher-prev-link)
1196     (define-key map (kbd "u") 'elpher-back)
1197     (define-key map (kbd "O") 'elpher-root-dir)
1198     (define-key map (kbd "g") 'elpher-go)
1199     (define-key map (kbd "o") 'elpher-go-current)
1200     (define-key map (kbd "r") 'elpher-redraw)
1201     (define-key map (kbd "R") 'elpher-reload)
1202     (define-key map (kbd "T") 'elpher-toggle-tls)
1203     (define-key map (kbd "w") 'elpher-view-raw)
1204     (define-key map (kbd "d") 'elpher-download)
1205     (define-key map (kbd "D") 'elpher-download-current)
1206     (define-key map (kbd "m") 'elpher-jump)
1207     (define-key map (kbd "i") 'elpher-info-link)
1208     (define-key map (kbd "I") 'elpher-info-current)
1209     (define-key map (kbd "c") 'elpher-copy-link-url)
1210     (define-key map (kbd "C") 'elpher-copy-current-url)
1211     (define-key map (kbd "a") 'elpher-bookmark-link)
1212     (define-key map (kbd "A") 'elpher-bookmark-current)
1213     (define-key map (kbd "x") 'elpher-unbookmark-link)
1214     (define-key map (kbd "X") 'elpher-unbookmark-current)
1215     (define-key map (kbd "B") 'elpher-bookmarks)
1216     (define-key map (kbd "S") 'elpher-set-coding-system)
1217     (when (fboundp 'evil-define-key)
1218       (evil-define-key 'motion map
1219         (kbd "TAB") 'elpher-next-link
1220         (kbd "C-]") 'elpher-follow-current-link
1221         (kbd "C-t") 'elpher-back
1222         (kbd "u") 'elpher-back
1223         (kbd "O") 'elpher-root-dir
1224         (kbd "g") 'elpher-go
1225         (kbd "o") 'elpher-go-current
1226         (kbd "r") 'elpher-redraw
1227         (kbd "R") 'elpher-reload
1228         (kbd "T") 'elpher-toggle-tls
1229         (kbd "w") 'elpher-view-raw
1230         (kbd "d") 'elpher-download
1231         (kbd "D") 'elpher-download-current
1232         (kbd "m") 'elpher-jump
1233         (kbd "i") 'elpher-info-link
1234         (kbd "I") 'elpher-info-current
1235         (kbd "c") 'elpher-copy-link-url
1236         (kbd "C") 'elpher-copy-current-url
1237         (kbd "a") 'elpher-bookmark-link
1238         (kbd "A") 'elpher-bookmark-current
1239         (kbd "x") 'elpher-unbookmark-link
1240         (kbd "X") 'elpher-unbookmark-current
1241         (kbd "B") 'elpher-bookmarks
1242         (kbd "S") 'elpher-set-coding-system))
1243     map)
1244   "Keymap for gopher client.")
1245
1246 (define-derived-mode elpher-mode special-mode "elpher"
1247   "Major mode for elpher, an elisp gopher client.
1248
1249 This mode is automatically enabled by the interactive
1250 functions which initialize the gopher client, namely
1251 `elpher', `elpher-go' and `elpher-bookmarks'.")
1252
1253 (when (fboundp 'evil-set-initial-state)
1254   (evil-set-initial-state 'elpher-mode 'motion))
1255
1256
1257 ;;; Main start procedure
1258 ;;
1259
1260 ;;;###autoload
1261 (defun elpher ()
1262   "Start elpher with default landing page."
1263   (interactive)
1264   (if (get-buffer "*elpher*")
1265       (switch-to-buffer "*elpher*")
1266     (switch-to-buffer "*elpher*")
1267     (setq elpher-current-node nil)
1268     (let ((start-node (elpher-make-node "Elpher Start Page"
1269                                         (elpher-make-address 'start))))
1270       (elpher-visit-node start-node)))
1271   "Started Elpher.") ; Otherwise (elpher) evaluates to start page string.
1272
1273 ;;; elpher.el ends here