Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request : eww bookmark integration #347

Closed
rileyrg opened this issue Jun 30, 2021 · 12 comments
Closed

Feature request : eww bookmark integration #347

rileyrg opened this issue Jun 30, 2021 · 12 comments
Labels
feature New feature or request

Comments

@rileyrg
Copy link

rileyrg commented Jun 30, 2021

I pretty much use consult-buffer for all "switch" actions ;) bookmark+ is way too big for me to just integrate eww bookmarks into consult-buffer. Any chance of it coming out of the box? The recent package devdocs https://github.com/skeeto/devdocs-lookup has me using eww a lot more to browse APIs etc.

cheers.

@minad
Copy link
Owner

minad commented Jun 30, 2021

Of course, it should be possible to write an eww bookmark source (see multi sources). It is a bit unfortunate that eww does not make use of the standard bookmark facilities by default. The eww source should then be documented in the wiki. We may also consider to add this ootb. Unfortunately adding such an eww source ootb to the list of buffer sources will force loading eww in any case when consult-buffer is invoked, which may not be desired by all users.

[[ Unrelated - there seems to be also https://github.com/astoff/devdocs.el - how is this different? cc @astoff ]]

@astoff
Copy link
Contributor

astoff commented Jun 30, 2021

My devdocs.el package (which is new) doesn't use eww at all (it only uses the underlying HTML rendering engine, shr.el). The mentioned package, https://github.com/skeeto/devdocs-lookup in fact uses a browser (possibly eww), but it's not recent.

I don't see how devdocs.el would benefit from any sort of bookmarking, since looking up the bookmark seems to be as much work as searching directly for whatever you need.

@minad
Copy link
Owner

minad commented Jun 30, 2021

I don't see how devdocs.el would benefit from any sort of bookmarking, since looking up the bookmark seems to be as much work as searching directly for whatever you need.

Right. That's a good point. However supporting eww bookmarks in Consult still makes sense.

@rileyrg
Copy link
Author

rileyrg commented Jun 30, 2021

@astoff bookmarks exist for a reason. So you don't need to search. I type in "lldb" in my consult-buffer and I see it.. Done. And I'm not talking about devdocs specifically... Any eww bookmarks. Its very convenient to use an in emacs text browser.

@rileyrg
Copy link
Author

rileyrg commented Jun 30, 2021

I don't see how devdocs.el would benefit from any sort of bookmarking, since looking up the bookmark seems to be as much work as searching directly for whatever you need.

Right. That's a good point. However supporting eww bookmarks in Consult still makes sense.

Its a lot more work. devdocs works on a per mode basis for a start (or mine does). And opening up devdocs, searching for a term, getting a myriad of results back and then determining which one it is, is a lot more effort, and less logical, than just jumping to my bookmark "lldb scripting" for example. But as I mentioned before, its not about devdocs, more about eww in general.

@minad
Copy link
Owner

minad commented Jun 30, 2021

Its a lot more work. devdocs works on a per mode basis for a start (or mine does). And opening up devdocs, searching for a term, getting a myriad of results back and then determining which one it is, is a lot more effort, and less logical, than just jumping to my bookmark "lldb scripting" for example.

I don't believe it is signficantly more work. Vertico/Selectrum sort by history for completing-read. This means if you have looked up a function once it will be quickly accessible again. Bookmarks are of course are of course useful to keep things accessible for longer. You may still want to give devdocs.el a try. @astoff I think there exist at least three devdocs emacs packages now? You may want to mention these as alternatives in your README with a brief comparison.

@rileyrg
Copy link
Author

rileyrg commented Jun 30, 2021

@minad I think we're sidetracked. It's not about devdocs (I linked the one I use). It's simply eww bookmarks. I'm talking from anywhere. I mentioned eww use only in the context that I use it for devdocs too :) and in addition using bookmarks from the all powerful consult-buffer "unified switcher". Hopefully that's clarified it a little.

@minad
Copy link
Owner

minad commented Jun 30, 2021

@rileyrg No worries. I am aware of what this issue is about. I've already said it is possible - you can add the eww source to the wiki and we may even add it to consult ootb. However there is the issue that this will force loading eww which is undesired.

@astoff
Copy link
Contributor

astoff commented Jun 30, 2021

I think there exist at least three devdocs emacs packages now? You may want to mention these as alternatives in your README with a brief comparison.

I guess this makes sense, yes.

@astoff bookmarks exist for a reason. So you don't need to search. I type in "lldb" in my consult-buffer and I see it.. Done. And I'm not talking about devdocs specifically...

Of course, a completing-read interface for EWW bookmarks makes a lot of sense. Now, concerning devdocs specifically, I believe the devdocs.el package is more efficient than the workflow you described above; I know you're not asking for advice, but you might want to check it out :-).

@minad minad added the feature New feature or request label Jun 30, 2021
@minad
Copy link
Owner

minad commented Jul 1, 2021

What about using normal Emacs bookmarks for eww too? The missing integration is pretty easy to write as you see in the snippet below. I assume bookmark+ contains something like this. I don't really see a point in eww-specific bookmarks honestly.

(require 'bookmark)
(require 'eww)

(defun bookmark-eww--make ()
  "Make eww bookmark record."
  `((filename . ,(plist-get eww-data :url))
    (title . ,(plist-get eww-data :title))
    (time . ,(current-time-string))
    (handler . ,#'bookmark-eww-handler)
    (defaults . (,(concat
                   ;; url without the https and path
                   (replace-regexp-in-string
                    "/.*" ""
                    (replace-regexp-in-string
                     "\\`https?://" ""
                     (plist-get eww-data :url)))
                   " - "
                   ;; page title
                   (replace-regexp-in-string
                    "\\` +\\| +\\'" ""
                    (replace-regexp-in-string
                     "[\n\t\r ]+" " "
		     (plist-get eww-data :title))))))))

