[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat d375504e3c 27/84: Add with-buffer-unmodified-if-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat d375504e3c 27/84: Add with-buffer-unmodified-if-unchanged from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:32 -0500 (EST) |
branch: externals/compat
commit d375504e3cb06ac6519b96e4448c6cbd800f474b
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add with-buffer-unmodified-if-unchanged from Emacs 29
---
compat-29.el | 38 ++++++++++++++++++++++++++++++++++++++
compat.texi | 17 +++++++++++++++++
2 files changed, 55 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index 4389289105..8af82913ce 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -323,5 +323,43 @@ than this function."
(insert string)
(car (compat--buffer-text-pixel-size nil nil t)))))
+;;* UNTESTED
+(compat-defmacro with-buffer-unmodified-if-unchanged (&rest body)
+ "Like `progn', but change buffer-modified status only if buffer text changes.
+If the buffer was unmodified before execution of BODY, and
+buffer text after execution of BODY is identical to what it was
+before, ensure that buffer is still marked unmodified afterwards.
+For example, the following won't change the buffer's modification
+status:
+
+ (with-buffer-unmodified-if-unchanged
+ (insert \"a\")
+ (delete-char -1))
+
+Note that only changes in the raw byte sequence of the buffer text,
+as stored in the internal representation, are monitored for the
+purpose of detecting the lack of changes in buffer text. Any other
+changes that are normally perceived as \"buffer modifications\", such
+as changes in text properties, `buffer-file-coding-system', buffer
+multibyteness, etc. -- will not be noticed, and the buffer will still
+be marked unmodified, effectively ignoring those changes."
+ (declare (debug t) (indent 0))
+ (let ((hash (gensym))
+ (buffer (gensym)))
+ `(let ((,hash (and (not (buffer-modified-p))
+ (buffer-hash)))
+ (,buffer (current-buffer)))
+ (prog1
+ (progn
+ ,@body)
+ ;; If we didn't change anything in the buffer (and the buffer
+ ;; was previously unmodified), then flip the modification status
+ ;; back to "unchanged".
+ (when (and ,hash (buffer-live-p ,buffer))
+ (with-current-buffer ,buffer
+ (when (and (buffer-modified-p)
+ (equal ,hash (buffer-hash)))
+ (restore-buffer-modified-p nil))))))))
+
(provide 'compat-29)
;;; compat-29.el ends here
diff --git a/compat.texi b/compat.texi
index f19c884df5..e35065883c 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2481,6 +2481,23 @@ you can say:
@xref{Size of Displayed Text,,,elisp}.
@end defun
+@c based on lisp/subr-x.el
+@defmac with-buffer-unmodified-if-unchanged &rest body@dots{}
+Evaluate @var{body} like @code{progn}, but change buffer-modified status
+only if buffer text changes. If the buffer was unmodified before
+execution of BODY, and buffer text after execution of BODY is identical
+to what it was before, ensure that buffer is still marked unmodified
+afterwards.
+
+Note that only changes in the raw byte sequence of the buffer text, as
+stored in the internal representation, are monitored for the purpose of
+detecting the lack of changes in buffer text. Any other changes that
+are normally perceived as "buffer modifications", such as changes in
+text properties, @code{buffer-file-coding-system}, buffer multibyteness,
+etc. -- will not be noticed, and the buffer will still be marked
+unmodified, effectively ignoring those changes.
+@end defmac
+
@subsection Prefixed Definitions
- [elpa] externals/compat fdae099b00 34/84: Move if-let and related function from subr-x to subr, (continued)
- [elpa] externals/compat fdae099b00 34/84: Move if-let and related function from subr-x to subr, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 6ac6ed2a99 36/84: Use make-symbol instead of gensym in function-alias-p tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ef5246cf55 38/84: Fix issues related to 'expect' tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e6d279af18 14/84: Extend byte-compile-docstring-max-column to 100, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c177ff5e83 17/84: Reuse ntake in take definition, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0de389aca6 19/84: Add string-equal-ignore-case from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9ab3081959 26/84: Add string-pixel-width from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat d375504e3c 27/84: Add with-buffer-unmodified-if-unchanged from Emacs 29,
ELPA Syncer <=
- [elpa] externals/compat ded0f01036 40/84: Revert "Fix gv-expander for compat-alist-get", ELPA Syncer, 2023/01/03
- [elpa] externals/compat 878221eabd 44/84: Update the commentary section for compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4a56adbcdf 42/84: Remove references to the deleted "Emacs 24.5" node, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0c14c42bc1 50/84: Copy edebug specifications instead of referencing, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b888c2fb49 53/84: Replace when-let with expansions in compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 59cd42a912 60/84: Generate test names without double-dashes, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b0f8f6eaac 61/84: Remove realname for ntake, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 45028d9fa7 64/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 68c6ccd5cc 68/84: Always load compat-macs, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 54565a768c 73/84: Abbreviate Makefile by re-using BYTEC, ELPA Syncer, 2023/01/03