"Association list from types to getters, renderers, margin codes and index faces.")
+;;; Internal variables
+;;
+
+(defvar elpher--gemini-page-links '()
+ "Internal variable containing list of links on page.")
+
+
;;; Customization group
;;
some servers which do not support IPv6 can take a long time to time-out."
:type '(boolean))
+(defcustom elpher-gemini-number-links nil
+ "If non-nil, number links in gemini pages when rendering.
+Links can be accessed by pressing `v' ('visit') followed by the link number."
+ :type '(boolean))
+
;; Face customizations
(defgroup elpher-faces nil
(address (elpher-address-from-gemini-url url))
(type (if address (elpher-address-type address) nil))
(type-map-entry (cdr (assoc type elpher-type-map))))
+ (setq elpher--gemini-page-links (append elpher--gemini-page-links `(,address)))
(when display-string
(insert elpher-gemini-link-string)
(if type-map-entry
(defun elpher-render-gemini-map (data _parameters)
"Render DATA as a gemini map file, PARAMETERS is currently unused."
(elpher-with-clean-buffer
- (let ((preformatted nil))
+ (let ((preformatted nil)
+ (link-counter 1))
(auto-fill-mode 1)
(setq-local fill-column (min (window-width) elpher-gemini-max-fill-width))
+ (setq elpher--gemini-page-links '())
(dolist (line (split-string data "\n"))
(cond
((string-prefix-p "```" line) (setq preformatted (not preformatted)))
(preformatted (insert (elpher-process-text-for-display
(propertize line 'face 'elpher-gemini-preformatted))
"\n"))
- ((string-prefix-p "=>" line) (elpher-gemini-insert-link line))
+ ((string-prefix-p "=>" line)
+ (progn
+ (if elpher-gemini-number-links
+ (insert
+ (concat
+ "["
+ (number-to-string link-counter)
+ "] ")))
+ (setq link-counter (1+ link-counter))
+ (elpher-gemini-insert-link line)))
((string-prefix-p "#" line) (elpher-gemini-insert-header line))
(t (elpher-gemini-insert-text line)))))
(elpher-cache-content
" - u/mouse-3/U: return to previous page or to the start page\n"
" - o/O: visit different selector or the root menu of the current server\n"
" - g: go to a particular address (gopher, gemini, finger)\n"
+ " - v: visit a numbered link on a gemini page\n"
" - d/D: download item under cursor or current page\n"
" - i/I: info on item under cursor or current page\n"
" - c/C: copy URL representation of item under cursor or current page\n"
(let ((url (read-string "Gopher or Gemini URL: " (elpher-address-to-url address))))
(elpher-visit-page (elpher-make-page url (elpher-address-from-url url)))))))
+(defun elpher-visit-gemini-numbered-link (n)
+ "Visit link designated by a number."
+ (interactive "nLink number: ")
+ (if (or (> n (length elpher--gemini-page-links))
+ (< n 1))
+ (user-error "Invalid link number"))
+ (let ((address (nth (1- n) elpher--gemini-page-links)))
+ (elpher-go (url-recreate-url address))))
+
(defun elpher-redraw ()
"Redraw current page."
(interactive)
(define-key map (kbd "B") 'elpher-bookmarks)
(define-key map (kbd "S") 'elpher-set-gopher-coding-system)
(define-key map (kbd "F") 'elpher-forget-current-certificate)
+ (define-key map (kbd "v") 'elpher-visit-gemini-numbered-link)
(when (fboundp 'evil-define-key*)
(evil-define-key* 'motion map
(kbd "TAB") 'elpher-next-link
(kbd "X") 'elpher-unbookmark-current
(kbd "B") 'elpher-bookmarks
(kbd "S") 'elpher-set-gopher-coding-system
- (kbd "F") 'elpher-forget-current-certificate))
+ (kbd "F") 'elpher-forget-current-certificate
+ (kbd "v") 'elpher-visit-gemini-numbered-link))
map)
"Keymap for gopher client.")