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

fetch link at point #50

Open
mooseyboots opened this issue Mar 22, 2022 · 2 comments
Open

fetch link at point #50

mooseyboots opened this issue Mar 22, 2022 · 2 comments
Assignees
Milestone

Comments

@mooseyboots
Copy link

mooseyboots commented Mar 22, 2022

i thought to add this to org-web-tools, in order to say, run org-web-tools-read-url-as-org on a link in an elfeed entry or in eww, or on also an org link:

(defun org-web-tools--get-first-url ()
  "Return (shr) URL or org link URL at point, or URL in clipboard, or first URL in the `kill-ring', or nil if none."
  (or (shr-url-at-point nil) ; elfeed or eww links
      (plist-get (get-text-property (point) 'htmlize-link) :uri) ; org links
      (cl-loop for item in (append (list (gui-get-selection 'CLIPBOARD))
                                   kill-ring)
               when (and item (string-match (rx bol "http" (optional "s") "://") item))
               return item)))

could poss add some others, could poss find more rigorous way of fetching them...

@alphapapa
Copy link
Owner

That would more idiomatically belong in the org-web-tools-read-url-as-org function's interactive form. But it would seem to be a matter of preference, because some users might want the command to ignore any links at point.

@mooseyboots
Copy link
Author

mooseyboots commented Mar 27, 2022

@alphapapa thanks for the hint.

i came up with this:

(defcustom org-web-tools-use-link-at-point nil
  "Whether `org-web-tools' should operate on the link at point."
    :type 'boolean)

(cl-defun org-web-tools-read-url-as-org (url &key (show-buffer-fn #'switch-to-buffer))
  "Read URL's readable content in an Org buffer.
Buffer is displayed using SHOW-BUFFER-FN."
  (interactive
   (list
    (if org-web-tools-use-link-at-point
        (or
         ;; shr link (modified from `elfeed-get-link-at-point'):
         (or (shr-url-at-point nil)
             (and (fboundp 'eww-current-url)
                  (funcall 'eww-current-url))
             (get-text-property (point) :nt-link))
         ;; org link:
         (plist-get (get-text-property (point) 'htmlize-link) :uri)
         ;; plain URL (from `elfeed-get-url-at-point'):
         (or (if (fboundp 'thing-at-point-url-at-point)
                    (thing-at-point-url-at-point)
                  (with-no-warnings (url-get-url-at-point)))
             (thing-at-point 'url))
         ;; kill ring as per usual:
         (org-web-tools--get-first-url))
      (org-web-tools--get-first-url))))
  (let ((entry (org-web-tools--url-as-readable-org url)))
    (when entry
      (funcall show-buffer-fn url)
      (org-mode)
      (insert entry)
      ;; Set buffer title
      (goto-char (point-min))
      (rename-buffer (cdr (org-web-tools--read-org-bracket-link))))))

@alphapapa alphapapa self-assigned this Jun 17, 2022
@alphapapa alphapapa added this to the 1.4 milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants