More delinting.
[elpher.git] / elpher.el
index 6530949..29d2e2b 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -21,7 +21,7 @@
 ;; Created: 11 April 2019
 ;; Version: 2.11.0
 ;; Keywords: comm gopher
-;; Homepage: https://alexschroeder.ch/cgit/elpher
+;; Homepage: https://thelambdalab.xyz/elpher
 ;; Package-Requires: ((emacs "27.1"))
 
 ;; This file is not part of GNU Emacs.
@@ -62,7 +62,8 @@
 
 ;; Elpher is under active development.  Any suggestions for
 ;; improvements are welcome, and can be made on the official
-;; project page, https://alexschroeder.ch/cgit/elpher.
+;; project page, gopher://thelambdalab.xyz/elpher, or via the
+;; project mailing list at https://lists.sr.ht/~michel-slm/elpher.
 
 ;;; Code:
 
 (defalias 'elpher-color-filter-apply
   (if (fboundp 'xterm-color-filter)
       (lambda (s)
-        (let ((xterm-color-render nil))
+        (let ((_xterm-color-render nil))
           (xterm-color-filter s)))
     'ansi-color-filter-apply)
   "A function to filter out ANSI escape sequences.")
+
 (defalias 'elpher-color-apply
   (if (fboundp 'xterm-color-filter)
       'xterm-color-filter
 (defvar elpher--gemini-page-headings nil
   "List of headings on the page.")
 
+;;; Declarations to avoid compiler warnings.
+;;
+
+(eval-when-compile
+  (defvar bookmark-make-record-function)
+  (declare-function bookmark-store "bookmark")
+  (declare-function org-link-store-props "ol")
+  (declare-function org-link-set-parameters "ol")
+  (defvar thing-at-point-uri-schemes)
+  (defvar mu4e~view-beginning-of-url-regexp))
+
 
 ;;; Customization group
 ;;
@@ -531,8 +544,7 @@ unless NO-HISTORY is non-nil."
   (setq-local elpher-current-page page)
   (let* ((address (elpher-page-address page))
          (type (elpher-address-type address))
-         (type-record (cdr (assoc type elpher-type-map)))
-         (page-links nil))
+         (type-record (cdr (assoc type elpher-type-map))))
     (if type-record
         (funcall (car type-record)
                  (if renderer
@@ -1007,12 +1019,14 @@ displayed.  The _WINDOW argument is currently unused."
                                                 address
                                               (elpher-address-to-url address))))))))
 
-(defvar elpher--link-number-counter 0)
+(defvar elpher--link-number-counter 0
+  "Used to number links on elpher pages.")
 (defun elpher-reset-link-number-counter ()
+  "Reset the link number counter."
   (setq-local elpher--link-number-counter 0))
 
 (defun elpher--insert-text-button (label &rest properties)
-  "Inserts a potentially-numbered button into the current buffer.
+  "Insert a potentially-numbered button into the current buffer.
 The text for the button is provided by LABEL, while the button
 properties in PROPERTIES are as per `insert-text-button'."
 
@@ -1288,10 +1302,15 @@ that the response was malformed."
          (error "Gemini server response unknown: %s %s"
                 response-code response-meta))))))
 
-(unless (fboundp 'read-answer)
-  (defun read-answer (question answers)
-    "Backfill for the new read-answer code."
-    (completing-read question (mapcar 'identity answers))))
+(defun elpher--read-answer-polyfill (question answers)
+  "Polyfill for `read-answer' in Emacs 26.1.
+QUESTION is a string containing a question, and ANSWERS
+is a list of possible answers."
+    (completing-read question (mapcar 'identity answers)))
+
+(if (fboundp 'read-answer)
+    (defalias 'elpher-read-answer 'read-answer)
+  (defalias 'elpher-read-answer 'elpher--read-answer-polyfill))
 
 (defun elpher-choose-client-certificate ()
   "Prompt for a client certificate to use to establish a TLS connection."
@@ -1652,6 +1671,20 @@ The result is rendered using RENDERER."
                                (elpher-make-gopher-address ?7 "/v2/vs" "gopher.floodgap.com" 70))
    (elpher-insert-index-record "Gemini Search Engine (geminispace.info)"
                                (elpher-address-from-url "gemini://geminispace.info/search"))
+   (insert "\n"
+           "Your bookmarks are stored in your ")
+   (let ((help-string "RET,mouse-1: Open Emacs bookmark list"))
+     (elpher--insert-text-button "Emacs bookmark list"
+                                'face 'link
+                                'action (lambda (_)
+                                          (interactive)
+                                          (call-interactively #'bookmark-bmenu-list))
+                                'follow-link t
+                                'help-echo help-string))
+   (insert ".\n")
+   (insert (propertize
+            "(Bookmarks from legacy elpher-bookmarks files will be automatically imported.)\n"
+            'face 'shadow))
    (insert "\n"
            "For Elpher release news or to leave feedback, visit:\n")
    (elpher-insert-index-record "The Elpher Project Page"
@@ -1796,11 +1829,6 @@ To bookmark the current page, use \\[bookmark-set-no-overwrite]."
 
 ;;; Org
 
-;; Avoid byte compilation warnings.
-(eval-when-compile
-  (declare-function org-link-store-props "ol")
-  (declare-function org-link-set-parameters "ol"))
-
 (defun elpher-org-export-link (link description format protocol)
   "Export a LINK with DESCRIPTION for the given PROTOCOL and FORMAT.
 
@@ -1844,7 +1872,8 @@ supports the old protocol elpher, where the link is self-contained."
                (format "%s:%s" protocol link))))
     (elpher-go url)))
 
-(with-eval-after-load 'org
+(defun elpher-org-mode-integration ()
+  "Set up `elpher' integration for `org-mode'."
   (org-link-set-parameters
    "elpher"
    :store #'elpher-org-store-link
@@ -1867,11 +1896,9 @@ supports the old protocol elpher, where the link is self-contained."
              (elpher-org-export-link link description format "finger"))
    :follow (lambda (link _arg) (elpher-org-follow-link link "finger"))))
 
-;;; Browse URL
+(add-hook 'org-mode-hook #'elpher-org-mode-integration)
 
-;; Avoid byte compilation warnings.
-(eval-when-compile
-  (defvar thing-at-point-uri-schemes))
+;;; Browse URL
 
 ;;;###autoload
 (defun elpher-browse-url-elpher (url &rest _args)
@@ -1905,13 +1932,9 @@ supports the old protocol elpher, where the link is self-contained."
 
 ;;; Mu4e:
 
-(eval-when-compile
-  (defvar mu4e~view-beginning-of-url-regexp))
-
-(with-eval-after-load 'mu4e-view
-  ;; Make mu4e aware of the gemini world
-  (setq mu4e~view-beginning-of-url-regexp
-        "\\(?:https?\\|gopher\\|finger\\|gemini\\)://\\|mailto:"))
+;; Make mu4e aware of the gemini world
+(setq mu4e~view-beginning-of-url-regexp
+      "\\(?:https?\\|gopher\\|finger\\|gemini\\)://\\|mailto:")
 
 ;;; Interactive procedures
 ;;
@@ -2050,7 +2073,7 @@ When run interactively HOST-OR-URL is read from the minibuffer."
             (let ((b (cdr (elt link-map (- n 1)))))
               (goto-char (button-start b))
               (button-activate b))
-          (error "No link with that number.")))))
+          (error "No link with that number")))))
 
 (defun elpher-root-dir ()
   "Visit root of current server."
@@ -2199,7 +2222,7 @@ functions which initialize the client, namely
   (setq-local elpher-history nil)
   (setq-local elpher-buffer-name (buffer-name))
   (setq-local bookmark-make-record-function #'elpher-bookmark-make-record)
-  (setq-local imenu-create-index-function #'elpher--gemini-page-headings))
+  (setq-local imenu-create-index-function (lambda () elpher--gemini-page-headings)))
 
 (when (fboundp 'evil-set-initial-state)
   (evil-set-initial-state 'elpher-mode 'motion))