summaryrefslogtreecommitdiff
path: root/devdocs/elisp/reading-from-files.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/reading-from-files.html
new repository
Diffstat (limited to 'devdocs/elisp/reading-from-files.html')
-rw-r--r--devdocs/elisp/reading-from-files.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/elisp/reading-from-files.html b/devdocs/elisp/reading-from-files.html
new file mode 100644
index 00000000..07b86252
--- /dev/null
+++ b/devdocs/elisp/reading-from-files.html
@@ -0,0 +1,14 @@
+ <h3 class="section">Reading from Files</h3> <p>To copy the contents of a file into a buffer, use the function <code>insert-file-contents</code>. (Don’t use the command <code>insert-file</code> in a Lisp program, as that sets the mark.) </p> <dl> <dt id="insert-file-contents">Function: <strong>insert-file-contents</strong> <em>filename &amp;optional visit beg end replace</em>
+</dt> <dd>
+<p>This function inserts the contents of file <var>filename</var> into the current buffer after point. It returns a list of the absolute file name and the length of the data inserted. An error is signaled if <var>filename</var> is not the name of a file that can be read. </p> <p>This function checks the file contents against the defined file formats, and converts the file contents if appropriate and also calls the functions in the list <code>after-insert-file-functions</code>. See <a href="format-conversion">Format Conversion</a>. Normally, one of the functions in the <code>after-insert-file-functions</code> list determines the coding system (see <a href="coding-systems">Coding Systems</a>) used for decoding the file’s contents, including end-of-line conversion. However, if the file contains null bytes, it is by default visited without any code conversions. See <a href="lisp-and-coding-systems">inhibit-null-byte-detection</a>. </p> <p>If <var>visit</var> is non-<code>nil</code>, this function additionally marks the buffer as unmodified and sets up various fields in the buffer so that it is visiting the file <var>filename</var>: these include the buffer’s visited file name and its last save file modtime. This feature is used by <code>find-file-noselect</code> and you probably should not use it yourself. </p> <p>If <var>beg</var> and <var>end</var> are non-<code>nil</code>, they should be numbers that are byte offsets specifying the portion of the file to insert. In this case, <var>visit</var> must be <code>nil</code>. For example, </p> <div class="example"> <pre class="example">(insert-file-contents filename nil 0 500)
+</pre>
+</div> <p>inserts the characters coded by the first 500 bytes of a file. </p> <p>If <var>beg</var> or <var>end</var> happens to be in the middle of a character’s multibyte sequence, Emacs’s character code conversion will insert one or more eight-bit characters (a.k.a. “raw bytes”) (see <a href="character-sets">Character Sets</a>) into the buffer. If you want to read part of a file this way, we recommend to bind <code>coding-system-for-read</code> to a suitable value around the call to this function (see <a href="specifying-coding-systems">Specifying Coding Systems</a>), and to write Lisp code which will check for raw bytes at the boundaries, read the entire sequence of these bytes, and convert them back to valid characters. </p> <p>If the argument <var>replace</var> is non-<code>nil</code>, it means to replace the contents of the buffer (actually, just the accessible portion) with the contents of the file. This is better than simply deleting the buffer contents and inserting the whole file, because (1) it preserves some marker positions and (2) it puts less data in the undo list. </p> <p>It is possible to read a special file (such as a FIFO or an I/O device) with <code>insert-file-contents</code>, as long as <var>replace</var> and <var>visit</var> are <code>nil</code>. </p>
+</dd>
+</dl> <dl> <dt id="insert-file-contents-literally">Function: <strong>insert-file-contents-literally</strong> <em>filename &amp;optional visit beg end replace</em>
+</dt> <dd><p>This function works like <code>insert-file-contents</code> except that each byte in the file is handled separately, being converted into an eight-bit character if needed. It does not run <code>after-insert-file-functions</code>, and does not do format decoding, character code conversion, automatic uncompression, and so on. </p></dd>
+</dl> <p>If you want to pass a file name to another process so that another program can read the file, use the function <code>file-local-copy</code>; see <a href="magic-file-names">Magic File Names</a>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Reading-from-Files.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Reading-from-Files.html</a>
+ </p>
+</div>