[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/wfnames c7e895f406 86/98: Allow reverting changes line by
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/wfnames c7e895f406 86/98: Allow reverting changes line by line |
Date: |
Tue, 8 Aug 2023 04:01:39 -0400 (EDT) |
branch: elpa/wfnames
commit c7e895f40671c28dc240074533f07ed050044b62
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Allow reverting changes line by line
Now wfnames-revert-changes is used as revert-buffer-function.
---
wfnames.el | 52 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 36 insertions(+), 16 deletions(-)
diff --git a/wfnames.el b/wfnames.el
index 6d013da506..d67ffd3d62 100644
--- a/wfnames.el
+++ b/wfnames.el
@@ -91,7 +91,8 @@
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'wfnames-commit-buffer)
(define-key map (kbd "C-x C-s") #'wfnames-commit-buffer)
- (define-key map (kbd "C-c C-r") #'wfnames-revert-changes)
+ (define-key map (kbd "C-c C-r") #'wfnames-revert-current-line)
+ (define-key map (kbd "C-M-r") #'revert-buffer)
(define-key map (kbd "C-c C-k") #'wfnames-abort)
(define-key map (kbd "TAB") #'completion-at-point)
;; This override ispell completion in iedit map which is useless
@@ -117,7 +118,8 @@ Special commands:
\\{wfnames-mode-map}"
(add-hook 'after-change-functions #'wfnames-after-change-hook nil t)
(make-local-variable 'wfnames--modified)
- (set (make-local-variable 'completion-at-point-functions) #'wfnames-capf))
+ (set (make-local-variable 'completion-at-point-functions) #'wfnames-capf)
+ (set (make-local-variable 'revert-buffer-function) #'wfnames-revert-changes))
(defun wfnames-abort ()
"Quit and kill wfnames buffer."
@@ -275,9 +277,37 @@ When APPEND is specified, append FILES to existing
`wfnames-buffer'."
(message "Renamed %s file(s), Skipped %s file(s)" renamed skipped)
(funcall wfnames-after-commit-function wfnames-buffer))))
-(defun wfnames-revert-changes ()
- "Revert wfnames buffer to its initial state."
- (interactive)
+(defun wfnames-revert-current-line-1 ()
+ "Revert current line to its initial state in a wfnames buffer.
+
+With a numeric prefix ARG, revert the ARG next lines."
+ (let ((old (get-text-property (point) 'old-name))
+ (new (buffer-substring-no-properties
+ (point-at-bol) (point-at-eol))))
+ (unless (string= old new)
+ (delete-region (point-at-bol) (point-at-eol))
+ (insert (propertize
+ old 'old-name old 'face 'wfnames-file
+ 'line-prefix (propertize
+ "* "
+ 'face 'wfnames-prefix))))
+ (forward-line 1)))
+
+(defun wfnames-revert-current-line (&optional arg)
+ "Revert current line to its initial state in a wfnames buffer.
+
+With a numeric prefix ARG, revert the ARG next lines."
+ (interactive "p")
+ (dotimes (_ arg)
+ (wfnames-revert-current-line-1)
+ (when (eobp) (forward-line -1))
+ (goto-char (point-at-bol))
+ (while (re-search-forward "/" (point-at-eol) t))))
+
+(defun wfnames-revert-changes (_ignore-auto _no-confirm)
+ "Revert wfnames buffer to its initial state.
+
+This is used as `revert-buffer-function' for `wfnames-mode'."
(with-current-buffer wfnames-buffer
(cl-loop for o in (overlays-in (point-min) (point-max))
when (overlay-get o 'hff-changed)
@@ -285,17 +315,7 @@ When APPEND is specified, append FILES to existing
`wfnames-buffer'."
(goto-char (point-min))
(save-excursion
(while (not (eobp))
- (let ((old (get-text-property (point) 'old-name))
- (new (buffer-substring-no-properties
- (point-at-bol) (point-at-eol))))
- (unless (string= old new)
- (delete-region (point-at-bol) (point-at-eol))
- (insert (propertize
- old 'old-name old 'face 'wfnames-file
- 'line-prefix (propertize
- "* "
- 'face 'wfnames-prefix))))
- (forward-line 1))))
+ (wfnames-revert-current-line-1)))
(while (re-search-forward "/" (point-at-eol) t))))
(provide 'wfnames)
- [nongnu] elpa/wfnames 6f13e86c85 48/98: Fix renaming directories behavior, (continued)
- [nongnu] elpa/wfnames 6f13e86c85 48/98: Fix renaming directories behavior, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames d632731f2e 50/98: Go to beginning of basename on first line, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames a707b9d073 72/98: Add binding for CAP, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 6899da10b2 75/98: Modify revert binding, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 8d267316e8 83/98: Minor fixes in headers and keep requiring cl-lib as always, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 14cd7e7108 87/98: Ensure we have not an empty line at point, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames db1f17a5dd 92/98: Require emacs-24.4 for delete-duplicate-lines, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 3a12c46be1 64/98: Comments only, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames c761a398ab 65/98: Add a minimal capf, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 0064a2b8e4 82/98: Fix errors according to package-lint, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames c7e895f406 86/98: Allow reverting changes line by line,
ELPA Syncer <=
- [nongnu] elpa/wfnames 4447417c58 88/98: Bump to 1.1, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 810a606075 04/98: Use a different face when file would be overwrited, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 0cf41398c2 05/98: Fix after-change-function, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 120c08652a 15/98: Revert "Remove unused variable", ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 1219dca135 14/98: Bind beg and end to avoid repeating, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 75bae40bf4 17/98: Add comments, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames ca6e126e15 49/98: Change commit buffer default binding, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 6d661e78a2 68/98: Erase buffer, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 14e9d0204d 66/98: New user var to decide what to to with buffer when done, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 4ccea88ae1 93/98: Prefer defcustom over defvar, ELPA Syncer, 2023/08/08