[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/wfnames 14545063a4 01/98: Initial commit
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/wfnames 14545063a4 01/98: Initial commit |
Date: |
Tue, 8 Aug 2023 04:01:11 -0400 (EDT) |
branch: elpa/wfnames
commit 14545063a4700bf7b49fe743d6cc9d6826d02d28
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Initial commit
---
helm-edit-marked.el | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/helm-edit-marked.el b/helm-edit-marked.el
new file mode 100644
index 0000000000..5f625968db
--- /dev/null
+++ b/helm-edit-marked.el
@@ -0,0 +1,103 @@
+;;; Edit marked files
+;;
+(defvar helm-ff-edit-buffer "*edit hff marked*")
+(defvar helm-ff--edit-marked-old-files nil)
+
+(defvar helm-ff-edit-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-x C-s") #'helm-ff-edit-marked-commit-buffer)
+ (define-key map (kbd "C-c C-k") #'helm-ff-edit-marked-revert-changes)
+ map))
+
+(define-derived-mode helm-ff-edit-mode text-mode
+ "helm-ff-edit-mode"
+ "Edit HFF marked files.
+
+Special commands:
+\\{helm-ff-edit-mode-map}
+"
+ (add-hook 'after-change-functions #'helm-ff-edit-marked-after-change-hook
nil t))
+
+(defun helm-ff-edit-marked-after-change-hook (beg end _leng-before)
+ (with-current-buffer helm-ff-edit-buffer
+ (let ((old (get-text-property (point-at-bol) 'old-name))
+ (new (buffer-substring-no-properties
+ (point-at-bol) (point-at-eol)))
+ ov)
+ (cond ((string= old new)
+ (cl-loop for o in (overlays-in (point-at-bol) (point-at-eol))
+ when (overlay-get o 'hff-changed)
+ do (delete-overlay o)))
+ (t
+ (setq ov (make-overlay (point-at-bol) (point-at-eol)))
+ (overlay-put ov 'face '(:background "LightBlue"))
+ (overlay-put ov 'hff-changed t)
+ (setq ov (make-overlay beg end))
+ (overlay-put ov 'face 'font-lock-variable-name-face)
+ (overlay-put ov 'hff-changed t))))))
+
+(defun helm-ff-edit-marked-files (_candidate)
+ (let ((marked (helm-marked-candidates :with-wildcard t)))
+ (with-current-buffer (get-buffer-create helm-ff-edit-buffer)
+ (save-excursion
+ (cl-loop for file in marked
+ do (insert (propertize
+ file 'old-name file 'face 'helm-ff-file)
+ "\n")))
+ (helm-ff-edit-mode)
+ (set (make-local-variable 'helm-ff--edit-marked-old-files) marked))
+ (switch-to-buffer helm-ff-edit-buffer)))
+
+;; /home/thierry/tmp/test001.txt
+;; /home/thierry/tmp/test002.txt
+;; /home/thierry/tmp/test003.txt
+;; /home/thierry/tmp/test004.txt
+;; /home/thierry/tmp/test005.txt
+
+
+;; /home/thierry/tmp/test005.txt
+;; /home/thierry/tmp/test004.txt
+;; /home/thierry/tmp/test003.txt
+;; /home/thierry/tmp/test002.txt
+
+(defun helm-ff-edit-marked-commit-buffer ()
+ (interactive)
+ (let ((renamed 0) suspended)
+ (cl-labels ((commit ()
+ (with-current-buffer helm-ff-edit-buffer
+ (goto-char (point-min))
+ (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) ; not modified.
+ (if (file-exists-p new)
+ (push new suspended)
+ (rename-file old new)
+ (add-text-properties
+ (point-at-bol) (point-at-eol) `(old-name ,new))
+ (setq suspended (delete new suspended))
+ (cl-incf renamed))))
+ (forward-line 1))
+ (when suspended (commit)))))
+ (commit)
+ (message "* Renamed %s file(s) " renamed)
+ (kill-buffer helm-ff-edit-buffer))))
+
+(defun helm-ff-edit-marked-revert-changes ()
+ (interactive)
+ (with-current-buffer helm-ff-edit-buffer
+ (cl-loop for o in (overlays-in (point-min) (point-max))
+ when (overlay-get o 'hff-changed)
+ do (delete-overlay o))
+ (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 'helm-ff-file)))
+ (forward-line 1))))))
- [nongnu] branch elpa/wfnames created (now e4d6097892), ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames d3f69bdf68 33/98: Add README, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 20c12aefce 21/98: Add interactive renaming, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames f4d9e77e86 25/98: Fix renaming directories, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 6f35a52e39 28/98: Rename all to wfnames prefix, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 2cf98cdf92 39/98: Long lines only, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames c665261bae 09/98: No need to call helm-marked-candidates with wildcard arg, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 14545063a4 01/98: Initial commit,
ELPA Syncer <=
- [nongnu] elpa/wfnames d5a87a00c2 08/98: Add TODO comment, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames c36c387f1c 13/98: Fix paren error (again), ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames ccf3696257 12/98: Update TODO, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 924319f51a 23/98: Fixup comments, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 8e34c7bb75 18/98: Reindent, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 73104c1cbd 29/98: Fix group and use someting else than helm-basedir, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 2e9f34d939 20/98: Handle directories rename, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames d034d09e6d 36/98: Restore props after changes made by something else than self-insert-command, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames 810aea61db 38/98: Long lines only, ELPA Syncer, 2023/08/08
- [nongnu] elpa/wfnames ac577774ef 40/98: Revert "Handle backup overwrite", ELPA Syncer, 2023/08/08