Explorar o código

babel: adding library-of-babel functions for file I/O

* contrib/babel/lisp/org-babel.el (org-babel-insert-result): Replaced
  call to `org-cycle' with a call to the simpler and more appropriate
  `org-table-align'.

* contrib/babel/library-of-babel.org (Read/Write): adding
  library-of-babel functions for file I/O
Eric Schulte %!s(int64=14) %!d(string=hai) anos
pai
achega
4e43e7fea8
Modificáronse 2 ficheiros con 27 adicións e 1 borrados
  1. 26 0
      contrib/babel/library-of-babel.org
  2. 1 1
      contrib/babel/lisp/org-babel.el

+ 26 - 0
contrib/babel/library-of-babel.org

@@ -35,6 +35,32 @@
   The raw Org-mode text of this file can be downloaded at
   [[repofile:contrib/babel/library-of-babel.org][library-of-babel.org]]
 
+* File I/O
+** reading and writing files
+Read the contents of the file at =path= into a string.
+#+srcname: read
+#+begin_src emacs-lisp :var path=""
+  (with-temp-filebuffer path
+    (buffer-substring (point-min) (point-max)))
+#+end_src
+
+Read the lines of the file at =path= into a list.
+#+srcname: read-lines
+#+begin_src emacs-lisp :var path=""
+  (split-string
+   (with-temp-filebuffer path
+     (buffer-substring (point-min) (point-max))))
+#+end_src
+
+Write =data= to a file at =path=.  If =data= is a list, then write it
+as a table in traditional Org-mode table syntax.
+#+srcname: write
+#+begin_src emacs-lisp :var data="" :var path=""
+  (with-temp-file path
+    (org-babel-insert-result data))
+  nil
+#+end_src
+
 * Plotting code
 
 ** R

+ 1 - 1
contrib/babel/lisp/org-babel.el

@@ -965,7 +965,7 @@ code ---- the results are extracted in the syntax of the source
 					  (listp (cdr (car result)))))
 				 result (list result))
 			     '(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
-	    (goto-char beg) (org-cycle))
+	    (goto-char beg) (org-table-align))
 	   ((member "file" result-params)
 	    (insert result))
 	   ((member "html" result-params)