(defun bookmark-eww-handler (bm)
  "Handler for eww bookmarks."
  (eww-browse-url (alist-get 'filename bm)))

(defun bookmark-eww--setup ()
  "Setup eww bookmark integration."
  (setq-local bookmark-make-record-function #'bookmark-eww--make))

(add-hook 'eww-mode-hook #'bookmark-eww--setup)
(define-key eww-mode-map "b" #'bookmark-set)
(define-key eww-mode-map "B" #'bookmark-jump)
(define-key eww-mode-map (kbd "M-n") nil)
(define-key eww-mode-map (kbd "M-p") nil)

@hmelman
Copy link

hmelman commented Jul 2, 2021

I don't know what the current state is, but there has been recent discussion of eww using standard bookmarks. https://lists.gnu.org/archive/html/emacs-devel/2020-10/msg01651.html

@minad
Copy link
Owner

minad commented Jul 4, 2021

I consider Eww bookmarks to be a legacy feature. Therefore I have no intention to add Eww bookmark support out of the box to Consult. Hopefully Eww pages can be bookmarked using standard Emacs bookmarks at some point. For now Eww bookmarks can be used with Consult as follows:

(require 'eww)

(defvar consult--source-eww
  (list
   :name     "Eww"
   :narrow   ?e
   :action   (lambda (bm)
               (eww-browse-url (get-text-property 0 'url bm)))
   :items    (lambda ()
               (eww-read-bookmarks)
               (mapcar (lambda (bm)
                         (propertize
                          (format "%s (%s)"
                                  (plist-get bm :url)
                                  (plist-get bm :title))
                          'url (plist-get bm :url)))
                       eww-bookmarks))))

(add-to-list 'consult-buffer-sources 'consult--source-eww 'append)

I've documented the eww bookmark source in the wiki: https://github.com/minad/consult/wiki#eww-bookmarks

@minad minad closed this as completed Jul 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants