summaryrefslogtreecommitdiff
path: root/devdocs/elisp/buffer-modification.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/buffer-modification.html
new repository
Diffstat (limited to 'devdocs/elisp/buffer-modification.html')
-rw-r--r--devdocs/elisp/buffer-modification.html25
1 files changed, 25 insertions, 0 deletions
diff --git a/devdocs/elisp/buffer-modification.html b/devdocs/elisp/buffer-modification.html
new file mode 100644
index 00000000..c28752d4
--- /dev/null
+++ b/devdocs/elisp/buffer-modification.html
@@ -0,0 +1,25 @@
+ <h3 class="section">Buffer Modification</h3> <p>Emacs keeps a flag called the <em>modified flag</em> for each buffer, to record whether you have changed the text of the buffer. This flag is set to <code>t</code> whenever you alter the contents of the buffer, and cleared to <code>nil</code> when you save it. Thus, the flag shows whether there are unsaved changes. The flag value is normally shown in the mode line (see <a href="mode-line-variables">Mode Line Variables</a>), and controls saving (see <a href="saving-buffers">Saving Buffers</a>) and auto-saving (see <a href="auto_002dsaving">Auto-Saving</a>). </p> <p>Some Lisp programs set the flag explicitly. For example, the function <code>set-visited-file-name</code> sets the flag to <code>t</code>, because the text does not match the newly-visited file, even if it is unchanged from the file formerly visited. </p> <p>The functions that modify the contents of buffers are described in <a href="text">Text</a>. </p> <dl> <dt id="buffer-modified-p">Function: <strong>buffer-modified-p</strong> <em>&amp;optional buffer</em>
+</dt> <dd><p>This function returns <code>t</code> if the buffer <var>buffer</var> has been modified since it was last read in from a file or saved, or <code>nil</code> otherwise. If <var>buffer</var> is not supplied, the current buffer is tested. </p></dd>
+</dl> <dl> <dt id="set-buffer-modified-p">Function: <strong>set-buffer-modified-p</strong> <em>flag</em>
+</dt> <dd>
+<p>This function marks the current buffer as modified if <var>flag</var> is non-<code>nil</code>, or as unmodified if the flag is <code>nil</code>. </p> <p>Another effect of calling this function is to cause unconditional redisplay of the mode line for the current buffer. In fact, the function <code>force-mode-line-update</code> works by doing this: </p> <div class="example"> <pre class="example">(set-buffer-modified-p (buffer-modified-p))
+</pre>
+</div> </dd>
+</dl> <dl> <dt id="restore-buffer-modified-p">Function: <strong>restore-buffer-modified-p</strong> <em>flag</em>
+</dt> <dd><p>Like <code>set-buffer-modified-p</code>, but does not force redisplay of mode lines. </p></dd>
+</dl> <dl> <dt id="not-modified">Command: <strong>not-modified</strong> <em>&amp;optional arg</em>
+</dt> <dd>
+<p>This command marks the current buffer as unmodified, and not needing to be saved. If <var>arg</var> is non-<code>nil</code>, it marks the buffer as modified, so that it will be saved at the next suitable occasion. Interactively, <var>arg</var> is the prefix argument. </p> <p>Don’t use this function in programs, since it prints a message in the echo area; use <code>set-buffer-modified-p</code> (above) instead. </p>
+</dd>
+</dl> <dl> <dt id="buffer-modified-tick">Function: <strong>buffer-modified-tick</strong> <em>&amp;optional buffer</em>
+</dt> <dd><p>This function returns <var>buffer</var>’s modification-count. This is a counter that increments every time the buffer is modified. If <var>buffer</var> is <code>nil</code> (or omitted), the current buffer is used. </p></dd>
+</dl> <dl> <dt id="buffer-chars-modified-tick">Function: <strong>buffer-chars-modified-tick</strong> <em>&amp;optional buffer</em>
+</dt> <dd><p>This function returns <var>buffer</var>’s character-change modification-count. Changes to text properties leave this counter unchanged; however, each time text is inserted or removed from the buffer, the counter is reset to the value that would be returned by <code>buffer-modified-tick</code>. By comparing the values returned by two <code>buffer-chars-modified-tick</code> calls, you can tell whether a character change occurred in that buffer in between the calls. If <var>buffer</var> is <code>nil</code> (or omitted), the current buffer is used. </p></dd>
+</dl> <p>Sometimes there’s a need for modifying buffer in a way that doesn’t really change its text, like if only its text properties are changed. If your program needs to modify a buffer without triggering any hooks and features that react to buffer modifications, use the <code>with-silent-modifications</code> macro. </p> <dl> <dt id="with-silent-modifications">Macro: <strong>with-silent-modifications</strong> <em>body…</em>
+</dt> <dd><p>Execute <var>body</var> pretending it does not modify the buffer. This includes checking whether the buffer’s file is locked (see <a href="file-locks">File Locks</a>), running buffer modification hooks (see <a href="change-hooks">Change Hooks</a>), etc. Note that if <var>body</var> actually modifies the buffer text (as opposed to its text properties), its undo data may become corrupted. </p></dd>
+</dl><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/Buffer-Modification.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Buffer-Modification.html</a>
+ </p>
+</div>