all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Sebastián Monía" <sebastian@sebasmonia.com>
To: Jim Porter <jporterbugs@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>,  emacs-devel@gnu.org
Subject: Re: [PATCH] EWW - use revert--buffer-function to reload, and allow reload in eww-list-buffer
Date: Fri, 20 Sep 2024 22:14:49 -0400	[thread overview]
Message-ID: <thqnldzl21nq.fsf@sebasmonia.com> (raw)
In-Reply-To: <30fbc38f-2b86-55c2-a4f3-6c924d82aed8@gmail.com> (Jim Porter's message of "Fri, 20 Sep 2024 10:43:03 -0700")

[-- Attachment #1: Type: text/plain, Size: 1043 bytes --]

Jim Porter <jporterbugs@gmail.com> writes:

> On 9/20/2024 8:06 AM, Sebastián Monía wrote:
>> If not, I will convert it to tabulated-list (or vtable), only
>> disadvantage I see, is that it would change the internals of the buffer
>> list quite a bit. I don't expect anyone to rely on them, though.
>
> I think a tabulated list would be fine.

I included below a patch that does this

> Your other earlier suggestion of splitting 'eww-list-buffers' in three
> also makes sense to me though. Then one of the functions could be
> 'eww-buffer-list' (which returns a list of EWW buffers), just like how
> we have 'buffer-list' and 'list-buffers' in Emacs.

I read this just now :(
I can add it in a subsequent patch.

BTW, 'eww-bookmark-mode' could also use a tabulated list.
I use the eww specific bookmarks or some pages (and "general" bookmarks
for others, everyone has their workflows I guess).

If you all think it is worth it, I can make a similar change to this one
for bookmarks. And add 'eww-list-buffers' too.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Derive-eww-buffers-mode-from-tabulated-list-adjust-c.patch --]
[-- Type: text/x-patch, Size: 5558 bytes --]

From 5fc0308ea6569ab5bc06db45ac1e7f7590c90c42 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebasti=C3=A1n=20Mon=C3=ADa?= <sebastian@sebasmonia.com>
Date: Fri, 20 Sep 2024 21:52:05 -0400
Subject: [PATCH] Derive eww-buffers-mode from tabulated-list, adjust command
 eww-list-buffers to use it

---
 lisp/net/eww.el | 95 +++++++++++++++++--------------------------------
 1 file changed, 32 insertions(+), 63 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index b5d2f20781a..a651d9d5020 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -2605,57 +2605,31 @@ see)."
 ;;; eww buffers 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*"))
-    (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)))))
+  (with-current-buffer (get-buffer-create "*eww buffers*")
+    (eww-buffers-mode))
   (pop-to-buffer "*eww buffers*"))
 
+(defun eww--list-buffers-get-eww-data (buf)
+  "Return the eww-data of BUF, if its major mode is eww.
+The format (buffer [title url]) is for use in of `eww-buffers-mode'.
+If BUF has another mode, return nil."
+  (with-current-buffer buf
+    (when (derived-mode-p 'eww-mode)
+      (list buf
+            (vector
+             (plist-get eww-data :title)
+             (plist-get eww-data :url))))))
+
+(defun eww--list-buffers-collect ()
+  "Update the eww buffers list displayed in this buffer."
+  (delq nil (mapcar #'eww--list-buffers-get-eww-data (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 (tabulated-list-get-id)))
     (unless buffer
       (error "No buffer on current line"))
     (quit-window)
@@ -2663,8 +2637,7 @@ see)."
 
 (defun eww-buffer-show ()
   "Display buffer under point in eww buffer list."
-  (let ((buffer (get-text-property (line-beginning-position)
-                                   'eww-buffer)))
+  (let ((buffer (tabulated-list-get-id)))
     (unless buffer
       (error "No buffer on current line"))
     (other-window -1)
@@ -2691,17 +2664,11 @@ see)."
 (defun 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))
-	 (inhibit-read-only t))
+  (let ((buffer (tabulated-list-get-id)))
     (unless buffer
       (user-error "No buffer on the current line"))
     (kill-buffer buffer)
-    (forward-line 1)
-    (delete-region start (point)))
-  (when (eobp)
-    (forward-line -1))
-  (eww-buffer-show))
+    (revert-buffer)))
 
 (defvar-keymap eww-buffers-mode-map
   "C-k" #'eww-buffer-kill
@@ -2709,20 +2676,22 @@ see)."
   "n" #'eww-buffer-show-next
   "p" #'eww-buffer-show-previous
   :menu '("Eww Buffers"
-          ["Exit" quit-window t]
           ["Select" eww-buffer-select
-           :active (get-text-property (line-beginning-position) 'eww-buffer)]
+           :active (tabulated-list-get-id)]
           ["Kill" eww-buffer-kill
-           :active (get-text-property (line-beginning-position)
-                                      'eww-buffer)]))
+           :active (tabulated-list-get-id)]
+          ["Exit" quit-window]))
 
-(define-derived-mode eww-buffers-mode special-mode "eww buffers"
+(define-derived-mode eww-buffers-mode tabulated-list-mode "eww buffers"
   "Mode for listing buffers.
-
 \\{eww-buffers-mode-map}"
   :interactive nil
-  (buffer-disable-undo)
-  (setq truncate-lines t))
+  (setq tabulated-list-format [("Title" 30 t)
+                               ("URL" 0 t)])
+  (setq tabulated-list-padding 1
+        tabulated-list-entries #'eww--list-buffers-collect)
+  (tabulated-list-init-header)
+  (tabulated-list-print))
 
 ;;; Desktop support
 
-- 
2.45.2.windows.1


[-- Attachment #3: Type: text/plain, Size: 54 bytes --]


-- 
Sebastián Monía
https://site.sebasmonia.com/

  reply	other threads:[~2024-09-21  2:14 UTC|newest]

Thread overview: 34+ 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 [this message]
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
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
     [not found]                                                 ` <thqnh69apzgp.fsf@sebasmonia.com>
2024-10-19 20:51                                                   ` Sebastián Monía
2024-10-20 17:50                                                     ` Jim Porter
2024-10-21  1:57                                                       ` Sebastián Monía
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=thqnldzl21nq.fsf@sebasmonia.com \
    --to=sebastian@sebasmonia.com \
    --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.