Scimax notebook's nb: links do not work
I have the following link in my file
nb:ESS462::po4-model-2.org::c580
Clicking this link will open the respective file, but
#+transclude: [[nb:ESS462::po4-model-2.org::c580][PO4 Model]]
will result in a no-content found error. Thx for any hints how to go about this
What does nb: link link to? I have never seen it.
Perhaps you can add support; similar things have been done https://github.com/nobiot/org-transclusion/issues/160
did some digging. It is a link format introduced by J Kitchen and used in scimax.
https://github.com/jkitchin/scimax/blob/master/scimax-notebook.org#notebookproject-links
I looked at #160 and I think John's code provides similar functions so that this solution could be adapted, but my background is in python so I am not sure.
As a workaround, setting (org-link-set-parameters "nb" :store nil) disables the notebook links, and uses id's instead.
I can't really test this as I don't have scimax, but something like the following should work. Could I assume you know how to use the snippets like this below? If not, that's fine; I can help you. I would just like to know how comfortable you are with Elisp.
(defun org-transclusion-add-nb-org-file (link plist)
"Return a list for Org file LINK object and PLIST.
Return nil if not found."
(when (string= "nb" (org-element-property :type link))
(append '(:tc-type "org-link")
(org-transclusion-content-nb-link-to-org link plist))))
(defun org-transclusion-content-nb-link-to-org (link plist)
(nb-follow-other (org-element-property :path link))
;; Now in the notes buffer
;; Assume it's an Org buffer
(prog1 (org-transclusion-content-org-buffer-or-element
'only-element plist)
;; No need to stay in the notes buffer
;; Kill
(kill-buffer)))
(add-hook 'org-transclusion-add-functions #'org-transclusion-add-nb-org-file)
Thanks, I tried the above and it works somewhat.
Using a regular org file located in ~tmp and adding the following link
[[nb:esbmtk::esbmtk/esbmtk.py::c1]] resolves to ~python-scripts/esbmtk/esbmtk.py when I follow the link.
Using your code snippet above, adding the transclusion keyword, and then trying to transclude attempts to open ~tmp/esbmtk/esbmtk.py instead.
So there is some difference between how org resolves the link and how transclude resolves the link.
OK, thank you for confirming. I only covered the case of the target file being an org file based on the example you gave me, assuming that's probably your use case.
Yes, the nb function nb-follow-other differentiates the two case: target org file or others. I didn't have energy to cover both on a Sunday night.
I'll give another try. Probably not this week or weekend. Some time next week is my guess...
NP. I tried with an org file but then it says. no content found. Cheers
On Mon, Jan 23, 2023 at 9:42 AM nobiot @.***> wrote:
OK, thank you for confirming. I only covered the case of the target file being an org file based on the example you gave me, assuming that's probably your use case.
Yes, the nb function nb-follow-other differentiates the two case: target org file or others. I didn't have energy to cover both on a Sunday night.
I'll give another try. Probably not this week or weekend. Some time next week is my guess...
— Reply to this email directly, view it on GitHub https://github.com/nobiot/org-transclusion/issues/161#issuecomment-1400458458, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWSVAU3OC6DGB2L3W7H7YLWT2KGZANCNFSM6AAAAAAUCUM2QY . You are receiving this because you authored the thread.Message ID: @.***>
-- Ulrich G. Wortmann https://www.es.utoronto.ca/people/faculty/wortmann-ulrich/ Dept. of Earth Sciences University of Toronto Phone: 416 978 7084 22 Ursula Franklin Street, Toronto, ON, Canada M5S 3B1
I see. Hmm. It sounds like I will need to install scimax and see how it really works.
it installs cleanly into a separate directory without interfering with your local setup. From the scimax menu, select notebook, new notebook. Storing a link from within the notebook should create the above link format.
Thank you. Internally, scimax seems to use a lot of packages that I don't use and am not familiar with -- e.g. projectile to group the org and other files into projects, etc. I will see what I can do, but at the moment my gut feel is it is not a quick thing. Stay tuned and wish me luck.
Will do! I think the linking code is in this package
https://github.com/jkitchin/scimax/blob/master/scimax-notebook.org#notebookproject-links
here is another tidbit. The link returned from org-store-link looks like this [[nb:esbmtk::esbmtk/esbmtk.py::c]] if scimax is installed the following lisp command will open the relevant buffer)
#+SRC emacs-lisp
(nb-follow "esbmtk::esbmtk/esbmtk.py::c")
#+END_SRC
note that the link type (nb) has been stripped
I had some time and got curious, so had a second go. I coded this in scimax, and it worked on my project for both an org file and program files.
Two notes:
-
As noted in the source comment, evaluate
add-hookafterorg-transclusionhas been loaded. The key is that#'org-transclusion-add-nb-org-filemust be in an element before other default ones in the list; it must be beforeorg-transclusion-add-src-lines; otherwiseadd-src-linestakes precedent. -
For source files, this code only get the file name and ignore the location specifier (::c10, ::10, etc.). If you wish to specify a starting line number, use
:linesparameter. as part of the#+transclude:.
One thing I was not sure about in your case is the use of ~tmp. It seems to be a temporary directory, but I'm not sure how you use it. This could be another source of issues, but this is as far as I can get to in this week. I can't work on it on this weekend, so if there is any issue that requires a bit of work, it will have to wait until some time next week.
;; -*- lexical-binding: t; -*-
(defun org-transclusion-add-nb-org-file (link plist)
"Return a list for Org file LINK object and PLIST.
Return nil if not found."
(when (string= "nb" (org-element-property :type link))
(append '(:tc-type "org-link")
(org-transclusion-content-nb-link-to-org link plist))))
(defun org-transclusion-content-nb-link-to-org (link plist)
(let ((orig-buf (current-buffer))
(target-file nil))
(nb-follow-other (org-element-property :path link))
;; Now in the notes buffer
;; Assume it's an Org buffer
(setq target-file buffer-file-name)
(prog1
(cond
((derived-mode-p 'org-mode)
(org-transclusion-content-org-buffer-or-element
'only-element plist))
(t
(let ((new-link (with-temp-buffer
(insert "file:")
(insert target-file)
(beginning-of-buffer)
(org-element-link-parser))))
(org-transclusion-content-src-lines new-link plist))))
(pop-to-buffer orig-buf))))
;; Run this after org-transclusion has been
;; loaded. `org-transclusion-add-nb-org-file' should be at the beginning
;; of the list
(add-hook 'org-transclusion-add-functions #'org-transclusion-add-nb-org-file)
that works like a charm, for org-files and also for py files. org-transclusion-make-from-link, does not work, but that is only a minor inconvenience. Thanks so much!
You're welcome. I will look into org-transclusion-make-from-link at some point later. It should just work...
I am thinking of spending a little more time on this. If I get somewhere, I might put it as a scimax notebook support.
Thanks for reporting the issue :)