From: "Sebastián Monía" <sebastian@sebasmonia.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: adam@alphapapa.net, jporterbugs@gmail.com, emacs-devel@gnu.org
Subject: Re: [PATCH] EWW - use revert--buffer-function to reload, and allow reload in eww-list-buffer
Date: Sun, 13 Oct 2024 21:06:46 -0400 [thread overview]
Message-ID: <87v7xvh4rd.fsf@sebasmonia.com> (raw)
In-Reply-To: <86y12tycdy.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 12 Oct 2024 11:05:29 +0300")
[-- Attachment #1: Type: text/plain, Size: 848 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> I didn't yet have time to read your discussion and make up my mind. I
> was waiting for you to reach some agreement, but it seems you are
> still discussing the various aspects?
I was wondering if there was an official project stance on using vtable
or tabulated-list. Like there's a preference for seq vs cl-lib (where
both apply) for example.
> Are there any downsides to using vtable?
None that I know of, and as Adam suggested, vtables are sometimes easier
to handle.
It doesn't make much of a difference in this case, though, the table is
pretty simple.
Attached a new patch that used vtable, and also adds the
(eww-buffer-list) function that Jim mentioned before.
Once this one is merged (after review & corrections :) etc.) I can take
the same vtable approach for eww-bookmarks.
Thank you,
Seb
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: eww-list-buffers and eww-buffer-list --]
[-- Type: text/x-patch, Size: 5916 bytes --]
From bb090996db7eb7d819b7d28e3dd1a97d6bccc959 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebasti=C3=A1n=20Mon=C3=ADa?= <code@sebasmonia.com>
Date: Sun, 13 Oct 2024 21:00:03 -0400
Subject: [PATCH] Use vtable in eww-list-buffers, add function eww-buffer-list
---
lisp/net/eww.el | 96 +++++++++++++++++++++++--------------------------
1 file changed, 45 insertions(+), 51 deletions(-)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index b5d2f20781a..b0467500ef3 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -33,6 +33,7 @@
(require 'url)
(require 'url-queue)
(require 'url-file)
+(require 'vtable)
(require 'xdg)
(eval-when-compile (require 'subr-x))
@@ -2604,58 +2605,50 @@ eww-history-mode
;;; eww buffers list
+(defun eww-buffer-list ()
+ "Return a list of all live eww buffers."
+ (seq-filter (lambda (buf)
+ (with-current-buffer buf
+ (derived-mode-p 'eww-mode)))
+ (buffer-list)))
+
(defun eww-list-buffers ()
- "Enlist eww buffers."
+ "Pop a buffer with a list of eww buffers."
(interactive)
- (let (buffers-info
- (current (current-buffer)))
- (dolist (buffer (buffer-list))
- (with-current-buffer buffer
- (when (derived-mode-p 'eww-mode)
- (push (vector buffer (plist-get eww-data :title)
- (plist-get eww-data :url))
- buffers-info))))
- (unless buffers-info
- (error "No eww buffers"))
- (setq buffers-info (nreverse buffers-info)) ;more recent on top
- (set-buffer (get-buffer-create "*eww buffers*"))
+ (with-current-buffer (get-buffer-create "*eww buffers*")
(eww-buffers-mode)
- (let ((inhibit-read-only t)
- (domain-length 0)
- (title-length 0)
- url title format start)
- (erase-buffer)
- (dolist (buffer-info buffers-info)
- (setq title-length (max title-length
- (length (elt buffer-info 1)))
- domain-length (max domain-length
- (length (elt buffer-info 2)))))
- (setq format (format "%%-%ds %%-%ds" title-length domain-length)
- header-line-format
- (concat " " (format format "Title" "URL")))
- (let ((line 0)
- (current-buffer-line 1))
- (dolist (buffer-info buffers-info)
- (setq start (point)
- title (elt buffer-info 1)
- url (elt buffer-info 2)
- line (1+ line))
- (insert (format format title url))
- (insert "\n")
- (let ((buffer (elt buffer-info 0)))
- (put-text-property start (1+ start) 'eww-buffer
- buffer)
- (when (eq current buffer)
- (setq current-buffer-line line))))
- (goto-char (point-min))
- (forward-line (1- current-buffer-line)))))
+ (eww--list-buffers-display-table))
(pop-to-buffer "*eww buffers*"))
+(defun eww--list-buffers-display-table (&optional ignore-auto noconfirm)
+ "Display a table with the list of eww buffers.
+Will remove all buffer contents first. The parameters IGNORE-AUTO and
+NOCONFIRM are ignored, they are for compatibility with
+`revert-buffer-function'."
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (make-vtable
+ :columns '((:name "Title" :width 30)
+ (:name "URL"))
+ :objects-function #'eww--list-buffers-get-data
+ ;; use fixed-font face
+ :face 'default)))
+
+(defun eww--list-buffers-get-data ()
+ "Return the eww-data of BUF, assumed to be a eww buffer.
+The format of the data is (title url buffer), for use in of
+`eww-buffers-mode'."
+ (mapcar (lambda (buf)
+ (with-current-buffer buf
+ (list (plist-get eww-data :title)
+ (plist-get eww-data :url)
+ buf)))
+ (eww-buffer-list)))
+
(defun eww-buffer-select ()
"Switch to eww buffer."
(interactive nil eww-buffers-mode)
- (let ((buffer (get-text-property (line-beginning-position)
- 'eww-buffer)))
+ (let ((buffer (nth 2 (vtable-current-object))))
(unless buffer
(error "No buffer on current line"))
(quit-window)
@@ -2663,8 +2656,7 @@ eww-buffer-select
(defun eww-buffer-show ()
"Display buffer under point in eww buffer list."
- (let ((buffer (get-text-property (line-beginning-position)
- 'eww-buffer)))
+ (let ((buffer (nth 2 (vtable-current-object))))
(unless buffer
(error "No buffer on current line"))
(other-window -1)
@@ -2692,7 +2684,7 @@ eww-buffer-kill
"Kill buffer from eww list."
(interactive nil eww-buffers-mode)
(let* ((start (line-beginning-position))
- (buffer (get-text-property start 'eww-buffer))
+ (buffer (nth 2 (vtable-current-object)))
(inhibit-read-only t))
(unless buffer
(user-error "No buffer on the current line"))
@@ -2711,10 +2703,9 @@ eww-buffers-mode-map
:menu '("Eww Buffers"
["Exit" quit-window t]
["Select" eww-buffer-select
- :active (get-text-property (line-beginning-position) 'eww-buffer)]
+ :active (nth 2 (vtable-current-object))]
["Kill" eww-buffer-kill
- :active (get-text-property (line-beginning-position)
- 'eww-buffer)]))
+ :active (nth 2 (vtable-current-object))]))
(define-derived-mode eww-buffers-mode special-mode "eww buffers"
"Mode for listing buffers.
@@ -2722,7 +2713,10 @@ eww-buffers-mode
\\{eww-buffers-mode-map}"
:interactive nil
(buffer-disable-undo)
- (setq truncate-lines t))
+ (setq truncate-lines t
+ ;; this is set so that pressing "g" with point just below the
+ ;; table will still update the listing
+ revert-buffer-function #'eww--list-buffers-display-table))
;;; Desktop support
--
2.43.0
next prev parent reply other threads:[~2024-10-14 1:06 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 17:28 [PATCH] EWW - use revert--buffer-function to reload, and allow reload in eww-list-buffer Sebastián Monía
2024-08-16 17:48 ` Eli Zaretskii
2024-08-16 18:55 ` Sebastián Monía
2024-08-17 12:35 ` Sebastián Monía
2024-08-24 8:42 ` Eli Zaretskii
2024-08-24 17:27 ` Jim Porter
2024-08-30 20:01 ` Sebastián Monía
2024-09-14 7:32 ` Eli Zaretskii
[not found] ` <thqnjzf7s74l.fsf@sebasmonia.com>
2024-09-20 6:18 ` Eli Zaretskii
2024-09-20 15:06 ` Sebastián Monía
2024-09-20 17:43 ` Jim Porter
2024-09-21 2:14 ` Sebastián Monía
2024-10-02 12:53 ` Sebastián Monía
2024-10-03 0:20 ` Adam Porter
2024-10-03 3:17 ` Sebastián Monía
2024-10-03 4:05 ` Jim Porter
2024-10-03 12:47 ` Sebastián Monía
2024-10-03 23:41 ` Adam Porter
2024-10-11 22:14 ` Sebastián Monía
2024-10-12 8:05 ` Eli Zaretskii
2024-10-12 18:56 ` Jim Porter
2024-10-14 1:06 ` Sebastián Monía [this message]
2024-10-14 2:39 ` Adam Porter
2024-10-14 4:06 ` Sebastián Monía
2024-10-15 0:08 ` Adam Porter
2024-10-15 2:39 ` Sebastián Monía
2024-10-15 4:04 ` Adam Porter
2024-10-14 4:05 ` Jim Porter
2024-10-15 2:59 ` Sebastián Monía
2024-10-15 4:01 ` Adam Porter
2024-10-03 21:58 ` Jim Porter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v7xvh4rd.fsf@sebasmonia.com \
--to=sebastian@sebasmonia.com \
--cc=adam@alphapapa.net \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=jporterbugs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.