qrencode-el icon indicating copy to clipboard operation
qrencode-el copied to clipboard

qrencode-url-at-point doesn't recognise org links

Open artelse opened this issue 1 year ago • 2 comments

When the point is on a collapsed or toggled org link, it won't recognise the url. Looked at the code and function thing-at-point-url-at-point seem not targeting org links. Noticed also that the function qrencode-url-at-point is also missing a closing parenthesis.

artelse avatar Jul 13 '24 15:07 artelse

What are org links? But yeah, the function uses thing-at-point-url-at-point which is part of the Emacs standard library (thingatpt.el). If you want support for different types of URLs the best place would be to start fixing it there.

What do you mean there is a missing closing parenthesis? All the parenthesis seem balanced otherwise the tests shouldn't succeed.

ruediger avatar Jul 27 '24 16:07 ruediger

Lame contribution, but gpt spits out this code which works fine for me:

(defun qrencode-url-at-point ()
  "Encode any URL found at point into a QR code.
First, try to get a standard URL at the point. If not found,
try to get an Org link URL. If either is found, encode it into a QR code."
  (interactive)
  (let ((url (or (thing-at-point-url-at-point)
                 (let* ((element (org-element-context))
                        (type (org-element-type element)))
                   (if (eq type 'link)
                       (org-element-property :raw-link element)
                     nil)))))
    (if url
        (progn
          (message "Encoding URL: %s" url)
          (qrencode--encode-to-buffer url))
      (message "No URL found at point"))))

p.s.: that missing parenthesis turned out to be in my code.

artelse avatar Jul 27 '24 19:07 artelse