From: Tim Vaughan Date: Thu, 18 Apr 2019 09:36:55 +0000 (+0200) Subject: Implementing reload. X-Git-Tag: v1.0.0~73 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=3ef1058c60fe54acde6e4f2f7080b730b0d355a7;p=elpher.git Implementing reload. --- diff --git a/elopher.el b/elopher.el index 30383ae..3aef080 100644 --- a/elopher.el +++ b/elopher.el @@ -13,7 +13,6 @@ "A simple gopher client." :group 'applications) - (defcustom elopher-index-face '(foreground-color . "cyan") "Face used for index records.") (defcustom elopher-text-face '(foreground-color . "white") @@ -60,20 +59,22 @@ ;;; Mode and keymap ;; -(defvar elopher-mode-map +(setq elopher-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "") 'elopher-next-link) (define-key map (kbd "") 'elopher-prev-link) - (define-key map (kbd "u") 'elopher-history-back) + (define-key map (kbd "u") 'elopher-pop-history) (define-key map (kbd "g") 'elopher-go) + (define-key map (kbd "r") 'elopher-reload) (when (require 'evil nil t) (evil-define-key 'normal map (kbd "C-]") 'elopher-follow-closest-link - (kbd "C-t") 'elopher-history-back - (kbd "u") 'elopher-history-back - (kbd "g") 'elopher-go)) - map) - "Keymap for gopher client.") + (kbd "C-t") 'elopher-pop-history + (kbd "u") 'elopher-pop-history + (kbd "g") 'elopher-go + (kbd "r") 'elopher-reload)) + map)) + ;; "Keymap for gopher client.") (define-derived-mode elopher-mode special-mode "elopher" "Major mode for elopher, an elisp gopher client.") @@ -148,13 +149,22 @@ (defvar elopher-history nil "List of pages in elopher history.") +(defvar elopher-place-history nil + "List of objects describing how to access pages in history.") + +(defvar elopher-current-place nil + "How to access current page.") + (defun elopher-push-history () "Add current contents of buffer, including point, to history." (unless (string-empty-p (buffer-string)) (push (list (buffer-string) (point)) - elopher-history))) + elopher-history) + (push + elopher-current-place + elopher-place-history))) (defun elopher-pop-history () "Restore most recent page from history." @@ -168,7 +178,8 @@ (switch-to-buffer "*elopher*") (erase-buffer) (insert page-string) - (goto-char page-point)) + (goto-char page-point) + (setq elopher-current-place (pop elopher-place-history))) (message "Already at start of history.")) (message "No elopher buffer found."))) @@ -176,7 +187,6 @@ ;;; Selector retrieval (all kinds) ;; - (defun elopher-get-selector (selector host port filter &optional sentinel) (switch-to-buffer "*elopher*") (elopher-mode) @@ -242,6 +252,14 @@ #'elopher-image-filter #'elopher-image-sentinel)) +;; Start page retrieval + +(defun elopher-get-start-page (&optional selector host port) + "Display start page. SELECTOR, HOST and PORT are unused." + (let ((inhibit-read-only t)) + (erase-buffer) + (save-excursion + (elopher-render-complete-records elopher-start-page)))) ;;; Navigation methods ;; @@ -255,7 +273,8 @@ (backward-button 1)) (defun elopher-click-link (button) - (apply (button-get button 'link-getter) (button-get button 'link-address))) + (apply (button-get button 'link-getter) (button-get button 'link-address)) + (setq elopher-current-place (list link-getter link-address))) (defun elopher-follow-closest-link () (interactive) @@ -264,8 +283,21 @@ (defun elopher-go () "Go to a particular gopher site." (interactive) - (elopher-get-index "" (read-from-minibuffer "Gopher host: ") 70)) + (let* ((selector "") + (hostname (read-from-minibuffer "Gopher host: ")) + (port 70) + (address (list selector hostname port))) + (elopher-get-index "" (read-from-minibuffer "Gopher host: ") 70)i + (setq elopher-current-place (list #'elopher-get-index address)))) +(defun elopher-reload () + "Reload current page." + (interactive) + (if elopher-current-place + (let ((link-getter (car elopher-current-place)) + (address (cadr elopher-current-place))) + (apply link-getter address)) + (elopher-get-start-page))) ;;; Main start procedure ;; @@ -276,10 +308,9 @@ (switch-to-buffer "*elopher*") (elopher-mode) (setq elopher-history nil) - (let ((inhibit-read-only t)) - (erase-buffer) - (save-excursion - (elopher-render-complete-records elopher-start-page)))) + (setq elopher-place-history nil) + (setq elopher-current-place nil) + (elopher-get-start-page)) ;;; elopher.el ends here