;; 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.
;; 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
;;
(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
If non-nil, FORCE-IPV4 causes the network connection to be made over
ipv4 only. (The default behaviour when this is not set depends on
-the host operating system and the local network capabilities."
+the host operating system and the local network capabilities.)"
(if (and use-tls (not (gnutls-available-p)))
(error "Use of TLS requires Emacs to be compiled with GNU TLS support")
(unless (< (elpher-address-port address) 65536)
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'."
(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."
" - c/C: copy URL representation of item under cursor or current page\n"
" - a/A: bookmark the item under cursor or current page\n"
" - B: list all bookmarks\n"
- " - h/H: show history of current buffer or for all buffers\n"
+ " - s/S: show history of current buffer or for all buffers\n"
" - r: redraw current page (using cached contents if available)\n"
" - R: reload current page (regenerates cache)\n"
- " - S: set character coding system for gopher (default is to autodetect)\n"
+ " - !: set character coding system for gopher (default is to autodetect)\n"
" - T: toggle TLS gopher mode\n"
" - F: forget/discard current TLS client certificate\n"
" - .: display the raw server response for the current page\n"
(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"
(defun elpher-show-history (pages)
"Show all PAGES in the Elpher buffer."
(elpher-with-clean-buffer
+ (insert "---- Visited link history ----\n\n")
(if pages
(dolist (page pages)
(when page
(let ((display-string (elpher-page-display-string page))
(address (elpher-page-address page)))
(elpher-insert-index-record display-string address))))
- (insert "No history items found.\n"))))
+ (insert "No history items found.\n"))
+ (insert "\n----------------------------")))
+
;;; Bookmarks
;;; 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.
(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
(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)
;;; 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
;;
(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."
(define-key map (kbd "O") 'elpher-root-dir)
(define-key map (kbd "g") 'elpher-go)
(define-key map (kbd "o") 'elpher-go-current)
- (define-key map (kbd "h") 'elpher-history)
- (define-key map (kbd "H") 'elpher-history-all)
+ (define-key map (kbd "s") 'elpher-history)
+ (define-key map (kbd "S") 'elpher-history-all)
(define-key map (kbd "r") 'elpher-redraw)
(define-key map (kbd "R") 'elpher-reload)
(define-key map (kbd "T") 'elpher-toggle-tls)
(define-key map (kbd "a") 'elpher-set-bookmark-no-overwrite)
(define-key map (kbd "A") 'bookmark-set-no-overwrite)
(define-key map (kbd "B") 'bookmark-bmenu-list)
- (define-key map (kbd "S") 'elpher-set-gopher-coding-system)
+ (define-key map (kbd "!") 'elpher-set-gopher-coding-system)
(define-key map (kbd "F") 'elpher-forget-current-certificate)
(when (fboundp 'evil-define-key*)
(evil-define-key*
(kbd "a") 'elpher-set-bookmark-no-overwrite
(kbd "A") 'bookmark-set-no-overwrite
(kbd "B") 'bookmark-bmenu-list
- (kbd "S") 'elpher-set-gopher-coding-system
+ (kbd "!") 'elpher-set-gopher-coding-system
(kbd "F") 'elpher-forget-current-certificate))
map)
"Keymap for gopher client.")
(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))