emacs/var/elfeed/db/data/47/479ed34d7262ee75590b86426d5098b764b84cef
2022-01-03 12:49:32 -06:00

1 line
2.5 KiB
Plaintext

<!-- SC_OFF --><div class="md"><p>So, I was working in an <code>org</code> file with tables that needed to reference tables from different files. According to the <a href="https://orgmode.org/manual/References.html">org manual</a>, you can do this with <code>remote(&lt;id&gt;, &lt;range&gt;)</code>. This is problematic for a couple of reasons. First, it is very fragile. Sometimes it works, sometimes it doesn&#39;t. Maybe I was doing something wrong with the IDs, but it was very unstable for me. Second, it means that, if you sync your org files in multiple machines, you&#39;ll also have to sync the id. Finally, and this is the big one, accoring to the org manual, you assing an ID to a heading and the remote call will look for the first table under that heading. But what if you need the second table?</p> <p>Instead of fighting with the IDs problem, I decided to do some elisp magic to see if I could grab a table range from a remote table with file path and <code>#:name</code>. To my surpirse, it was very easy to do. All you need is this function somewhere in your init file:</p> <pre><code>(defun j/remote-table-range (path name range) (with-current-buffer (find-file-noselect path) (org-table-get-remote-range name range))) </code></pre> <p>Then, you have to add the <code>#:name</code> tag to the remote table:</p> <pre><code>;; Contents of ~/table-test/remote.org #+name: remote-t1 | C1 | C2 | | 1 | 2 | </code></pre> <p>Then, from another table, you can call it like this:</p> <pre><code>;; Contents of ~/table-test/main.org | C1 | C2 | | | | #+tblfm: @1$1=&#39;(j/remote-table-range &quot;./remote.org&quot; &quot;remote-t1&quot; (string ?@ ?1 ?$ ?1)) </code></pre> <p>The path can be absolute or relative, and you can reference any table in that file using the name argument. The wierd string call is explained <a href="https://stackoverflow.com/a/15700076/3006252">here</a>.</p> <p>And that&#39;s it. IMO, while it makes for longer formulas, it is way more convenient than the current remote function with IDs and have less limitations. </p> <p>I was amazed with how little code was needed for this. Man, do I love emacs...</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/ElCondorHerido"> /u/ElCondorHerido </a> <br/> <span><a href="https://www.reddit.com/r/emacs/comments/r2nig7/remote_tables_with_file_path_no_ids_in_table/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/emacs/comments/r2nig7/remote_tables_with_file_path_no_ids_in_table/">[comments]</a></span>