[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/luwak 3af6104fe5 13/28: make link render a user option
From: |
ELPA Syncer |
Subject: |
[elpa] externals/luwak 3af6104fe5 13/28: make link render a user option and add dump to a file |
Date: |
Tue, 25 Oct 2022 15:57:54 -0400 (EDT) |
branch: externals/luwak
commit 3af6104fe533463a1886a9fcf318cb0727b9b58e
Author: Yuchen Pei <hi@ypei.me>
Commit: Yuchen Pei <hi@ypei.me>
make link render a user option and add dump to a file
---
luwak.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 48 insertions(+), 10 deletions(-)
diff --git a/luwak.el b/luwak.el
index 23a5d369df..e82f8cf6a6 100644
--- a/luwak.el
+++ b/luwak.el
@@ -34,9 +34,13 @@
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
+(defcustom luwak-max-history-length 100
"Maximum history length."
:group 'luwak :type '(natnum))
+(defcustom luwak-render-link-function 'luwak-render-link-id
+ "Function to render a link."
+ :group 'luwak :type '(choice (const luwak-render-link-id)
+ (const luwak-render-link-forward-sexp)))
(put luwak-history 'history-length luwak-max-history-length)
@@ -61,6 +65,7 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(define-key kmap "w" 'luwak-copy-url)
(define-key kmap "o" 'luwak-open)
(define-key kmap "s" 'luwak-search)
+ (define-key kmap "d" 'luwak-save-dump)
kmap))
(define-derived-mode luwak-mode special-mode (luwak-mode-name)
@@ -143,9 +148,12 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(luwak-history-open history-pos)))
(defun luwak-history-open (history-pos)
- (let ((pair (nth history-pos luwak-history)))
+ (let ((pair (nth history-pos luwak-history))
+ (len (length luwak-history)))
(luwak-open-internal (car pair) (cdr pair) history-pos
- (plist-get luwak-data :no-tor))))
+ (plist-get luwak-data :no-tor))
+ (message "Loaded history %d/%d: %s"
+ (- len history-pos) len (car pair))))
(defun luwak-reload ()
(interactive)
@@ -164,15 +172,28 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(goto-char (point-min))
(let ((i 1))
(dolist (url urls)
- (when (re-search-forward (format "\\[%d\\]" i) nil t)
- (replace-match "")
- (make-text-button (point) (progn (forward-sexp) (point))
- 'url url
- 'help-echo url
- 'action 'luwak-follow-link
- 'face 'button))
+ (luwak-render-link-id i url)
(setq i (1+ i)))))))
+(defun luwak-render-link-forward-sexp (idx url)
+ "Render a link using forward-sexp."
+ (when (re-search-forward (format "\\[%d\\]" idx) nil t)
+ (replace-match "")
+ (make-text-button (point) (progn (forward-sexp) (point))
+ 'url url
+ 'help-echo url
+ 'action 'luwak-follow-link
+ 'face 'button)))
+
+(defun luwak-render-link-id (idx url)
+ "Render a link by its id."
+ (when (re-search-forward (format "\\[%d\\]" idx) nil t)
+ (make-text-button (match-beginning 0) (match-end 0)
+ 'url url
+ 'help-echo url
+ 'action 'luwak-follow-link
+ 'face 'button)))
+
(defun luwak-get-links ()
"Get links and remove the reference section if any."
(with-current-buffer luwak-buffer
@@ -192,4 +213,21 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(apply 'start-process
(append (list name buffer "torsocks" program) program-args))))
+(defun luwak-save-dump (file-name)
+ (interactive
+ (list
+ (read-file-name (format "Write dump of %s to: " (plist-get luwak-data
:url))
+ default-directory)))
+ (let ((dump (plist-get luwak-data :dump)))
+ (with-temp-buffer
+ (insert dump)
+ (write-file file-name)))
+ (message "Wrote %s." file-name))
+
+(defun luwak-make-filename (name &optional sep)
+ "Convert name to filename by replacing special chars with sep."
+ (unless sep (setq sep "-"))
+ (replace-regexp-in-string "[[:punct:][:space:]\n\r]+" sep
+ (string-trim name)))
+
(provide 'luwak)
- [elpa] branch externals/luwak created (now ec97058718), ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 1899e7903a 19/28: typo, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 7652f876d0 08/28: display tor status, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 8e7da0d089 10/28: making using tor a user option, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 5e72329d3a 03/28: some more convenient keys, as well as removal of ref section, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 3c337adc87 07/28: removing deps on eww, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak ea6a1c4c2d 18/28: removing an unused fun, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 3af6104fe5 13/28: make link render a user option and add dump to a file,
ELPA Syncer <=
- [elpa] externals/luwak e0408b2cb6 15/28: org store and capture, ELPA Syncer, 2022/10/25
- [elpa] externals/luwak 05f5fef4bf 17/28: history and follow numbered link, ELPA Syncer, 2022/10/25
- [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