* [BUG] org-context called from link in org-agenda entry returns wrong values [9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)]
@ 2021-10-06 9:44 Harald Judt
2021-10-07 4:10 ` Ihor Radchenko
0 siblings, 1 reply; 3+ messages in thread
From: Harald Judt @ 2021-10-06 9:44 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1.1: Type: text/plain, Size: 10604 bytes --]
Hi,
I am using this function to copy links from the agenda to the clipboard:
(defun my-copy-org-url ()
(interactive)
(let* ((link-info (assoc :link (org-context)))
(text (when link-info
(buffer-substring-no-properties
(or (cadr link-info) (point-min))
(or (caddr link-info) (point-max))))))
(if (not text)
(error "Point not in an org link.")
(string-match org-bracket-link-regexp text)
(kill-new (url-encode-url (substring text (match-beginning 1)
(match-end 1))))
(message "Org link URL copied to clipboard."))))
This indeed worked fine with previous versions of org, but recently started
to fail to extract the link. Example entry to put into your agenda
to test this:
* TODO Header with [[https://orgmode.org/][Link]]
SCHEDULED: <2021-10-06 Mi 12:00>
Now the function above should extract "https://orgmode.org/", but
instead the text extracted is "Lin".
Stepping through the function with edefun-debug tells me that
org-context returns the wrong values ((:link begin end)).
Note that the function seems to work fine if I call it from a normal
org file (not from the agenda) interactively, and I get ((:item i j)
(:link x y)) with the correct link.
(Note in the following section I have edited some paths and the list of my org
files for privacy reasons, but that shouldn't be relevant to this issue.)
Emacs : GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.29,
cairo version 1.16.0)
of 2021-09-27
Package: Org mode version 9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)
current state:
==============
(setq
org-roam-db-location "~/.cache/emacs/org-roam.db"
org-src-mode-hook '(org-src-babel-configure-edit-buffer
org-src-mode-configure-edit-buffer)
org-capture-prepare-finalize-hook '(org-roam-capture--install-finalize-h)
org-link-shell-confirm-function 'yes-or-no-p
org-metadown-hook '(org-babel-pop-to-session-maybe)
org-roam-db-node-include-function '(closure (t) nil t)
org-refile-targets '((org-agenda-files :maxlevel . 2))
org-table-convert-region-max-lines 2000
org-roam-mode-hook '(org-roam-bibtex-mode)
org-roam-bibtex-mode t
org-agenda-files '("snip.org")
org-reveal-start-hook '(org-decrypt-entry)
org-archive-location "~/work/org/archive/%s_archive::"
org-mode-hook '(org-bullets-mode org-clock-load
(lambda nil (add-hook 'before-save-hook
'my-org-add-ids-to-headlines-in-file nil 'local))
#[0 "\300\301\302\303\304$\207" [add-hook
change-major-mode-hook org-show-all append local] 5]
#[0 "\300\301\302\303\304$\207"
[add-hook change-major-mode-hook org-babel-show-result-all
append local] 5]
org-babel-result-hide-spec org-babel-hide-all-hashes
#[0 "\301\211\x10\207" [imenu-create-index-function
org-imenu-get-tree] 2] whitespace-mode
yas-minor-mode)
org-clock-persist 'history
org-archive-hook '(org-attach-archive-delete-maybe)
org-roam-capture-new-node-hook '(orb--insert-captured-ref-h)
org-confirm-elisp-link-function 'yes-or-no-p
org-journal-mode-hook '((closure
(org-journal-search-mode-abbrev-table
org-journal-search-mode-syntax-table
org-journal-mode-abbrev-table
org-journal-mode-syntax-table view-exit-action t)
nil (add-hook org-journal-encrypt-on
'org-journal-encryption-hook nil t))
(lambda nil (add-hook org-journal-encrypt-on
'org-journal-encryption-hook nil t)))
org-agenda-before-write-hook '(org-agenda-add-entry-text)
org-metaup-hook '(org-babel-load-in-session-maybe)
org-bibtex-headline-format-function #[257 "\300\x01\236A\207" [:title] 3
"\n\n(fn ENTRY)"]
org-log-reschedule 'note
org-babel-pre-tangle-hook '(save-buffer)
org-tab-first-hook '(org-babel-hide-result-toggle-maybe
org-babel-header-arg-expand)
org-babel-load-languages '((emacs-lisp . t) (shell . t) (python . t) (sed .
t) (awk . t) (sql . t) (ditaa . t))
org-log-done 'time
org-journal-date-format "%Y-%m-%d %A"
org-agenda-span 'fortnight
org-agenda-loop-over-headlines-in-active-region nil
org-roam-find-file-hook '(org-roam-buffer--setup-redisplay-h
org-roam--register-completion-functions-h
org-roam--replace-roam-links-on-save-h
org-roam-open-id-with-org-roam-db-h
org-roam-db-autosync--setup-update-on-save-h)
org-catch-invisible-edits t
org-occur-hook '(org-first-headline-recenter)
org-log-into-drawer t
org-ditaa-jar-path "/usr/share/ditaa/lib/ditaa.jar"
org-ref-bibtex-assoc-pdf-with-entry-move-function 'rename-file
org-agenda-include-diary t
org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers
org-cycle-show-empty-lines
org-optimize-window-after-visibility-change)
org-speed-command-hook '(org-speed-command-activate
org-babel-speed-command-activate)
org-roam-node-annotation-function 'org-roam-node-read--annotation
org-clock-persist-file "~/.cache/emacs/org-clock-save.el"
org-roam-ui-browser-function 'browse-url
org-roam-ref-annotation-function 'org-roam-ref-read--annotation
org-journal-dir "~/work/org/journal"
org-babel-tangle-lang-exts '(("awk" . "awk") ("sed" . "sed") ("python" .
"py") ("emacs-lisp" . "el")
("elisp" . "el"))
org-ref-pdf-to-bibtex-function 'copy-file
org-refile-allow-creating-parent-nodes 'confirm
org-export-before-parsing-hook '(org-attach-expand-links)
org-journal-created-property-timestamp-format "%Y-%m-%d"
org-id-locations-file "~/.cache/emacs/.org-id-locations"
org-capture-use-agenda-date t
org-confirm-shell-link-function 'yes-or-no-p
org-link-parameters '(("attachment" :follow org-attach-follow :complete
org-attach-complete-link)
("roam" :follow org-roam-link-follow-link) ("id"
:follow org-id-open)
("eww" :follow org-eww-open :store org-eww-store-link)
("rmail" :follow org-rmail-open :store
org-rmail-store-link)
("mhe" :follow org-mhe-open :store org-mhe-store-link)
("irc" :follow org-irc-visit :store org-irc-store-link
:export org-irc-export)
("info" :follow org-info-open :export org-info-export
:store org-info-store-link)
("gnus" :follow org-gnus-open :store org-gnus-store-link)
("docview" :follow org-docview-open :export
org-docview-export :store org-docview-store-link)
("bbdb" :follow org-bbdb-open :export org-bbdb-export
:complete org-bbdb-complete-link
:store org-bbdb-store-link)
("w3m" :store org-w3m-store-link)
("nov" :follow nov-org-link-follow :store
nov-org-link-store)
("doi" :follow org-link-doi-open :export
org-link-doi-export)
("bibtex" :follow org-bibtex-open :store
org-bibtex-store-link)
("treemacs" :store treemacs-store-org-link)
("file+sys") ("file+emacs")
("shell" :follow org-link--open-shell)
("news" :follow
#[514 "\301\300\302\x04Q\x02\"\207" ["news" browse-url ":"]
6 "\n\n(fn URL ARG)"])
("mailto" :follow
#[514 "\301\300\302\x04Q\x02\"\207" ["mailto" browse-url
":"] 6 "\n\n(fn URL ARG)"])
("https" :follow
#[514 "\301\300\302\x04Q\x02\"\207" ["https" browse-url
":"] 6 "\n\n(fn URL ARG)"])
("http" :follow
#[514 "\301\300\302\x04Q\x02\"\207" ["http" browse-url ":"]
6 "\n\n(fn URL ARG)"])
("ftp" :follow #[514 "\301\300\302\x04Q\x02\"\207" ["ftp"
browse-url ":"] 6 "\n\n(fn URL ARG)"])
("help" :follow org-link--open-help :store
org-link--store-help)
("file" :complete org-link-complete-file) ("elisp"
:follow org-link--open-elisp))
org-capture-templates '(("p" "Private templates")
("pt" "TODO entry" entry (file+headline
"~/work/org/home.org" "Inbox")
(file "~/work/org/templates/private/todo.org")
:empty-lines-before 1)
("pd" "Daily plan entry" plain (file+olp+datetree
"~/work/org/plan-home.org")
(file
"~/work/org/templates/private/plan-entry.org") :empty-lines 0 :immediate-finish t
:jump-to-captured t :time-prompt t)
)
org-link-elisp-confirm-function 'yes-or-no-p
org-roam-db-autosync-mode t
org-capture-after-finalize-hook '(orb-make-notes-cache)
org-clock-into-drawer "CLOCKING"
org-roam-directory "~/work/org/roam/"
org-journal-file-format "%Y-%m-%d.org"
org-ditaa-eps-jar-path "/home/.emacs.d/elpa/contrib/scripts/DitaaEps.jar"
org-confirm-babel-evaluate nil
org-agenda-custom-commands '(("n" "Agenda and all TODOs" ((agenda "" nil)
(alltodo "" nil)) nil)
("r" "Agenda and all TODOs without recurring tasks"
((agenda ""
((org-agenda-overriding-header "Agenda
without recurring tasks")
(org-agenda-include-diary nil)
(org-agenda-files
'("snip.org"))
)
)
(alltodo "" nil))
nil)
("w" "Agenda and all TODOs (work-related only)"
agenda ""
((org-agenda-overriding-header "Work Agenda
and work-related TODOs ")
(org-agenda-include-diary t)
(org-agenda-tag-filter-preset '("-home")))
)
)
org-ref-notes-function 'orb-org-ref-edit-note
)
Best regards,
Harald
--
`Experience is the best teacher.'
PGP Key ID: 4FFFAB21B8580ABD
Fingerprint: E073 6DD8 FF40 9CF2 0665 11D4 4FFF AB21 B858 0ABD
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 659 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] org-context called from link in org-agenda entry returns wrong values [9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)]
2021-10-06 9:44 [BUG] org-context called from link in org-agenda entry returns wrong values [9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)] Harald Judt
@ 2021-10-07 4:10 ` Ihor Radchenko
2021-10-08 11:38 ` Harald Judt
0 siblings, 1 reply; 3+ messages in thread
From: Ihor Radchenko @ 2021-10-07 4:10 UTC (permalink / raw)
To: Harald Judt; +Cc: emacs-orgmode
Harald Judt <h.judt@gmx.at> writes:
> Hi,
>
> I am using this function to copy links from the agenda to the clipboard:
>
> (defun my-copy-org-url ()
> (interactive)
> (let* ((link-info (assoc :link (org-context)))
> ...
org-context is ancient. It relies on org-links being fontified using
'org-link face and would fail for any non-standard link with :face link
parameter. Moreover, the return value will be different depending on
org-link-descriptive setting.
We should probably deprecate this function and encourage using
org-element-context. So, I recommend rewriting your code with
org-element-context.
> This indeed worked fine with previous versions of org, but recently started
> to fail to extract the link. Example entry to put into your agenda
> to test this:
>
> * TODO Header with [[https://orgmode.org/][Link]]
> SCHEDULED: <2021-10-06 Mi 12:00>
>
> Now the function above should extract "https://orgmode.org/", but
> instead the text extracted is "Lin".
It seems that some of the faces were not applied together, making
next-single-property change stop early because faces are not 'eq (though
'equal). Not sure if we really need to do anything about it. It is a bad
idea to rely on next/prev-property-change in org-context anyway.
Best,
Ihor
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [BUG] org-context called from link in org-agenda entry returns wrong values [9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)]
2021-10-07 4:10 ` Ihor Radchenko
@ 2021-10-08 11:38 ` Harald Judt
0 siblings, 0 replies; 3+ messages in thread
From: Harald Judt @ 2021-10-08 11:38 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: emacs-orgmode
[-- Attachment #1.1.1: Type: text/plain, Size: 1264 bytes --]
Am 07.10.21 um 06:10 schrieb Ihor Radchenko:
> Harald Judt <h.judt@gmx.at> writes:
>
>> Hi,
>>
>> I am using this function to copy links from the agenda to the clipboard:
>>
>> (defun my-copy-org-url ()
>> (interactive)
>> (let* ((link-info (assoc :link (org-context)))
>> ...
>
> org-context is ancient. It relies on org-links being fontified using
> 'org-link face and would fail for any non-standard link with :face link
> parameter. Moreover, the return value will be different depending on
> org-link-descriptive setting.
>
> We should probably deprecate this function and encourage using
> org-element-context. So, I recommend rewriting your code with
> org-element-context.
Thank you, that helped me updating the function, which works fine with
org-element-context:
(defun my-copy-org-url ()
(interactive)
(let* ((raw-link (plist-get (nth 1 (org-element-context)) :raw-link)))
(if (not raw-link)
(error "Point not in an org link.")
(kill-new raw-link)
(message "Org link URL copied to clipboard."))))
Regards,
Harald
--
`Experience is the best teacher.'
PGP Key ID: 4FFFAB21B8580ABD
Fingerprint: E073 6DD8 FF40 9CF2 0665 11D4 4FFF AB21 B858 0ABD
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 659 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-08 11:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-06 9:44 [BUG] org-context called from link in org-agenda entry returns wrong values [9.5 (9.5-g0a86ad @ /home/.emacs.d/elpa/org-9.5/)] Harald Judt
2021-10-07 4:10 ` Ihor Radchenko
2021-10-08 11:38 ` Harald Judt
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).