main
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<!-- Sep 03, 2024 -->
5<meta charset="utf-8" />
6<meta name="viewport" content="width=device-width, initial-scale=1" />
7<title>Library of Babel (org-mode)</title>
8<meta name="author" content="Vincent Demeester" />
9<meta name="generator" content="Org Mode" />
10<link rel='icon' type='image/x-icon' href='/images/favicon.ico'/>
11<meta name='viewport' content='width=device-width, initial-scale=1'>
12<link rel='stylesheet' href='/css/new.css' type='text/css'/>
13<link rel='stylesheet' href='/css/syntax.css' type='text/css'/>
14<link href='/index.xml' rel='alternate' type='application/rss+xml' title='Vincent Demeester' />
15</head>
16<body>
17<main id="content" class="content">
18<header>
19<h1 class="title">Library of Babel (org-mode)</h1>
20</header><p>
21This is my <a href="org_mode.html">org-mode</a> <a href="https://orgmode.org/manual/Library-of-Babel.html">Library of Babel</a>.
22</p>
23<section id="outline-container-File%20I%2FO" class="outline-2">
24<h2 id="File%20I%2FO">File I/O</h2>
25<div class="outline-text-2" id="text-File%20I%2FO">
26</div>
27<div id="outline-container-Reading%20and%20writing%20files" class="outline-3">
28<h3 id="Reading%20and%20writing%20files">Reading and writing files</h3>
29<div class="outline-text-3" id="text-Reading%20and%20writing%20files">
30<p>
31Read the contents of the file at <code>file</code>. The <code>:results vector</code> and
32<code>:results scalar</code> header arguments can be used to read the contents of
33file as either a table or a string.
34</p>
35
36<div class="org-src-container">
37<pre class="src src-emacs-lisp" id="org3a5f35f">(if (string= format "csv")
38 (with-temp-buffer
39 (org-table-import (expand-file-name file) nil)
40 (org-table-to-lisp))
41 (with-temp-buffer
42 (insert-file-contents (expand-file-name file))
43 (buffer-string)))
44</pre>
45</div>
46
47<p>
48Write <code>data</code> to a file at <code>file</code>. If <code>data</code> is a list, then write it
49as a table in traditional Org-mode table syntax.
50</p>
51
52<div class="org-src-container">
53<pre class="src src-emacs-lisp" id="orgcff07ff">(flet ((echo (r) (if (stringp r) r (format "%S" r))))
54 (with-temp-file file
55 (case (and (listp data)
56 (or ext (intern (file-name-extension file))))
57 ('tsv (insert (orgtbl-to-tsv data '(:fmt echo))))
58 ('csv (insert (orgtbl-to-csv data '(:fmt echo))))
59 (t (org-babel-insert-result data)))))
60nil
61</pre>
62</div>
63</div>
64</div>
65</section>
66</main>
67<footer id="postamble" class="status">
68<footer>
69 <small><a href="/" rel="history">Index</a> • <a href="/sitemap.html">Sitemap</a> • <a href="https://dl.sbr.pm/">Files</a></small><br/>
70 <small class='questions'>Questions, comments ? Please use my <a href="https://lists.sr.ht/~vdemeester/public-inbox">public inbox</a> by sending a plain-text email to <a href="mailto:~vdemeester/public-inbox@lists.sr.ht">~vdemeester/public-inbox@lists.sr.ht</a>.</small><br/>
71 <small class='copyright'>
72 Content and design by Vincent Demeester
73 (<a rel='licence' href='http://creativecommons.org/licenses/by-nc-sa/3.0/'>Some rights reserved</a>)
74 </small><br />
75</footer>
76</footer>
77</body>
78</html>