all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: emacs-devel@gnu.org
Cc: Lars Ingebrigtsen <larsi@gnus.org>
Subject: Re: eww and bookmarks
Date: Sun, 07 Jun 2020 17:09:48 +0200	[thread overview]
Message-ID: <87mu5ec3pf.fsf@web.de> (raw)
In-Reply-To: <87tv0a5k5b.fsf@web.de> (Michael Heerdegen's message of "Thu, 21 May 2020 00:14:24 +0200")

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

Michael Heerdegen <michael_heerdegen@web.de> writes:

> I'll install my suggested patch as well soon, sorry for the delay.

Coming back to this: I've got a problem with the implementation: because
eww retrieves asynchronously, jumping to the bookmark's position does
not work, because when that is done, the buffer is not yet filled and
rendered.  I don't see a way to make this work that is not either an
ugly hack or would involve changing and refactoring parts of the eww
code.  I don't really feel qualified.

What would be needed at least would be to replace the hardcoded
#'eww-render in the `url-retrieve' call in `eww' with a newly introduced
variable `eww-render-function' I could bind.  Or is there a better way?

Here is what I have so far:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: WIP-Make-standard-bookmarks-work-for-eww-buffers.patch --]
[-- Type: text/x-diff, Size: 4604 bytes --]

From 520ada35ad5804b01afa84fd258d59ecc567799f Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Wed, 25 Mar 2020 03:55:41 +0100
Subject: [PATCH] WIP: Make standard bookmarks work for eww buffers

---
 etc/NEWS        |  3 +++
 lisp/net/eww.el | 58 +++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ed4722b27f..3ddfbe3d25 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -403,6 +403,9 @@ The function that is invoked when clicking on or otherwise following a
 'mailto:' link in an EWW buffer can now be customized.  For more
 information, see the related entry about 'shr-browse-url' above.

+*** Support for bookmark.el.
+EWW buffers can now be bookmarked with standard bookmarks.
+
 ** Project

 *** New user option 'project-vc-merge-submodules'.
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 2a70560ca7..3b1948649d 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -83,6 +83,13 @@ eww-bookmarks-directory
   :group 'eww
   :type 'directory)

+(defcustom bookmark-eww-browse-url-function #'eww-browse-url
+  "Doc..."
+  :type '(choice
+          (function-item eww-browse-url :doc "Use eww")
+          (const :tag "Use value of `browse-url-browser-function'" nil)
+          function))
+
 (defcustom eww-desktop-remove-duplicates t
   "Whether to remove duplicates from the history when saving desktop data.
 If non-nil, repetitive EWW history entries (comprising of the URI, the
@@ -895,6 +902,8 @@ eww-mode
   (setq-local desktop-save-buffer #'eww-desktop-misc-data)
   ;; multi-page isearch support
   (setq-local multi-isearch-next-buffer-function #'eww-isearch-next-buffer)
+  ;; Emacs bookmarks support
+  (setq-local bookmark-make-record-function #'eww-bookmark-make-record)
   (setq truncate-lines t)
   (buffer-disable-undo)
   (setq buffer-read-only t))
@@ -1720,6 +1729,11 @@ eww-toggle-colors

 (defvar eww-bookmarks nil)

+(defun eww--bookmark-title (title-string)
+  (replace-regexp-in-string
+   "\\` +\\| +\\'" ""
+   (replace-regexp-in-string "[\n\t\r]" " " title-string)))
+
 (defun eww-add-bookmark ()
   "Bookmark the current page."
   (interactive)
@@ -1728,13 +1742,10 @@ eww-add-bookmark
     (when (equal (plist-get eww-data :url) (plist-get bookmark :url))
       (user-error "Already bookmarked")))
   (when (y-or-n-p "Bookmark this page?")
-    (let ((title (replace-regexp-in-string "[\n\t\r]" " "
-					   (plist-get eww-data :title))))
-      (setq title (replace-regexp-in-string "\\` +\\| +\\'" "" title))
-      (push (list :url (plist-get eww-data :url)
-		  :title title
-		  :time (current-time-string))
-	    eww-bookmarks))
+    (push (list :url (plist-get eww-data :url)
+		:title (eww--bookmark-title (plist-get eww-data :title))
+		:time (current-time-string))
+	  eww-bookmarks)
     (eww-write-bookmarks)
     (message "Bookmarked %s (%s)" (plist-get eww-data :url)
 	     (plist-get eww-data :title))))
@@ -1888,6 +1899,39 @@ eww-bookmark-mode
   (buffer-disable-undo)
   (setq truncate-lines t))

+;;; Emacs bookmarks support
+
+(declare-function bookmark-make-record-default
+                  "bookmark" (&optional no-file no-context posn))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-default-handler "bookmark" (bmk))
+
+(defun eww-bookmark-make-record  ()
+  "Create an emacs bookmark record for an eww buffer.
+This implements the `bookmark-make-record-function' type (which
+see)."
+  (let ((url (plist-get eww-data :url)))
+    `(,(plist-get eww-data :title)
+      ,@(bookmark-make-record-default 'no-file)
+      (url      . ,url)
+      (defaults . (,(eww--bookmark-title (plist-get eww-data :title))
+                   ,url))
+      (handler  . ,#'bookmark-eww-bookmark-jump))))
+
+(declare-function bookmark-get-bookmark-record bookmark)
+;;;###autoload
+(defun bookmark-eww-bookmark-jump (bookmark)
+  "Bookmark handler for eww buffers."
+  (let ((browse-url-fun (or bookmark-eww-browse-url-function
+                            browse-url-browser-function)))
+    (funcall browse-url-fun (bookmark-prop-get bookmark 'url))
+    (when (eq browse-url-fun #'eww-browse-url)
+      ;;FIXME: this doesn't work because eww renders asynchronously:
+      (bookmark-default-handler
+       `(""
+         (buffer . ,(current-buffer)) .
+         ,(bookmark-get-bookmark-record bookmark))))))
+
 ;;; History code

 (defun eww-save-history ()
--
2.26.2


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



Thanks,

Michael.

  reply	other threads:[~2020-06-07 15:09 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 11:48 eww and bookmarks Matthias Meulien
2020-05-20 16:29 ` Drew Adams
2020-05-20 16:35   ` Noam Postavsky
2020-05-20 16:40     ` Drew Adams
2020-05-20 20:13     ` Matthias Meulien
2020-05-23 22:56       ` Michael Heerdegen
2020-05-24  8:44         ` Matthias Meulien
2020-05-24 14:14           ` Alfred M. Szmidt
2020-05-24 19:06             ` Karl Fogel
2020-05-25  4:35             ` Michael Heerdegen
2020-05-25  5:26               ` Alfred M. Szmidt
2020-05-26  2:17                 ` Michael Heerdegen
2020-06-10 15:39                   ` Lars Ingebrigtsen
2020-06-10 20:03                     ` Drew Adams
2020-05-25 12:51               ` Stefan Monnier
2020-05-25 13:52                 ` Marcin Borkowski
2020-05-25 15:03                 ` Alfred M. Szmidt
2020-05-25 15:24                   ` Stefan Monnier
2020-05-25 23:40                   ` Michael Heerdegen
     [not found]                 ` <e23432dd-212b-4bf0-8e8c-185988c653f0@default>
2020-05-26  1:04                   ` Michael Heerdegen
2020-05-27  5:10                     ` Drew Adams
2020-05-25  4:28           ` Michael Heerdegen
2020-05-25 14:35             ` T.V Raman
2020-05-20 22:14     ` Michael Heerdegen
2020-06-07 15:09       ` Michael Heerdegen [this message]
2020-06-07 15:30         ` Basil L. Contovounesios
2020-06-07 16:13           ` Michael Heerdegen
2020-06-07 16:36             ` Tomas Hlavaty
2020-06-07 18:23             ` Basil L. Contovounesios
2020-06-08 14:49               ` Michael Heerdegen
2020-06-08 16:54                 ` Basil L. Contovounesios
2020-06-10 12:01                   ` Michael Heerdegen
2020-06-07 16:36           ` Lars Ingebrigtsen
2020-06-07 18:23             ` Basil L. Contovounesios
2020-06-08 14:42           ` Michael Heerdegen
2020-06-08 16:58             ` Basil L. Contovounesios
2020-06-10 12:06               ` Michael Heerdegen
2020-10-26 18:15                 ` Adam Porter
2020-10-26 18:33                   ` Drew Adams
2020-10-26 18:43                   ` Lars Ingebrigtsen
2020-10-26 19:05                     ` Adam Porter
2020-10-26 19:26                   ` Karl Fogel
2020-06-07 16:31         ` Clément Pit-Claudel
  -- strict thread matches above, loose matches on Subject: below --
2020-05-27  7:18 Boruch Baum
2020-05-27 14:40 ` Drew Adams

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=87mu5ec3pf.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.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.