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