[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/luwak 179461ba0e 14/28: adding link rendering toggle
From: |
ELPA Syncer |
Subject: |
[elpa] externals/luwak 179461ba0e 14/28: adding link rendering toggle |
Date: |
Tue, 25 Oct 2022 15:57:54 -0400 (EDT) |
branch: externals/luwak
commit 179461ba0ec028a408a836c2f277e3f3a998c33a
Author: Yuchen Pei <hi@ypei.me>
Commit: Yuchen Pei <hi@ypei.me>
adding link rendering toggle
---
luwak.el | 50 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 43 insertions(+), 7 deletions(-)
diff --git a/luwak.el b/luwak.el
index e82f8cf6a6..c8e5470df7 100644
--- a/luwak.el
+++ b/luwak.el
@@ -40,7 +40,8 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(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)))
+ (const luwak-render-link-forward-sexp)
+ (const luwak-render-link-hide-link)))
(put luwak-history 'history-length luwak-max-history-length)
@@ -66,10 +67,27 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(define-key kmap "o" 'luwak-open)
(define-key kmap "s" 'luwak-search)
(define-key kmap "d" 'luwak-save-dump)
+ (define-key kmap "j" 'imenu)
+ (define-key kmap "t" 'luwak-toggle-links)
kmap))
(define-derived-mode luwak-mode special-mode (luwak-mode-name)
- "Major mode for browsing the web using lynx -dump.")
+ "Major mode for browsing the web using lynx -dump."
+ (setq-local imenu-create-index-function #'luwak-imenu-create-index
+ imenu-space-replacement " "
+ imenu-max-item-length nil
+ imenu-auto-rescan t))
+
+(defun luwak-imenu-create-index ()
+ (goto-char (point-min))
+ (let ((index) (position))
+ (while (re-search-forward "^[^[:space:]]" nil t)
+ (push (cons (buffer-substring-no-properties
+ (setq position (1- (point)))
+ (progn (end-of-line 1) (point)))
+ position)
+ index))
+ (reverse index)))
(defun luwak-open (url)
"Open URL in luwak."
@@ -115,13 +133,27 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(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)))
+ (luwak-insert-and-render)
(setq mode-name (luwak-mode-name))
(goto-char (point-min))))
+(defun luwak-toggle-links ()
+ (interactive)
+ (pcase luwak-render-link-function
+ ('luwak-render-link-id
+ (setq luwak-render-link-function 'luwak-render-link-hide-link))
+ ('luwak-render-link-hide-link
+ (setq luwak-render-link-function 'luwak-render-link-forward-sexp))
+ (_
+ (setq luwak-render-link-function 'luwak-render-link-id)))
+ (save-excursion (luwak-insert-and-render)))
+
+(defun luwak-insert-and-render ()
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert (plist-get luwak-data :dump))
+ (luwak-render-links (luwak-get-links))))
+
(defun luwak-add-to-history ()
(let ((history-delete-duplicates nil))
(setq luwak-history (nthcdr (plist-get luwak-data :history-pos)
@@ -172,7 +204,7 @@ When non-nill, swap the tor-switch in prefix-arg effect."
(goto-char (point-min))
(let ((i 1))
(dolist (url urls)
- (luwak-render-link-id i url)
+ (funcall luwak-render-link-function i url)
(setq i (1+ i)))))))
(defun luwak-render-link-forward-sexp (idx url)
@@ -194,6 +226,10 @@ When non-nill, swap the tor-switch in prefix-arg effect."
'action 'luwak-follow-link
'face 'button)))
+(defun luwak-render-link-hide-link (idx _)
+ (when (re-search-forward (format "\\[%d\\]" idx) nil t)
+ (replace-match "")))
+
(defun luwak-get-links ()
"Get links and remove the reference section if any."
(with-current-buffer luwak-buffer
- [elpa] externals/luwak 3c337adc87 07/28: removing deps on eww, (continued)
- [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, 2022/10/25
- [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 <=
- [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, 2022/10/25
- [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