[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/luwak f08e3189eb 12/28: Caching dump for history nav
From: |
ELPA Syncer |
Subject: |
[elpa] externals/luwak f08e3189eb 12/28: Caching dump for history nav |
Date: |
Tue, 25 Oct 2022 15:57:54 -0400 (EDT) |
branch: externals/luwak
commit f08e3189eb109a26f4dc0c61eba26ad25eec925d
Author: Yuchen Pei <hi@ypei.me>
Commit: Yuchen Pei <hi@ypei.me>
Caching dump for history nav
- also refactoring code a bit
---
luwak.el | 66 +++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 40 insertions(+), 26 deletions(-)
diff --git a/luwak.el b/luwak.el
index 2c27c9775a..23a5d369df 100644
--- a/luwak.el
+++ b/luwak.el
@@ -18,7 +18,7 @@
(defvar luwak-buffer "*luwak*")
-(defvar-local luwak-data nil)
+(defvar-local luwak-data (:url nil :dump nil :history-pos nil :no-tor nil))
(defvar-local luwak-history nil)
(defun luwak-lynx-buffer (url) (format "*luwak-lynx %s*" url))
@@ -34,6 +34,11 @@
When nil, use tor by default, and not use it with a prefix arg.
When non-nill, swap the tor-switch in prefix-arg effect."
:group 'luwak :type '(boolean))
+(defcustom luwak-max-history-length 25
+ "Maximum history length."
+ :group 'luwak :type '(natnum))
+
+(put luwak-history 'history-length luwak-max-history-length)
(defun luwak-toggle-tor-switch ()
(interactive)
@@ -64,7 +69,7 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(defun luwak-open (url)
"Open URL in luwak."
(interactive "sUrl to open: ")
- (luwak-open-internal
+ (luwak-open-url
url (xor luwak-tor-switch current-prefix-arg) 'luwak-add-to-history))
(defun luwak-copy-url ()
@@ -79,7 +84,7 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(interactive "sLuwak search query: ")
(luwak-open (format luwak-search-engine query)))
-(defun luwak-open-internal (url no-tor &optional cb)
+(defun luwak-open-url (url no-tor &optional cb)
(setq url (funcall luwak-url-rewrite-function url))
(message "Loading %s..." url)
(set-process-sentinel
@@ -90,27 +95,35 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(lambda (process _)
(message "Loading %s... Done." url)
(with-current-buffer (get-buffer-create luwak-buffer)
- (let ((inhibit-read-only t))
- (erase-buffer)
- (insert-buffer-substring (process-buffer process))
- (kill-buffer (process-buffer process))
- (goto-char (point-min))
- (luwak-render-links (luwak-get-links)))
- (unless (derived-mode-p 'luwak-mode) (luwak-mode))
- (if luwak-data
- (progn
- (plist-put luwak-data :url url)
- (plist-put luwak-data :no-tor no-tor))
- (setq luwak-data (list :url url :no-tor no-tor :history-pos 0)))
- (setq mode-name (luwak-mode-name))
- (when cb (funcall cb)))
+ (luwak-open-internal
+ url
+ (with-current-buffer (process-buffer process) (buffer-string))
+ (or (plist-get luwak-data :history-pos) 0)
+ no-tor)
+ (kill-buffer (process-buffer process))
+ (when cb (funcall cb))
+ (goto-char (point-min)))
(display-buffer luwak-buffer))))
+(defun luwak-open-internal (url dump history-pos no-tor)
+ (with-current-buffer (get-buffer-create luwak-buffer)
+ (unless (derived-mode-p 'luwak-mode) (luwak-mode))
+ (setq luwak-data (list :url url :no-tor no-tor
+ :history-pos history-pos :dump dump))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert dump)
+ (luwak-render-links (luwak-get-links)))
+ (setq mode-name (luwak-mode-name))
+ (goto-char (point-min))))
+
(defun luwak-add-to-history ()
(let ((history-delete-duplicates nil))
(setq luwak-history (nthcdr (plist-get luwak-data :history-pos)
luwak-history))
- (add-to-history 'luwak-history (plist-get luwak-data :url))
+ (add-to-history 'luwak-history
+ (cons (plist-get luwak-data :url)
+ (plist-get luwak-data :dump)))
(plist-put luwak-data :history-pos 0)))
(defun luwak-history-backward ()
@@ -119,9 +132,7 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(1+ (plist-get luwak-data :history-pos))))
(when (<= (length luwak-history) history-pos)
(error "Already at the earliest history."))
- (plist-put luwak-data :history-pos history-pos)
- (luwak-open-internal (nth history-pos luwak-history)
- (plist-get luwak-data :no-tor))))
+ (luwak-history-open history-pos)))
(defun luwak-history-forward ()
(interactive)
@@ -129,19 +140,22 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(1- (plist-get luwak-data :history-pos))))
(when (< history-pos 0)
(error "Already at the latest history."))
- (plist-put luwak-data :history-pos history-pos)
- (luwak-open-internal (nth history-pos luwak-history)
- (plist-get luwak-data :no-tor))))
+ (luwak-history-open history-pos)))
+
+(defun luwak-history-open (history-pos)
+ (let ((pair (nth history-pos luwak-history)))
+ (luwak-open-internal (car pair) (cdr pair) history-pos
+ (plist-get luwak-data :no-tor))))
(defun luwak-reload ()
(interactive)
- (luwak-open-internal
+ (luwak-open-url
(plist-get luwak-data :url)
(plist-get luwak-data :no-tor)))
(defun luwak-follow-link (marker)
(let ((url (get-text-property marker 'url)))
- (luwak-open-internal
+ (luwak-open-url
url (plist-get luwak-data :no-tor) 'luwak-add-to-history)))
(defun luwak-render-links (urls)
- [elpa] externals/luwak 0c1b6e97ab 11/28: docstring minor, (continued)
- [elpa] externals/luwak 0c1b6e97ab 11/28: docstring minor, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 8373015f75 21/28: Prepare for ELPA submission, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 2d11ff50d6 25/28: toggle default tor switch., ELPA Syncer, 2022/10/25
- [elpa] externals/luwak aa846e8484 20/28: fixing some compiling error, as well as bugs, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak b86519f50b 06/28: updating docs about torsocks, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 179461ba0e 14/28: adding link rendering toggle, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 12692b1207 05/28: adding gitignore, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 9341d7ac6b 01/28: initial commit, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 39ac2162c5 02/28: adding luwak-mode, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 4b0acd3441 09/28: moving luwak-mode-map definition to be above the mode definition, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak f08e3189eb 12/28: Caching dump for history nav,
ELPA Syncer <=
- [elpa] externals/luwak f12c63b8a5 16/28: render a dump buffer, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 08855c83c4 24/28: minor wording, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 96fec3bce0 23/28: minor rewording, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 91764c44b9 22/28: updated readme, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 9c95bcb74f 27/28: adding an example url rewrite function, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak ec97058718 28/28: minor docstring, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 544187e3e7 26/28: fixed a bug when no title could be guessed., ELPA Syncer, 2022/10/25
- [elpa] externals/luwak fa9a801f81 04/28: licensing and readme, ELPA Syncer, 2022/10/25