all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrey Kotlarski <m00naticus@gmail.com>
To: 19131@debbugs.gnu.org
Subject: bug#19131: 25.0.50; [PATCH] eww.el: Create simple mode to manage eww buffers
Date: Fri, 21 Nov 2014 01:05:46 +0200	[thread overview]
Message-ID: <87vbm9iib9.fsf@gmail.com> (raw)

Once opening new buffers becomes easier, there should be way to manage
the ensuing chaos.  Following patch adds simple interface that allows
showing, switching to and killing eww buffers.

(worry not about size, me papers has signed)

---
 lisp/ChangeLog  |   7 +++
 lisp/net/eww.el | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 473a1f8..2b28946 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2014-11-20  Andrey Kotlarski  <m00naticus@gmail.com>
+
+	* net/eww.el (eww-buffers-mode): New major mode.
+	(eww-list-buffers, eww-buffer-select, eww-buffer-show-next)
+	(eww-buffer-show-previous, eww-buffer-kill, eww-buffer-show): New
+	commands/functions.
+
 2014-11-20  Eric S. Raymond  <esr@snark>
 
 	* vc/vc-bzr.el, vc/vc-cvs.el, vc/vc-dav.el, vc/vc-git.el,
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 6746668..5f8ebae 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -567,6 +567,7 @@ the like."
     (define-key map "v" 'eww-view-source)
     (define-key map "R" 'eww-readable)
     (define-key map "H" 'eww-list-histories)
+    (define-key map "S" 'eww-list-buffers)
 
     (define-key map "b" 'eww-add-bookmark)
     (define-key map "B" 'eww-list-bookmarks)
@@ -587,6 +588,7 @@ the like."
 	["View page source" eww-view-source]
 	["Copy page URL" eww-copy-page-url t]
 	["List histories" eww-list-histories t]
+	["List buffers" eww-list-buffers t]
 	["Add bookmark" eww-add-bookmark t]
 	["List bookmarks" eww-list-bookmarks t]
 	["List cookies" url-cookie-list t]))
@@ -1560,6 +1562,134 @@ Differences in #targets are ignored."
   (setq buffer-read-only t
 	truncate-lines t))
 
+;;; eww buffers list
+
+(defun eww-list-buffers ()
+  "List the eww-histories."
+  (interactive)
+  (let (buffers-info
+        (current (current-buffer)))
+    (dolist (buffer (buffer-list))
+      (with-current-buffer buffer
+        (if (derived-mode-p 'eww-mode)
+            (push (vector buffer (plist-get eww-data :title)
+                          (plist-get eww-data :url))
+                  buffers-info))))
+    (or buffers-info
+        (error "No eww buffers"))
+    (setq buffers-info (nreverse buffers-info)) ;get 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)
+            (if (eq current buffer)
+                (setq current-buffer-line line))))
+        (goto-char (point-min))
+        (forward-line (1- current-buffer-line)))))
+  (pop-to-buffer "*eww buffers*"))
+
+(defun eww-buffer-select ()
+  "Switch to eww buffer."
+  (interactive)
+  (let ((buffer (get-text-property (line-beginning-position)
+                                   'eww-buffer)))
+    (or buffer
+        (error "No buffer on current line"))
+    (quit-window)
+    (switch-to-buffer buffer)))
+
+(defun eww-buffer-show ()
+  "Display buffer under point in eww buffer list."
+  (let ((buffer (get-text-property (line-beginning-position)
+                                   'eww-buffer)))
+    (or buffer
+        (error "No buffer on current line"))
+    (other-window -1)
+    (switch-to-buffer buffer)
+    (other-window 1)))
+
+(defun eww-buffer-show-next ()
+  "Move to next eww buffer in the list and display it."
+  (interactive)
+  (forward-line)
+  (if (eobp)
+      (goto-char (point-min)))
+  (eww-buffer-show))
+
+(defun eww-buffer-show-previous ()
+  "Move to previous eww buffer in the list and display it."
+  (interactive)
+  (beginning-of-line)
+  (if (bobp)
+      (goto-char (point-max)))
+  (forward-line -1)
+  (eww-buffer-show))
+
+(defun eww-buffer-kill ()
+  "Kill buffer from eww list."
+  (interactive)
+  (let* ((start (line-beginning-position))
+	 (buffer (get-text-property start 'eww-buffer))
+	 (inhibit-read-only t))
+    (or buffer
+        (user-error "No buffer on the current line"))
+    (kill-buffer buffer)
+    (forward-line 1)
+    (delete-region start (point)))
+  (if (eobp)
+      (forward-line -1))
+  (eww-buffer-show))
+
+(defvar eww-buffers-mode-map
+  (let ((map (make-sparse-keymap)))
+    (suppress-keymap map)
+    (define-key map "q" 'quit-window)
+    (define-key map [(control k)] 'eww-buffer-kill)
+    (define-key map "\r" 'eww-buffer-select)
+    (define-key map "n" 'eww-buffer-show-next)
+    (define-key map "p" 'eww-buffer-show-previous)
+
+    (easy-menu-define nil map
+      "Menu for `eww-buffers-mode-map'."
+      '("Eww Buffers"
+        ["Exit" quit-window t]
+        ["Select" eww-buffer-select
+         :active (get-text-property (line-beginning-position) 'eww-buffer)]
+        ["Kill" eww-buffer-kill
+         :active (get-text-property (line-beginning-position) 'eww-buffer)]))
+    map))
+
+(define-derived-mode eww-buffers-mode nil "eww buffers"
+  "Mode for listing buffers.
+
+\\{eww-buffers-mode-map}"
+  (buffer-disable-undo)
+  (setq buffer-read-only t
+	truncate-lines t))
+
 ;;; Desktop support
 
 (defvar eww-desktop-data-save
-- 
2.1.3






             reply	other threads:[~2014-11-20 23:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 23:05 Andrey Kotlarski [this message]
     [not found] ` <handler.19131.B.141652478814119.ack@debbugs.gnu.org>
2014-11-20 23:23   ` bug#19131: Acknowledgement (25.0.50; [PATCH] eww.el: Create simple mode to manage eww buffers) Andrey Kotlarski
2014-12-07 19:36     ` Lars Magne Ingebrigtsen
2014-12-08 13:01       ` Andrey Kotlarski
2014-12-08 18:30         ` Lars Magne Ingebrigtsen

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=87vbm9iib9.fsf@gmail.com \
    --to=m00naticus@gmail.com \
    --cc=19131@debbugs.gnu.org \
    /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.