From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: Re: eww and bookmarks Date: Sun, 07 Jun 2020 17:09:48 +0200 Message-ID: <87mu5ec3pf.fsf@web.de> References: <87k1163jz5.fsf@gmail.com> <87tv0a5k5b.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="37727"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Lars Ingebrigtsen To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Jun 07 17:12:40 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhwyV-0009le-Ir for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Jun 2020 17:12:39 +0200 Original-Received: from localhost ([::1]:46186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhwyU-0006qU-4m for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Jun 2020 11:12:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhwvo-0004tg-UB for emacs-devel@gnu.org; Sun, 07 Jun 2020 11:09:52 -0400 Original-Received: from mout.web.de ([212.227.15.4]:41745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhwvn-00040n-Jw for emacs-devel@gnu.org; Sun, 07 Jun 2020 11:09:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1591542589; bh=RNH8wNHeAGYIskU3VaQFAtPFZd+Hlsc9j6n75afhhtc=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=C6GoSsNNzQvsAyTuqCbGYhDvlNn9wV5NULnCWOAREUsBAxCD+bQ5yfzw3VATWkrdI FGxljDjrn+MjACoQWlLONFN1GQIDdevXtepI0ddHCJG4+rfuc77NSk5cxxgv9YH4Nc m432/6IWq6EvBcPcdaRFPqILX7elM3hJrOoMpJ1g= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from drachen.dragon ([94.217.119.187]) by smtp.web.de (mrweb005 [213.165.67.108]) with ESMTPSA (Nemesis) id 1N7xeZ-1iw5C21NEx-0151VD; Sun, 07 Jun 2020 17:09:49 +0200 In-Reply-To: <87tv0a5k5b.fsf@web.de> (Michael Heerdegen's message of "Thu, 21 May 2020 00:14:24 +0200") X-Provags-ID: V03:K1:B1VdkgYDYHB7wZowqJVSQOoiwg8J6uQ1VdQUsrb6HPSFCAEAwTA szKKDFD5+nC/2149/ijjYUi6VBzTvuC+NEX57KiKAaODZAlt+taR5rytDZ42y6/y+iVoPTt DThF9FjqPXZhWqXoEc0AnlpPLyVM7aUUC9lXDn2wJPN8P8jEOmwKQJ6mwFtRJweuSNskzqY b9gP4MbWeUEdddO1IVfvg== X-UI-Out-Filterresults: notjunk:1;V03:K0:C790qDOmcZU=:D96acKZZwIcqxwVCcTJCsJ q7Q5EDgS+mP69K5bEc5Z4aBvPHdnD5rNImcxBiXC9DF8dar7wF7VQcqjA4dxlVL91hK1t3zAm ocvQUUQ5iQ6xSw/ZpG6qDGjpzO7k8diWJIHOV+wMwINHFBipI/HQp7M9NrWJIKoNTVSOKB7xP vNt7Pja5mU8fBTtttmRt0INfCVwCuyJXDqeYaVNSRmuvSmRefLuHpHhhu6xUDSn/64i6Rmhp+ xmAB98rwtWGPssqPM5NFVO8VNXo+zqulQZfrF3jhw8nT7PgzjR8t4onu/OjOoVw9RRJcTotWH NP5YdmIeHZEUmPytoxlt297o4c6aovV7S2kHMpU5XvyQ+31qCizugrXjQKdipQlHXvoSOmNp4 3mLkxMBCoG6TZ6YtiAbc9neDMRaiujCttsciP7qlCk31Unlqor7Sz9Jn3tPOL2JEhgHxFhCad Bw5nvu3LtXu5NeW+gMKSjapt5HYly/daawGubRKaLxIHC+MQjaei113uQEtx0Nz9Bb69MMTZq JuRlJHSKgdgn6MPhL1bcqPFBfqoe4KwHRNuyKTpKFFNq3izA3iI7PyhGmWPM4C3T1w9LV4fnB nmx3L3NwzukSUkUfw67qEwN4+WvBnowdeRm9r7c4MDOWOaKBf10ufa6lsToGexkAqMT01yZsm epN3e5hJ2KYZhUfVod9ckdtYdkYdPer6W8o3f/U5mvhWStWv6RWQ3bn1nqCe6m5l1b4SF5zw3 ybjSzRpDZF6Orr7cuHHmLfDoHP6m3EvXRdDjvYBaNMihtnlU1QUWpbORw47TVUU9LmR5dDXY Received-SPF: pass client-ip=212.227.15.4; envelope-from=michael_heerdegen@web.de; helo=mout.web.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/07 10:45:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252011 Archived-At: --=-=-= Content-Type: text/plain Michael Heerdegen 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=WIP-Make-standard-bookmarks-work-for-eww-buffers.patch Content-Transfer-Encoding: quoted-printable =46rom 520ada35ad5804b01afa84fd258d59ecc567799f Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Wed, 25 Mar 2020 03:55:41 +0100 Subject: [PATCH] WIP: Make standard bookmarks work for eww buffers =2D-- 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 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -403,6 +403,9 @@ The function that is invoked when clicking on or other= wise 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 =2D-- 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-buffe= r) + ;; 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 () =2D- 2.26.2 --=-=-= Content-Type: text/plain Thanks, Michael. --=-=-=--