* Bookmarks in EWW @ 2020-03-23 11:26 Marcin Borkowski 2020-03-23 14:56 ` Drew Adams 2020-03-23 20:41 ` Michael Heerdegen 0 siblings, 2 replies; 39+ messages in thread From: Marcin Borkowski @ 2020-03-23 11:26 UTC (permalink / raw) To: Help Gnu Emacs mailing list Hi all, I have just noticed that Emacs bookmarks do not work in EWW (which has its own bookmarks). Is there a way to use Emacs bookmarks with EWW (other than bookmark+, which is too heavy for me)? TIA, -- Marcin Borkowski http://mbork.pl ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: Bookmarks in EWW 2020-03-23 11:26 Bookmarks in EWW Marcin Borkowski @ 2020-03-23 14:56 ` Drew Adams 2020-03-25 11:48 ` Marcin Borkowski 2020-03-23 20:41 ` Michael Heerdegen 1 sibling, 1 reply; 39+ messages in thread From: Drew Adams @ 2020-03-23 14:56 UTC (permalink / raw) To: Marcin Borkowski, Help Gnu Emacs mailing list > I have just noticed that Emacs bookmarks do not work in EWW (which has > its own bookmarks). Is there a way to use Emacs bookmarks with EWW > (other than bookmark+, which is too heavy for me)? I know you're not keen on Bookmark+, Marcin. But for the benefit of others, at least, it lets you use Emacs bookmarks with EWW, and it provides several enhancements. As always, Bookmark+ (and vanilla) bookmarking features are available for such bookmarks, including tagging, annotating, keeping track of number of visits and latest visit time, etc. You can optionally automatically set a bookmark whenever you visit a URL with EWW. The bookmark name is the title of the web page. You can convert existing EWW "bookmarks" to Emacs bookmarks, using command `bmkp-convert-eww-bookmarks'. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-23 14:56 ` Drew Adams @ 2020-03-25 11:48 ` Marcin Borkowski 0 siblings, 0 replies; 39+ messages in thread From: Marcin Borkowski @ 2020-03-25 11:48 UTC (permalink / raw) To: Drew Adams; +Cc: Help Gnu Emacs mailing list On 2020-03-23, at 15:56, Drew Adams <drew.adams@oracle.com> wrote: >> I have just noticed that Emacs bookmarks do not work in EWW (which has >> its own bookmarks). Is there a way to use Emacs bookmarks with EWW >> (other than bookmark+, which is too heavy for me)? > > I know you're not keen on Bookmark+, Marcin. > But for the benefit of others, at least, it > lets you use Emacs bookmarks with EWW, and it > provides several enhancements. Fair enough - even though I'm probably not going to use it, someone might want to check it out. Thanks. > > As always, Bookmark+ (and vanilla) bookmarking > features are available for such bookmarks, > including tagging, annotating, keeping track of > number of visits and latest visit time, etc. > > You can optionally automatically set a bookmark > whenever you visit a URL with EWW. The bookmark > name is the title of the web page. > > You can convert existing EWW "bookmarks" to Emacs > bookmarks, using command `bmkp-convert-eww-bookmarks'. Best, -- Marcin Borkowski http://mbork.pl ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-23 11:26 Bookmarks in EWW Marcin Borkowski 2020-03-23 14:56 ` Drew Adams @ 2020-03-23 20:41 ` Michael Heerdegen 2020-03-24 14:46 ` Stefan Monnier 2020-03-25 11:49 ` Marcin Borkowski 1 sibling, 2 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-03-23 20:41 UTC (permalink / raw) To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list Marcin Borkowski <mbork@mbork.pl> writes: > Hi all, > > I have just noticed that Emacs bookmarks do not work in EWW (which has > its own bookmarks). Is there a way to use Emacs bookmarks with EWW > (other than bookmark+, which is too heavy for me)? Seems like `bookmark-make-record-function' is there to implement things like this. Several Emacs modes use it to provide bookmarks (Info, doc-view, etc). Haven't tried but looks promising. Bookmarks can have a `handler' field to implement non-standard behavior. Your `bookmark-make-record-function' should return an according record using an eww handler you want to write. Look how the other modes do it. Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-23 20:41 ` Michael Heerdegen @ 2020-03-24 14:46 ` Stefan Monnier 2020-03-25 3:05 ` Michael Heerdegen 2020-03-25 11:49 ` Marcin Borkowski 1 sibling, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-03-24 14:46 UTC (permalink / raw) To: help-gnu-emacs >> I have just noticed that Emacs bookmarks do not work in EWW (which has >> its own bookmarks). Is there a way to use Emacs bookmarks with EWW >> (other than bookmark+, which is too heavy for me)? > > Seems like `bookmark-make-record-function' is there to implement things > like this. Several Emacs modes use it to provide bookmarks (Info, > doc-view, etc). Haven't tried but looks promising. Bookmarks can have > a `handler' field to implement non-standard behavior. Your > `bookmark-make-record-function' should return an according record using > an eww handler you want to write. Look how the other modes do it. So should we expect a patch shortly on `master`? Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-24 14:46 ` Stefan Monnier @ 2020-03-25 3:05 ` Michael Heerdegen 2020-03-25 3:45 ` `declare-function' docu (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor ` (2 more replies) 0 siblings, 3 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-03-25 3:05 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 182 bytes --] Stefan Monnier <monnier@iro.umontreal.ca> writes: > So should we expect a patch shortly on `master`? My thoughts. Ok, I've thrown something together (draft!) and tested quickly: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-WIP-Make-standard-bookmarks-work-for-eww-buffers.patch --] [-- Type: text/x-diff, Size: 1805 bytes --] From 1c5929ee230d4efddfb4b0e0c647653026da4bd1 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 --- lisp/net/eww.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lisp/net/eww.el b/lisp/net/eww.el index c83884fd25..8d0405ba0e 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -889,6 +889,9 @@ 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 + (defvar bookmark-make-record-function) + (setq-local bookmark-make-record-function #'eww-bookmark-make-record) (setq truncate-lines t) (buffer-disable-undo) (setq buffer-read-only t)) @@ -1880,6 +1883,27 @@ 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 () + "Doc..." + (let ((url (plist-get eww-data :url))) + `(,(plist-get eww-data :title) + ,@(bookmark-make-record-default 'no-file) + (url . ,url) + (handler . bookmark-eww-bookmark-jump)))) + +;;;###autoload +(defun bookmark-eww-bookmark-jump (bookmark) + "Default bookmark handler for eww buffers." + (eww-browse-url (bookmark-prop-get bookmark 'url)) + (bookmark-default-handler bookmark)) + ;;; History code (defun eww-save-history () -- 2.25.1 [-- Attachment #3: Type: text/plain, Size: 431 bytes --] Questions: Does it make sense that these bookmarks save a text part? Surely makes sense for some cases, e.g. locally saved documentation in html, but makes not much sense for e.g. newspaper sites. Do I need to declare `bookmark-make-record-function' as special when setting with `setq-local' (that's what doc-view does)? If the answer is "yes", do I need to do it at top-level? Do I have to add a NEWS entry? TIA, Michael. ^ permalink raw reply related [flat|nested] 39+ messages in thread
* `declare-function' docu (was: Re: Bookmarks in EWW) 2020-03-25 3:05 ` Michael Heerdegen @ 2020-03-25 3:45 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-28 17:59 ` `declare-function' docu Bruno Félix Rezende Ribeiro 2020-03-25 14:06 ` Bookmarks in EWW Stefan Monnier 2020-03-25 21:48 ` Bookmarks in EWW Drew Adams 2 siblings, 1 reply; 39+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-03-25 3:45 UTC (permalink / raw) To: help-gnu-emacs Michael Heerdegen wrote: > (declare-function ... I didn't know about `declare-function', so I used `C-h f' to find out that... err... then I followed the link, provided by the help page (great!), which lead to the info pages, specifically this one (info "(elisp) Declaring Functions") ^eval me and it says: Byte-compiling a file often produces warnings about functions that the compiler doesn’t know about. Sometimes this indicates a real problem, but usually the functions in question are defined in other files which would be loaded if that code is run. For example, byte-compiling ‘simple.el’ used to warn: simple.el:8727:1:Warning: the function ‘shell-mode’ is not known to be defined. In fact, ‘shell-mode’ is used only in a function that executes ‘(require 'shell)’ before calling ‘shell-mode’, so ‘shell-mode’ will be defined properly at run-time. When you know that such a warning does not indicate a real problem, it is good to suppress the warning. That makes new warnings which might mean real problems more visible. You do that with ‘declare-function’. All you need to do is add a ‘declare-function’ statement before the first use of the function in question: (declare-function shell-mode "shell" ()) This says that ‘shell-mode’ is defined in ‘shell.el’ (the ‘.el’ can be omitted). The compiler takes for granted that that file really defines the function, and does not check. [...] That's were I stopped reading! Here we see the benefits of links from the docstring-based help system to the info pages, which IMO should always be present when available. When this issue was brought up last time around, there was the argument that links would increase the size of Emacs. However, if one is really concerned with size at that level, cannot the hyperlinks be computed on-the-fly? That would provide the functionality while not increasing the size - well, not lineary, at least! And if anyone was concerned with speed, we could have an option to switch it on and off... Also, the two pieces of documentation seem to have completely different focus points? The docstring help focuses on technical aspects instead of the purpose, while the info just says instantly, ~"use this to shut the byte-compiler up". -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: `declare-function' docu 2020-03-25 3:45 ` `declare-function' docu (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-03-28 17:59 ` Bruno Félix Rezende Ribeiro 2020-03-28 18:38 ` Drew Adams 2020-03-28 21:38 ` Emanuel Berg via Users list for the GNU Emacs text editor 0 siblings, 2 replies; 39+ messages in thread From: Bruno Félix Rezende Ribeiro @ 2020-03-28 17:59 UTC (permalink / raw) To: help-gnu-emacs Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> writes: > Here we see the benefits of links from the docstring-based > help system to the info pages, which IMO should always be > present when available. When this issue was brought up last > time around, there was the argument that links would increase > the size of Emacs. For anyone that doesn’t know and is interested, there is the package ‘helpful’[1] on MELPA which provides (among many other things) links to the info manuals from its ‘*help*’ buffers. (describe-package 'helpful) Footnotes: [1] https://github.com/wilfred/helpful -- Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF] <http://oitofelix.freeshell.org/> ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: `declare-function' docu 2020-03-28 17:59 ` `declare-function' docu Bruno Félix Rezende Ribeiro @ 2020-03-28 18:38 ` Drew Adams 2020-04-09 12:30 ` Bruno Félix Rezende Ribeiro 2020-03-28 21:38 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 1 reply; 39+ messages in thread From: Drew Adams @ 2020-03-28 18:38 UTC (permalink / raw) To: Bruno Félix Rezende Ribeiro, help-gnu-emacs > > Here we see the benefits of links from the docstring-based > > help system to the info pages, which IMO should always be > > present when available. When this issue was brought up last > > time around, there was the argument that links would increase > > the size of Emacs. > > For anyone that doesn’t know and is interested, there is the package > ‘helpful’[1] on MELPA which provides (among many other things) links to > the info manuals from its ‘*help*’ buffers. > > (describe-package 'helpful) > > [1] > https://urldefense.com/v3/__https://github.com/wilfred/helpful__;!!Gqiv > PVa7Brio!PvV817f2RWtnUCodAGybbqf0ieslwKXhTIpY4ie5T7VwmIPQytGCQCwFEkrnNe > AB$ Similarly, help-fns+.el. There you have option `help-cross-reference-manuals': `help-cross-reference-manuals' is a variable defined in `help-fns+.el'. Its value is (("emacs" "elisp")) Documentation: Manuals to search, for a `*Help*' buffer link to the manuals. A cons. The car is a list of manuals to search, or the symbol `all', to search all. If nil, then do not create a cross-reference link. The cdr is a boolean: Non-`nil' means search the manuals, then create a cross-ref link: create it only if some search hits are found. `nil' means create a cross-ref link without searching manuals first (but only if there are some manuals to search). You can customize this variable. --- https://www.emacswiki.org/emacs/download/help-fns%2b.el ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: `declare-function' docu 2020-03-28 18:38 ` Drew Adams @ 2020-04-09 12:30 ` Bruno Félix Rezende Ribeiro 2020-04-09 15:47 ` Drew Adams 0 siblings, 1 reply; 39+ messages in thread From: Bruno Félix Rezende Ribeiro @ 2020-04-09 12:30 UTC (permalink / raw) To: Drew Adams; +Cc: Bruno Félix Rezende Ribeiro, help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 273 bytes --] Hi Drew, Drew Adams <drew.adams@oracle.com> writes: > Similarly, help-fns+.el. I see you’re the author. Do you plan to contribute it to Emacs core or GNU ELPA? -- Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF] <http://oitofelix.freeshell.org/> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 454 bytes --] ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: `declare-function' docu 2020-04-09 12:30 ` Bruno Félix Rezende Ribeiro @ 2020-04-09 15:47 ` Drew Adams 0 siblings, 0 replies; 39+ messages in thread From: Drew Adams @ 2020-04-09 15:47 UTC (permalink / raw) To: Bruno Félix Rezende Ribeiro; +Cc: help-gnu-emacs > > Similarly, help-fns+.el. > > I see you’re the author. Do you plan to > contribute it to Emacs core or GNU ELPA? I've offered its code, and that of all my libraries, several times. A few things from help-fns+.el have been integrated (e.g. `describe-keymap' - see Emacs bug #30660), albeit in a somewhat lesser form. But in general there's been little to no interest. From my point of view, I'd much prefer that vanilla Emacs offer such features, so I'd no longer need to maintain separate libraries. In the particular case of adding links from *Help* to manuals, I think the approaches being looked at now probably make sense - they may be performant. But some aspects of the simple approach to this taken in help-fns+.el might also help - such as user choice of whether to find lookup addresses ahead of time or just when following links. If the cost of systematically finding them ahead of time isn't too great, fine. Besides lookup cost, letting users specify which manuals to check can be useful - the set of manuals available differs for different users/platforms, and which ones to link to (search) is a question for users. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: `declare-function' docu 2020-03-28 17:59 ` `declare-function' docu Bruno Félix Rezende Ribeiro 2020-03-28 18:38 ` Drew Adams @ 2020-03-28 21:38 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 39+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-03-28 21:38 UTC (permalink / raw) To: help-gnu-emacs Bruno Félix Rezende Ribeiro wrote: >> Here we see the benefits of links from the >> docstring-based help system to the info pages, which >> IMO should always be present when available. When this >> issue was brought up last time around, there was the >> argument that links would increase the size of Emacs. > > For anyone that doesn’t know and is interested, there > is the package ‘helpful’[1] on MELPA which provides > (among many other things) links to the info manuals > from its ‘*help*’ buffers. "helpful" - clever! :) -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-25 3:05 ` Michael Heerdegen 2020-03-25 3:45 ` `declare-function' docu (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-03-25 14:06 ` Stefan Monnier 2020-03-26 1:09 ` Michael Heerdegen 2020-03-27 4:32 ` buffer-localness (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-25 21:48 ` Bookmarks in EWW Drew Adams 2 siblings, 2 replies; 39+ messages in thread From: Stefan Monnier @ 2020-03-25 14:06 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs > Ok, I've thrown something together (draft!) and tested quickly: Thanks. > + ;; Emacs bookmarks support > + (defvar bookmark-make-record-function) > + (setq-local bookmark-make-record-function #'eww-bookmark-make-record) No need for the `defvar` here. > Does it make sense that these bookmarks save a text part? Surely makes > sense for some cases, e.g. locally saved documentation in html, but > makes not much sense for e.g. newspaper sites. As you say, it's useful for pages which don't change (or not much), and it should be harmless for those pages that change too frequently. > Do I need to declare `bookmark-make-record-function' as special when > setting with `setq-local' (that's what doc-view does)? No. buffer-localness is a concept that only applies to dynamically scoped variables anyway, so if you need it it's a sign that we should improve something somewhere. > Do I have to add a NEWS entry? I think it deserves a mention, yes. Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-25 14:06 ` Bookmarks in EWW Stefan Monnier @ 2020-03-26 1:09 ` Michael Heerdegen 2020-03-26 4:07 ` Stefan Monnier 2020-03-27 4:32 ` buffer-localness (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-03-26 1:09 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > > + ;; Emacs bookmarks support > > + (defvar bookmark-make-record-function) > > + (setq-local bookmark-make-record-function #'eww-bookmark-make-record) > > No need for the `defvar` here. > > Do I need to declare `bookmark-make-record-function' as special when > > setting with `setq-local' (that's what doc-view does)? > > No. buffer-localness is a concept that only applies to dynamically > scoped variables anyway, so if you need it it's a sign that we should > improve something somewhere. Well, if I remove that defvar as you suggest, leaving none in that file, I get make[2]: Entering directory '/home/micha/software/emacs/lisp' ELC net/eww.elc In eww-mode: net/eww.el:893:47: Warning: assignment to free variable ‘bookmark-make-record-function’ Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-26 1:09 ` Michael Heerdegen @ 2020-03-26 4:07 ` Stefan Monnier 2020-03-27 2:07 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-03-26 4:07 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs > make[2]: Entering directory '/home/micha/software/emacs/lisp' > ELC net/eww.elc > > In eww-mode: > net/eww.el:893:47: Warning: assignment to free variable > ‘bookmark-make-record-function’ Ah, yes, it still complains, more as a warning (in case you just mis-typed the name of some other variable). But the generated code is fine (i.e. the defvar only silences the warnings). Maybe we should teach the byte-compiler to recognize `make-local-variable` as a declaration that the variable is dynamic? Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-26 4:07 ` Stefan Monnier @ 2020-03-27 2:07 ` Michael Heerdegen 2020-03-27 3:44 ` Stefan Monnier 0 siblings, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-03-27 2:07 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > Maybe we should teach the byte-compiler to recognize > `make-local-variable` as a declaration that the variable is dynamic? I think that would make sense, yes (i can't do it though cause I don't speak C). Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-27 2:07 ` Michael Heerdegen @ 2020-03-27 3:44 ` Stefan Monnier 2020-03-28 2:31 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-03-27 3:44 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs >> Maybe we should teach the byte-compiler to recognize >> `make-local-variable` as a declaration that the variable is dynamic? > I think that would make sense, yes (i can't do it though cause I don't > speak C). Nice try, but you won't get off the hook so easily: the byte-compiler is all written in Elisp. Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-27 3:44 ` Stefan Monnier @ 2020-03-28 2:31 ` Michael Heerdegen 2020-03-28 2:55 ` Stefan Monnier 0 siblings, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-03-28 2:31 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > Nice try, but you won't get off the hook so easily: the byte-compiler > is all written in Elisp. Hmm, too bad. Ok, we could ehm ... give `make-local-variable' a byte-hunk-handler that calls `byte-compile--declare-var'. Does that make sense? Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-28 2:31 ` Michael Heerdegen @ 2020-03-28 2:55 ` Stefan Monnier 2020-04-19 3:42 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-03-28 2:55 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs >> Nice try, but you won't get off the hook so easily: the byte-compiler >> is all written in Elisp. > Hmm, too bad. > Ok, we could ehm ... give `make-local-variable' a byte-hunk-handler that > calls `byte-compile--declare-var'. Does that make sense? Sounds credible, yes, Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-28 2:55 ` Stefan Monnier @ 2020-04-19 3:42 ` Michael Heerdegen 2020-04-19 13:18 ` Stefan Monnier 0 siblings, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-04-19 3:42 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > >> Nice try, but you won't get off the hook so easily: the byte-compiler > >> is all written in Elisp. > > Hmm, too bad. > > Ok, we could ehm ... give `make-local-variable' a byte-hunk-handler that > > calls `byte-compile--declare-var'. Does that make sense? > > Sounds credible, yes, But it seems that this byte-hunk-handler is ignored unless `make-local-variable' is called at top-level. Is this expected? Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-19 3:42 ` Michael Heerdegen @ 2020-04-19 13:18 ` Stefan Monnier 2020-04-20 3:17 ` Michael Heerdegen 2020-04-27 2:43 ` Michael Heerdegen 0 siblings, 2 replies; 39+ messages in thread From: Stefan Monnier @ 2020-04-19 13:18 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs Michael Heerdegen [2020-04-19 05:42:48] wrote: > Stefan Monnier <monnier@iro.umontreal.ca> writes: > >> >> Nice try, but you won't get off the hook so easily: the byte-compiler >> >> is all written in Elisp. >> > Hmm, too bad. >> > Ok, we could ehm ... give `make-local-variable' a byte-hunk-handler that >> > calls `byte-compile--declare-var'. Does that make sense? >> >> Sounds credible, yes, > > But it seems that this byte-hunk-handler is ignored unless > `make-local-variable' is called at top-level. Is this expected? Oh, right `byte-hunk-handler` is to handle top-level uses only (e.g. top-level uses of `require` trigger loading the file at compilation time, whereas they don't when not at top-level). I think you want to use `(byte-defop-compiler-1 make-local-variable)` and then define `byte-compile-make-local-variable`. Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-19 13:18 ` Stefan Monnier @ 2020-04-20 3:17 ` Michael Heerdegen 2020-04-20 13:24 ` Stefan Monnier 2020-04-27 2:43 ` Michael Heerdegen 1 sibling, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-04-20 3:17 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 594 bytes --] Stefan Monnier <monnier@iro.umontreal.ca> writes: > Oh, right `byte-hunk-handler` is to handle top-level uses only > (e.g. top-level uses of `require` trigger loading the file at > compilation time, whereas they don't when not at top-level). Yeah, I guess such stuff could be mentioned in the file header... > I think you want to use `(byte-defop-compiler-1 make-local-variable)` > and then define `byte-compile-make-local-variable`. Oh, that's what I originally wanted to try first, but `byte-defop-compiler-1' sounded too creepy. But that works now (unless I've missed something else): [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-WIP-My-byte-compile-local-patch.patch --] [-- Type: text/x-diff, Size: 1228 bytes --] From a21a6af1dfb60db4ba1c028aff91902649eae920 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen <michael_heerdegen@web.de> Date: Fri, 10 Apr 2020 01:21:33 +0200 Subject: [PATCH] WIP: My byte compile local patch --- lisp/emacs-lisp/bytecomp.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 4f01918bdb..4fdb6e65b7 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -4752,6 +4752,14 @@ byte-compile-make-variable-buffer-local (defun byte-compile-form-make-variable-buffer-local (form) (byte-compile-keep-pending form 'byte-compile-normal-call)) +(byte-defop-compiler-1 make-local-variable + byte-compile-make-local-variable) +(defun byte-compile-make-local-variable (form) + (let ((var-exp (car-safe (cdr-safe form)))) + (when (eq 'quote (car-safe var-exp)) + (byte-compile--declare-var (car (cdr var-exp))))) + (byte-compile-normal-call form)) + (put 'function-put 'byte-hunk-handler 'byte-compile-define-symbol-prop) (put 'define-symbol-prop 'byte-hunk-handler 'byte-compile-define-symbol-prop) (defun byte-compile-define-symbol-prop (form) -- 2.26.1 [-- Attachment #3: Type: text/plain, Size: 11 bytes --] Michael. ^ permalink raw reply related [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-20 3:17 ` Michael Heerdegen @ 2020-04-20 13:24 ` Stefan Monnier 2020-04-21 0:59 ` Michael Heerdegen 2020-04-29 22:53 ` Michael Heerdegen 0 siblings, 2 replies; 39+ messages in thread From: Stefan Monnier @ 2020-04-20 13:24 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs > +(byte-defop-compiler-1 make-local-variable > + byte-compile-make-local-variable) > +(defun byte-compile-make-local-variable (form) > + (let ((var-exp (car-safe (cdr-safe form)))) > + (when (eq 'quote (car-safe var-exp)) > + (byte-compile--declare-var (car (cdr var-exp))))) > + (byte-compile-normal-call form)) LGTM, [ Tho all those car/cdr messes in bytecomp.el really creep me out. It's when working on the compiler that I developed the urge to implement `pcase`: (pcase form (`(,_ ',v) (byte-compile--declare-var v))) ] Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-20 13:24 ` Stefan Monnier @ 2020-04-21 0:59 ` Michael Heerdegen 2020-04-29 22:53 ` Michael Heerdegen 1 sibling, 0 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-04-21 0:59 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > (pcase form (`(,_ ',v) (byte-compile--declare-var v))) ] Oh - if I had known that I am allowed to use `pcase' I would have done so by myself, of course :-) But I see now that it appears here and there in the file - thanks for the hint! Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-20 13:24 ` Stefan Monnier 2020-04-21 0:59 ` Michael Heerdegen @ 2020-04-29 22:53 ` Michael Heerdegen 2020-04-30 1:25 ` Stefan Monnier 1 sibling, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-04-29 22:53 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > > +(byte-defop-compiler-1 make-local-variable > > + byte-compile-make-local-variable) > > +(defun byte-compile-make-local-variable (form) > > + (let ((var-exp (car-safe (cdr-safe form)))) > > + (when (eq 'quote (car-safe var-exp)) > > + (byte-compile--declare-var (car (cdr var-exp))))) > > + (byte-compile-normal-call form)) > > LGTM, In this example: #+begin_src emacs-lisp (defun test () (make-local-variable 'my-test-var) (with-current-buffer (get-buffer-create "Testbuffer") (setq my-test-var 27))) #+end_src the patch suppresses the warning. But M-: (test) leads to `my-test-var' being bound to 27 buffer-locally in "Testbuffer" although we never made the variable local there...is this cosher? Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-29 22:53 ` Michael Heerdegen @ 2020-04-30 1:25 ` Stefan Monnier 2020-04-30 2:08 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-04-30 1:25 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs > In this example: > > #+begin_src emacs-lisp > (defun test () > (make-local-variable 'my-test-var) > (with-current-buffer (get-buffer-create "Testbuffer") > (setq my-test-var 27))) > #+end_src > > the patch suppresses the warning. But M-: (test) leads to `my-test-var' > being bound to 27 buffer-locally in "Testbuffer" although we never made > the variable local there...is this cosher? This behavior is not related to the patch (I get the same result in Emacs-24, FWIW). It's pretty odd, indeed, tho. I think it warrants a `M-x report-emacs-bug` Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-30 1:25 ` Stefan Monnier @ 2020-04-30 2:08 ` Michael Heerdegen 2020-04-30 3:08 ` Stefan Monnier 0 siblings, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-04-30 2:08 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > > In this example: > > > > #+begin_src emacs-lisp > > (defun test () > > (make-local-variable 'my-test-var) > > (with-current-buffer (get-buffer-create "Testbuffer") > > (setq my-test-var 27))) > > #+end_src > > > > the patch suppresses the warning. But M-: (test) leads to `my-test-var' > > being bound to 27 buffer-locally in "Testbuffer" although we never made > > the variable local there...is this cosher? > > This behavior is not related to the patch (I get the same result in > Emacs-24, FWIW). But don't you think what the patch does (suppressing the justified warning for this case) is also bad? > It's pretty odd, indeed, tho. I think it warrants a `M-x > report-emacs-bug`. It's somewhat what I expected a bit. Ok, will report. Thanks, Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-30 2:08 ` Michael Heerdegen @ 2020-04-30 3:08 ` Stefan Monnier 2020-04-30 20:09 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Stefan Monnier @ 2020-04-30 3:08 UTC (permalink / raw) To: help-gnu-emacs >> > In this example: >> > >> > #+begin_src emacs-lisp >> > (defun test () >> > (make-local-variable 'my-test-var) >> > (with-current-buffer (get-buffer-create "Testbuffer") >> > (setq my-test-var 27))) >> > #+end_src >> > >> > the patch suppresses the warning. But M-: (test) leads to `my-test-var' >> > being bound to 27 buffer-locally in "Testbuffer" although we never made >> > the variable local there...is this cosher? >> >> This behavior is not related to the patch (I get the same result in >> Emacs-24, FWIW). > > But don't you think what the patch does (suppressing the justified > warning for this case) is also bad? No. Stefan ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-30 3:08 ` Stefan Monnier @ 2020-04-30 20:09 ` Michael Heerdegen 0 siblings, 0 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-04-30 20:09 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > > But don't you think what the patch does (suppressing the justified > > warning for this case) is also bad? > > No. Ok. Yes, also an explicit `defvar' declaration would suppress the warning in this corner case. Anyway, ehm...installed! Regards, Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-04-19 13:18 ` Stefan Monnier 2020-04-20 3:17 ` Michael Heerdegen @ 2020-04-27 2:43 ` Michael Heerdegen 1 sibling, 0 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-04-27 2:43 UTC (permalink / raw) To: Stefan Monnier; +Cc: help-gnu-emacs Stefan Monnier <monnier@iro.umontreal.ca> writes: > Oh, right `byte-hunk-handler` is to handle top-level uses only > (e.g. top-level uses of `require` trigger loading the file at > compilation time, whereas they don't when not at top-level). > > I think you want to use `(byte-defop-compiler-1 make-local-variable)` > and then define `byte-compile-make-local-variable`. And now I also understand why in #+begin_src emacs-lisp (defun byte-compile-make-variable-buffer-local (form) (if (and (eq (car-safe (car-safe (cdr-safe form))) 'quote) (byte-compile-warning-enabled-p 'make-local)) (byte-compile-warn ;; <-- "`make-variable-buffer-local' not called at toplevel")) (byte-compile-normal-call form)) #+end_src the warning seems to be raised unconditionally. There is an additional byte-hunk-handler for `make-variable-buffer-local', and first it seemed redundant to me, but AFAIU it shadows the above byte-defop-compiler-1 function for top-level calls. Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* buffer-localness (was: Re: Bookmarks in EWW) 2020-03-25 14:06 ` Bookmarks in EWW Stefan Monnier 2020-03-26 1:09 ` Michael Heerdegen @ 2020-03-27 4:32 ` Emanuel Berg via Users list for the GNU Emacs text editor 1 sibling, 0 replies; 39+ messages in thread From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-03-27 4:32 UTC (permalink / raw) To: help-gnu-emacs Stefan Monnier wrote: >> Do I need to declare `bookmark-make-record-function' >> as special when setting with `setq-local' (that's what >> doc-view does)? > > No. buffer-localness is a concept that only applies to > dynamically scoped variables anyway, so if you need it > it's a sign that we should improve something somewhere. Here is some Elisp that indicates something should be improved... (defun buffer-menu-custom-font-lock () (interactive) (let ((font-lock-unfontify-region-function (lambda (start end) (remove-text-properties start end '(font-lock-face nil))))) (font-lock-unfontify-buffer) (set (make-local-variable 'font-lock-defaults) '(buffer-menu-buffer-font-lock-keywords t)) (font-lock-ensure) )) https://dataswamp.org/~incal/emacs-init/buffer-menu.el (But... I don't think I wrote that. It looks like something from the wiki, perhaps.) -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: Bookmarks in EWW 2020-03-25 3:05 ` Michael Heerdegen 2020-03-25 3:45 ` `declare-function' docu (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-25 14:06 ` Bookmarks in EWW Stefan Monnier @ 2020-03-25 21:48 ` Drew Adams 2020-03-26 2:29 ` Michael Heerdegen 2 siblings, 1 reply; 39+ messages in thread From: Drew Adams @ 2020-03-25 21:48 UTC (permalink / raw) To: Michael Heerdegen, Stefan Monnier; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 1277 bytes --] > Ok, I've thrown something together (draft!) and tested quickly: Attached is something I threw together, by removing some of the Bookmark+ features for EWW and adapting the code to what vanilla bookmark.el offers. Completely untested; as is. Perhaps you can make some use of it. Features: * An auto-bookmarking mode, for those who might want to automatically update an existing bookmark, or create a new bookmark, whenever they visit a URL with EWW. * A user option for whether that mode can create new bookmarks or just update existing ones. * A toggle command for that user option. * A command to set (create or update) a bookmark for the URL currently visited by EWW. * An option for whether and how an EWW buffer gets renamed (the default is to use vanilla EWW name, `*eww*'). Note: this acts beyond just bookmarking. * An option for whether to generate a new buffer when you jump to an EWW bookmark (the default is to reuse an existing buffer for that URL). * An option for whether to replace corresponding EWW "bookmarking" commands with standard bookmarking commands, in EWW key bindings (`eww-mode-map'). * A command to create regular Emacs bookmarks from a file of existing EWW "bookmarks". HTH. [-- Attachment #2: bmk-eww.el --] [-- Type: application/octet-stream, Size: 12361 bytes --] ;; Quiet the byte-compiler. (defvar bookmark-alist) ; In `bookmark.el' (defvar bookmark-default-file) ; In `bookmark.el' (defvar bookmark-make-record-function) ; In `bookmark.el' (defvar eww-data) ; In `eww.el' (defvar eww-local-regex) ; In `eww.el' (defvar eww-mode-map) ; In `eww.el' (defvar eww-search-prefix) ; In `eww.el' (require 'bookmark) (require 'cl-seq) ; `cl-remove-if-not' (defcustom bmkp-eww-auto-type 'update-only "How `bmkp-eww-auto-bookmark-mode' behaves when enabled. You can toggle this option using `\\[bmkp-toggle-eww-auto-type]'." :type '(choice (const :tag "Create EWW bookmark or update existing EWW bookmark" create-or-update) (const :tag "Update existing EWW bookmark (only)" update-only)) :group 'bookmark) (defcustom bmkp-eww-buffer-renaming nil "Whether and how an EWW buffer is renamed. Non-nil values affect EWW behavior even when bookmarks are not used. * nil: Do not rename buffer - use `*eww*' (vanilla EWW behavior). * `url': Rename buffer to web-page title plus last 20 chars of URL. * `page': Rename buffer to web-page title (only)." :type '(choice (const :tag "Do not rename buffer (use name `*eww*')" nil) (const :tag "Rename buffer to web-page title plus last 20 chars of URL" url) ;; Any symbol other than `page' and nil is treated the same as `page'. (const :tag "Rename buffer to web-page title" page)) :group 'bookmark) (defcustom bmkp-eww-generate-buffer-flag nil "Whether to generate a new buffer when jumping to an EWW bookmark. * nil means reuse an existing buffer for the bookmarked URL. * Non-nil means use a new buffer." :type 'boolean :group 'bookmark) (defcustom bmkp-eww-replace-keys-flag t "Non-nil means replace EWW bookmark keys with Emacs bookmark ones. If you change the value of this option then you must restart Emacs for it to take effect." :type 'boolean :group 'bookmark) ;; This is set by `bmkp-eww-rename-buffer', ;; and used in `bmkp-jump-eww' for local var `after-render-function'. (defvar bmkp-eww-new-buf-name nil "If non-nil, the name of the EWW buffer to jump to.") (make-variable-buffer-local 'bmkp-eww-new-buf-name) ;; This is set by `bmkp-jump-eww', ;; and used in `bmkp-eww-rename-buffer'. (defvar bmkp-eww-jumping-p nil "Non-nil only if we are currently jumping to an EWW bookmark.") (make-variable-buffer-local 'bmkp-eww-jumping-p) (defun bmkp-eww-bookmark-p (bookmark) "Return non-nil if BOOKMARK is an EWW bookmark. BOOKMARK is a bookmark name or a bookmark record. If it is a record then it need not belong to `bookmark-alist'." (eq (bookmark-get-handler bookmark) 'bmkp-jump-eww)) (defun bmkp-eww-alist-only () "`bookmark-alist', filtered to retain only EWW bookmarks. A new list is returned (no side effects)." (bookmark-maybe-load-default-file) (cl-remove-if-not #'bmkp-eww-bookmark-p bookmark-alist)) (defun bmkp-eww-title () "Return the web-page title of the current `eww-mode' buffer." (plist-get eww-data :title)) (defun bmkp-eww-url () "Return the URL of the current `eww-mode' buffer." (eww-current-url)) (defun bmkp-make-eww-record () "Make a record for an EWW buffer." `(,(bmkp-eww-title) (buffer-name . ,(bmkp-eww-new-buffer-name)) ,@(bookmark-make-record-default 'NO-FILE) (location . ,(bmkp-eww-url)) (handler . bmkp-jump-eww))) (defun bmkp-eww-new-buffer-name () "Return a new buffer name for the current `eww-mode' buffer. The name format is determined by option `bmkp-eww-buffer-renaming'." (concat "*eww*" (and bmkp-eww-buffer-renaming (concat "-" (bmkp-eww-title) (let ((url (bmkp-eww-url))) (and (eq 'url bmkp-eww-buffer-renaming) (concat " " (if (>= (length url) 20) (substring url -20) url)))))))) (defun bmkp-jump-eww (bookmark) "Handler function for record returned by `bmkp-make-eww-record'. BOOKMARK is a bookmark name or a bookmark record." (require 'eww) (let ((buffer (or (and (not bmkp-eww-generate-buffer-flag) (get-buffer (bookmark-prop-get bookmark 'buffer-name))) (generate-new-buffer "*eww*"))) ; Might get renamed later. ;; `bmkp-eww-new-buf-name' is free here, bound in `bmkp-eww-rename-buffer'. (after-render-function `(lambda () (when (and bmkp-eww-buffer-renaming bmkp-eww-new-buf-name) (kill-buffer) (set-buffer bmkp-eww-new-buf-name)) (bookmark-default-handler `("" (buffer . ,(current-buffer)) . ,(bookmark-get-bookmark-record ,(car bookmark)))) (dolist (var '(bmkp-eww-jumping-p eww-after-render-hook)) (kill-local-variable var))))) (setq bmkp-eww-jumping-p t) (with-current-buffer buffer (eww-mode) (save-window-excursion ; Because `eww' calls `pop-to-buffer-same-window'. (eww (bookmark-location bookmark))) (add-hook 'eww-after-render-hook after-render-function 'APPEND 'LOCAL)))) (defun bmkp-eww-rename-buffer (&rest _ignored) "Rename current buffer according to option `bmkp-eww-buffer-renaming'. When jumping to EWW bookmark with nil `bmkp-eww-generate-buffer-flag', if the buffer has already been visited, set `bmkp-eww-new-buf-name' so that `bmkp-jump-eww' will use the already visited buffer." (when bmkp-eww-buffer-renaming (let ((new-bname (bmkp-eww-new-buffer-name))) (condition-case nil (rename-buffer new-bname) ;; `bmkp-eww-jumping-p' is free here, set in `bmkp-jump-eww'. (error (if (and bmkp-eww-jumping-p (not bmkp-eww-generate-buffer-flag)) ;; Save buf name for `after-render-function' in `bmkp-jump-eww'. (setq bmkp-eww-new-buf-name new-bname) (rename-buffer (generate-new-buffer-name new-bname)))))))) (define-minor-mode bmkp-eww-auto-bookmark-mode "Toggle automatically setting a bookmark when you visit a URL with EWW. The bookmark name is the title of the web page. If option `bmkp-eww-auto-type' is `create-or-update' then such a bookmark is created for the URL if none exists. If the option value is `update-only' then no new bookmark is created automatically, but an existing bookmark is updated. (Updating a bookmark increments the recorded number of visits.) You can toggle the option using `\\[bmkp-toggle-eww-auto-type]'." :init-value nil :global t :group 'bookmark (cond (bmkp-eww-auto-bookmark-mode (add-hook 'eww-after-render-hook 'bmkp-set-eww-bookmark-here) (advice-add 'eww-restore-history :after 'bmkp-set-eww-bookmark-here)) (t (remove-hook 'eww-after-render-hook 'bmkp-set-eww-bookmark-here) (advice-remove 'eww-restore-history 'bmkp-set-eww-bookmark-here))) (when (called-interactively-p 'any) (message "Automatic EWW bookmarking is now %s" (if bmkp-eww-auto-bookmark-mode (if (eq bmkp-eww-auto-type 'update-only) "ON, updating only" "ON, creating or UPDATING") "OFF")))) (defun bmkp-set-eww-bookmark-here (&optional nomsg) "Set an EWW bookmark for the URL of the current EWW buffer. The current buffer is assumed to be in `eww-mode' and visiting a URL." (interactive) (let* ((bname (bmkp-eww-title)) (url (bmkp-eww-url)) (bmk (bookmark-get-bookmark bname 'NO-ERROR)) (visits (and bmk (bookmark-prop-get bmk 'visits)))) (when bname (cond ((and (not visits) (eq bmkp-eww-auto-type 'create-or-update)) (bookmark-set bname) (unless nomsg (message "Created EWW bookmark `%s'" bname))) (visits (bookmark-prop-set bmk 'visits (1+ visits)) (bookmark-prop-set bmk 'time (current-time)) (bookmark-bmenu-surreptitiously-rebuild-list) (unless nomsg (message "Updated EWW bookmark `%s'" bname))))))) (defun bmkp-toggle-eww-auto-type (&optional msgp) "Toggle the value of option `bmkp-eww-auto-type'." (interactive "p") (setq bmkp-eww-auto-type (if (eq bmkp-eww-auto-type 'create-or-update) 'update-only 'create-or-update)) (when msgp (message "`bmkp-eww-auto-bookmark-mode' now %s" (if (eq bmkp-eww-auto-type 'create-or-update) "CREATES, as well as updates, EWW bookmarks" "only UPDATES EXISTING EWW bookmarks")))) ;; You can use this to convert existing EWW bookmarks to Emacs bookmarks. (defun bmkp-convert-eww-bookmarks (eww-file bmk-file &optional msgp) "Add bookmarks from EWW-FILE to BMK-FILE. EWW-FILE is a file of \"bookmarks\" created by EWW, which are not compatible with Emacs bookmarks. EWW-FILE is not modified. BMK-FILE is an Emacs bookmarks file. If BMK-FILE exists then it is updated to include the converted bookmarks. If it does not exist then it is created." (interactive (let ((default bookmark-default-file)) (list (expand-file-name (read-file-name "EWW \"bookmarks\" file: " nil (expand-file-name "eww-bookmarks" user-emacs-directory) t)) (expand-file-name (read-file-name "Emacs bookmark file: " (or (file-name-directory default) "~/") bookmark-default-file)) t))) (when (file-directory-p eww-file) (error "`%s' is a directory, not a file" eww-file)) (unless (file-readable-p eww-file) (error "Cannot read bookmark file `%s'" eww-file)) (when (file-directory-p bmk-file) (error "`%s' is a directory, not a file" bmk-file)) (unless (file-readable-p bmk-file) ; Create empty bookmark file. (setq bmk-file (expand-file-name bmk-file)) (bookmark-maybe-load-default-file) (let ((bookmark-alist ())) (bookmark-write-file bmk-file))) (with-temp-buffer (insert-file-contents eww-file) (let ((bookmark-alist ()) url title created bmk) (dolist (ebmk (read (current-buffer))) (setq url (plist-get ebmk :url) title (plist-get ebmk :title) created (date-to-time (plist-get ebmk :time)) bmk `(,title ,@(bookmark-make-record-default 'NO-FILE) (location . ,url) (handler . bmkp-jump-eww))) (let ((buf-cell (assq 'buffer-name bmk))) (setcdr buf-cell "*eww*")) (let ((created-cell (assq 'created bmk))) (setcdr created-cell created)) (push bmk bookmark-alist)) (bookmark-write-file bmk-file))) (when msgp (message "Wrote Bookmark file `%s'" bmk-file))) (defun bmkp-eww-jump (bookmark-name) "Jump to an EWW bookmark." (interactive (let ((bookmark-alist (bmkp-eww-alist-only))) (list (bookmark-completing-read "Jump to EWW bookmark: ")))) (bookmark--jump-via bookmark-name 'pop-to-buffer-same-window)) (defun bmkp-eww-jump-other-window (bookmark-name) "Jump to an EWW bookmark in another window." (interactive (let ((bookmark-alist (bmkp-eww-alist-only))) (list (bookmark-completing-read "Jump to EWW bookmark: ")))) (bookmark--jump-via bookmark-name (lambda (buf) (pop-to-buffer buf t)))) ;; Non-nil `bmkp-eww-buffer-renaming' means EWW buffer is renamed on each visit. (eval-after-load "eww" '(progn (add-hook 'eww-after-render-hook 'bmkp-eww-rename-buffer) (advice-add 'eww-restore-history :after 'bmkp-eww-rename-buffer) (add-hook 'eww-mode-hook (lambda () (setq-local bookmark-make-record-function 'bmkp-make-eww-record) (unless (lookup-key eww-mode-map "j") (define-key eww-mode-map "j" 'bmkp-eww-jump)))) (when bmkp-eww-replace-keys-flag (define-key eww-mode-map [remap eww-add-bookmark] 'bookmark-set) (define-key eww-mode-map [remap eww-list-bookmarks] 'bookmark-bmenu-list)))) ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-25 21:48 ` Bookmarks in EWW Drew Adams @ 2020-03-26 2:29 ` Michael Heerdegen 2020-03-26 3:21 ` Drew Adams 2020-03-26 8:41 ` Marcin Borkowski 0 siblings, 2 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-03-26 2:29 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs, Stefan Monnier Drew Adams <drew.adams@oracle.com> writes: > Attached is something I threw together, by removing some > of the Bookmark+ features for EWW and adapting the code > to what vanilla bookmark.el offers. Completely untested; > as is. Perhaps you can make some use of it. Thanks, Drew. Seems your approach is similar but more feature rich. Most features are too much (I guess) for vanilla Emacs in the sense that Emacs bookmarks don't support them in other implementations. The most basic and interesting feature in my eyes is the code that controls whether the bookmarks opens in a new session (and how the buffer is named). Unfortunately it seems eww still hasn't factored the "open in a new session" code out of the command that follows links, so one can only use a hack to control the behavior. Marcin, how do you think about the features of Drew's code? Is there one you definitely want to have in any case? Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: Bookmarks in EWW 2020-03-26 2:29 ` Michael Heerdegen @ 2020-03-26 3:21 ` Drew Adams 2020-03-26 3:53 ` Michael Heerdegen 2020-03-26 8:41 ` Marcin Borkowski 1 sibling, 1 reply; 39+ messages in thread From: Drew Adams @ 2020-03-26 3:21 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs, Stefan Monnier Thanks for taking a look, Michael. I think it could help, but it might need some tweaking. > Most features are too much (I guess) for vanilla Emacs in the sense > that Emacs bookmarks don't support them in other implementations. Sorry, but I don't understand that part. What did you mean by: "Emacs bookmarks don't support them in other implementations"? I tried to remove anything that I thought wouldn't work with vanilla Emacs. But I may have forgotten, and left something in that doesn't belong. As I said, untested. What, in particular, do you think wouldn't be supported, and what do you mean by "other implementations"? ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-26 3:21 ` Drew Adams @ 2020-03-26 3:53 ` Michael Heerdegen 2020-03-26 14:02 ` Drew Adams 0 siblings, 1 reply; 39+ messages in thread From: Michael Heerdegen @ 2020-03-26 3:53 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs, Stefan Monnier Drew Adams <drew.adams@oracle.com> writes: > What, in particular, do you think wouldn't be supported, and > what do you mean by "other implementations"? You misunderstood my (probably again very poorly formulated) sentence. I meant the other locations where a special `bookmark-make-record-function' is implemented, e.g. "doc-view". I only had a quick look but most places don't care the features your code provides. I didn't want to say your code would not work, I also didn't want to say that those features aren't useful. But if we add them, we should add them in a uniform way for all implementations of `bookmark-make-record-function', not only for eww. This is something I don't want to do. Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* RE: Bookmarks in EWW 2020-03-26 3:53 ` Michael Heerdegen @ 2020-03-26 14:02 ` Drew Adams 2020-03-26 22:33 ` Michael Heerdegen 0 siblings, 1 reply; 39+ messages in thread From: Drew Adams @ 2020-03-26 14:02 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs, Stefan Monnier > I meant the other locations where a special > `bookmark-make-record-function' is implemented, e.g. "doc-view". I > only had a quick look but most places don't care the features your code > provides. I didn't want to say your code would not work, I also didn't > want to say that those features aren't useful. But if we add them, we > should add them in a uniform way for all implementations of > `bookmark-make-record-function', not only for eww. This is something I > don't want to do. FWIW - The stuff that's in that make-record function is only for EWW. In Bookmark+, the make-record functions for other kinds of bookmarks don't have such things. They're specifically about renaming the EWW buffer, etc. So no, I don't think such things apply "in a uniform way for all implementations" of a make-record function. They're only for EWW. (BTW, there's nothing about "sessions" in the Bookmark+ code, AFAIK; I haven't understood that part either, of your and Marcin's messages.) There is an Emacs Dev thread about this stuff. See https://lists.gnu.org/archive/html/emacs-devel/2018-04/msg00622.html Note that that thread was started by someone requesting to be able to do, for EWW, some of the kinds of things that Bookmark+ offers. And this part of that thread speaks to the use of EWW "bookmarks" versus regular bookmarks, and to the use of different make-record functions for different kinds of bookmarks: https://lists.gnu.org/archive/html/emacs-devel/2018-04/msg00660.html 'Nuff said. I'm not pushing anyone to use code similar to what I offered. My point is that those particular features were added specifically for use with EWW - they're not Bookmark+ features used for any other kinds of bookmarks. The latter kind of feature I didn't provide the code for here, though such things (e.g. tags) were requested in the original Emacs Dev thread. I didn't provide them in the code I offered here because they do require more of Bookmark+. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-26 14:02 ` Drew Adams @ 2020-03-26 22:33 ` Michael Heerdegen 0 siblings, 0 replies; 39+ messages in thread From: Michael Heerdegen @ 2020-03-26 22:33 UTC (permalink / raw) To: Drew Adams; +Cc: help-gnu-emacs, Stefan Monnier Drew Adams <drew.adams@oracle.com> writes: > So no, I don't think such things apply "in a uniform way for > all implementations" of a make-record function. They're only > for EWW. Ok, noted ;-) > (BTW, there's nothing about "sessions" in the Bookmark+ code, > AFAIK; I haven't understood that part either, of your and > Marcin's messages.) A session in a browser is a page loaded in some tab or window, at least it's the term used in w3m and eww AFAIK. If you open a link or a different page in a different buffer, leaving the old buffer untouched, you open it in a new session. > 'Nuff said. I'm not pushing anyone to use code similar to what > I offered. My point is that those particular features were > added specifically for use with EWW - they're not Bookmark+ > features used for any other kinds of bookmarks. Ok, all is well. For my part, I don't doubt the usefulness of what you suggest, I just don't have the time to create a bigger patch because I just stumbled in here too... so I want to offer a minimum of features for now, anyone can extend it later. Michael. ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-26 2:29 ` Michael Heerdegen 2020-03-26 3:21 ` Drew Adams @ 2020-03-26 8:41 ` Marcin Borkowski 1 sibling, 0 replies; 39+ messages in thread From: Marcin Borkowski @ 2020-03-26 8:41 UTC (permalink / raw) To: Michael Heerdegen; +Cc: help-gnu-emacs, Stefan Monnier On 2020-03-26, at 03:29, Michael Heerdegen <michael_heerdegen@web.de> wrote: > Drew Adams <drew.adams@oracle.com> writes: > >> Attached is something I threw together, by removing some >> of the Bookmark+ features for EWW and adapting the code >> to what vanilla bookmark.el offers. Completely untested; >> as is. Perhaps you can make some use of it. > > Thanks, Drew. Seems your approach is similar but more feature rich. > > Most features are too much (I guess) for vanilla Emacs in the sense that > Emacs bookmarks don't support them in other implementations. The most > basic and interesting feature in my eyes is the code that controls > whether the bookmarks opens in a new session (and how the buffer is > named). Unfortunately it seems eww still hasn't factored the "open in a > new session" code out of the command that follows links, so one can only > use a hack to control the behavior. > > Marcin, how do you think about the features of Drew's code? Is there > one you definitely want to have in any case? Well, I looked through the list, and frankly, I don't care about most of them. My needs are *very* simple - I just want to tell Emacs "save the currently visited URL as a bookmark under name such-and-such". But I can see how other people might need at least some of them, e.g. controlling whether Emacs should open a new eww session when jumping to a bookmark or not (I rarely use eww, basically only for a few cases, so I don't care about multiple eww buffers). Thanks for working on this, -- Marcin Borkowski http://mbork.pl ^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: Bookmarks in EWW 2020-03-23 20:41 ` Michael Heerdegen 2020-03-24 14:46 ` Stefan Monnier @ 2020-03-25 11:49 ` Marcin Borkowski 1 sibling, 0 replies; 39+ messages in thread From: Marcin Borkowski @ 2020-03-25 11:49 UTC (permalink / raw) To: Michael Heerdegen; +Cc: Help Gnu Emacs mailing list On 2020-03-23, at 21:41, Michael Heerdegen <michael_heerdegen@web.de> wrote: > Marcin Borkowski <mbork@mbork.pl> writes: > >> Hi all, >> >> I have just noticed that Emacs bookmarks do not work in EWW (which has >> its own bookmarks). Is there a way to use Emacs bookmarks with EWW >> (other than bookmark+, which is too heavy for me)? > > Seems like `bookmark-make-record-function' is there to implement things > like this. Several Emacs modes use it to provide bookmarks (Info, > doc-view, etc). Haven't tried but looks promising. Bookmarks can have > a `handler' field to implement non-standard behavior. Your > `bookmark-make-record-function' should return an according record using > an eww handler you want to write. Look how the other modes do it. Thanks. I've seen that you managed to convert this suggestion into a prototype before I replied to your email... Thanks again for that, too! I hope to have this feature soon on master - I use bookmarks heavily for many things (files, local and remote directories), and online docs in eww would be a natural thing for me. Best, -- Marcin Borkowski http://mbork.pl ^ permalink raw reply [flat|nested] 39+ messages in thread
end of thread, other threads:[~2020-04-30 20:09 UTC | newest] Thread overview: 39+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-03-23 11:26 Bookmarks in EWW Marcin Borkowski 2020-03-23 14:56 ` Drew Adams 2020-03-25 11:48 ` Marcin Borkowski 2020-03-23 20:41 ` Michael Heerdegen 2020-03-24 14:46 ` Stefan Monnier 2020-03-25 3:05 ` Michael Heerdegen 2020-03-25 3:45 ` `declare-function' docu (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-28 17:59 ` `declare-function' docu Bruno Félix Rezende Ribeiro 2020-03-28 18:38 ` Drew Adams 2020-04-09 12:30 ` Bruno Félix Rezende Ribeiro 2020-04-09 15:47 ` Drew Adams 2020-03-28 21:38 ` Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-25 14:06 ` Bookmarks in EWW Stefan Monnier 2020-03-26 1:09 ` Michael Heerdegen 2020-03-26 4:07 ` Stefan Monnier 2020-03-27 2:07 ` Michael Heerdegen 2020-03-27 3:44 ` Stefan Monnier 2020-03-28 2:31 ` Michael Heerdegen 2020-03-28 2:55 ` Stefan Monnier 2020-04-19 3:42 ` Michael Heerdegen 2020-04-19 13:18 ` Stefan Monnier 2020-04-20 3:17 ` Michael Heerdegen 2020-04-20 13:24 ` Stefan Monnier 2020-04-21 0:59 ` Michael Heerdegen 2020-04-29 22:53 ` Michael Heerdegen 2020-04-30 1:25 ` Stefan Monnier 2020-04-30 2:08 ` Michael Heerdegen 2020-04-30 3:08 ` Stefan Monnier 2020-04-30 20:09 ` Michael Heerdegen 2020-04-27 2:43 ` Michael Heerdegen 2020-03-27 4:32 ` buffer-localness (was: Re: Bookmarks in EWW) Emanuel Berg via Users list for the GNU Emacs text editor 2020-03-25 21:48 ` Bookmarks in EWW Drew Adams 2020-03-26 2:29 ` Michael Heerdegen 2020-03-26 3:21 ` Drew Adams 2020-03-26 3:53 ` Michael Heerdegen 2020-03-26 14:02 ` Drew Adams 2020-03-26 22:33 ` Michael Heerdegen 2020-03-26 8:41 ` Marcin Borkowski 2020-03-25 11:49 ` Marcin Borkowski
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.