[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/edit-indirect 273910a944 11/28: Ensure commit hooks are al
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/edit-indirect 273910a944 11/28: Ensure commit hooks are always called with the correct region. |
Date: |
Thu, 7 Jul 2022 11:59:13 -0400 (EDT) |
branch: elpa/edit-indirect
commit 273910a944400bb540d66acc16e5767af011afad
Author: Fanael Linithien <fanael4@gmail.com>
Commit: Fanael Linithien <fanael4@gmail.com>
Ensure commit hooks are always called with the correct region.
---
edit-indirect.el | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/edit-indirect.el b/edit-indirect.el
index b9c0cbd459..2edb03e9ac 100644
--- a/edit-indirect.el
+++ b/edit-indirect.el
@@ -299,11 +299,33 @@ No error is signaled if `inhibit-read-only' or
(edit-indirect--inhibit-read-only t))
(with-current-buffer (overlay-buffer edit-indirect--overlay)
(save-excursion
- (run-hook-with-args 'edit-indirect-before-commit-functions beg end)
- (delete-region beg end)
- (goto-char beg)
- (insert-buffer-substring-no-properties buffer 1 (1+ (buffer-size
buffer)))
- (run-hook-with-args 'edit-indirect-after-commit-functions beg
(point))))))
+ (let ((beg-marker (copy-marker beg))
+ (end-marker (copy-marker end)))
+ (edit-indirect--run-hook-with-positions
+ 'edit-indirect-before-commit-functions beg-marker end-marker)
+ (delete-region beg-marker end-marker)
+ (goto-char beg-marker)
+ (insert-buffer-substring-no-properties buffer 1 (1+ (buffer-size
buffer)))
+ (edit-indirect--run-hook-with-positions
+ 'edit-indirect-after-commit-functions beg-marker (point))
+ (set-marker beg-marker nil)
+ (set-marker end-marker nil))))))
+
+(defun edit-indirect--run-hook-with-positions (hook beg end)
+ "Run HOOK with the specified positions BEG and END.
+HOOK should be a symbol, a hook variable.
+The functions are passed integer positions.
+If a function changes the buffer contents, the next function will be
+called with updated positions."
+ (let ((beg-marker (unless (markerp beg) (copy-marker beg)))
+ (end-marker (unless (markerp end) (copy-marker end))))
+ (run-hook-wrapped hook
+ (lambda (f beg end)
+ (funcall f (marker-position beg) (marker-position end))
+ nil)
+ (or beg-marker beg) (or end-marker end))
+ (when beg-marker (set-marker beg-marker nil))
+ (when end-marker (set-marker end-marker nil))))
(defun edit-indirect--abort ()
"Abort indirect edit."
- [nongnu] branch elpa/edit-indirect created (now f80f63822f), ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 1d0cabfbe7 02/28: Clarify how this package differs from clone-indirect-buffer., ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 56e3231915 01/28: Initial import., ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect ac56a2ff8d 03/28: Add C-c C-c binding for edit-indirect-commit., ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect e01e7eeb79 04/28: Extract a nested let into a function., ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 273910a944 11/28: Ensure commit hooks are always called with the correct region.,
ELPA Syncer <=
- [nongnu] elpa/edit-indirect 215d3a714a 16/28: Release version 0.1.3, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect de645d8144 21/28: Add edit-indirect-save function and keybinding, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 2fc8f382ee 19/28: Add before-commit-hook, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect bdc8f542fe 23/28: Don't run buffer-local after-creation-hook twice, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect f80f63822f 28/28: Make edit-indirect--should-quit-window persistent, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 03b6ac9ed1 25/28: Use a remap binding for save-buffer instead of hardcoded C-x C-s, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 7fffd87ac3 24/28: Don't modify buffer if nothing changed, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 16bcdbdae6 27/28: Add an overlay keymap for easy switching to active edit-indirect buffers, ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect b461e559e1 05/28: Don't retrieve the buffer-local hook values before actual uses., ELPA Syncer, 2022/07/07
- [nongnu] elpa/edit-indirect 7d9bcfced3 06/28: Extract buffer-local value handling into a macro., ELPA Syncer, 2022/07/07