From: Arthur Miller <arthur.miller@live.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Partial wdired (edit just filename at the point)
Date: Wed, 17 Mar 2021 23:40:28 +0100 [thread overview]
Message-ID: <AM9PR09MB4977DF19DEE399844CA6C28E966A9@AM9PR09MB4977.eurprd09.prod.outlook.com> (raw)
In-Reply-To: <AM9PR09MB4977012DE14DAD419E2DF786966A9@AM9PR09MB4977.eurprd09.prod.outlook.com> (Arthur Miller's message of "Wed, 17 Mar 2021 20:56:26 +0100")
[-- Attachment #1: Type: text/plain, Size: 2327 bytes --]
Arthur Miller <arthur.miller@live.com> writes:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>>> The problem here is how aborting changes is implemented in wdired: undo
>>> is disabled and original code just copies entire buffer and pastes it back
>>> when changes are aborted.
>>
>> I think you should be able to leave this part of the code completely unchanged.
>
> Yes; and for the simplicity it will be so.
>
>>> I would like to skip copying entire buffer into buffer-string as
>>> wdired does originally.
>>
>> Any particular reason for that? It should be very fast, even for very
>> large directories.
>
> Just for efficiency; it copies entire buffer which can be quite big
> memory wise; but indeed it seems to be very fast, and I guess for the
> simplicity of implementation it can be left as is :-).
>
>>> I agree with you, but I am not sure how to implement it. My hack was
>>> literally less than a 5 minute change, I just removed loops and changed
>>> mode name so I can abort it properly.
>>
>> I'd start with the following:
>> When converting to wdired, instead of calling `wdired-preprocess-files`, use
>>
>> (add-hook 'before-change-functions #'wdired--preprocess-lines nil t)
>>
>> and then turn `wdired-preprocess-files` into `wdired--preprocess-lines`,
>> which will `get-text-property` of the first char of each line in the
>> region to see if it's already been marked as `read-only`. If yes,
>> do nothing and if not, do what the old code did on that line.
>
> I tested, and currently I don't see any noticable slowdowns, even on
> that large directory. Dropping into wdired seems to be quite reactive
> and I can start editing any file name immidiately.
>
> However I can't seem to be able to get it work with permissions; I am
> not sure why. I have checked that wdired-allow-to-change-permissions is t.
>
> I have attached code as a separate file (I worked so). I can make a
> patch for wdired.el later, if you or someone can give me a tip why text
> props for permissions are not changing as they should.
I change my mind :-) I have tested with emacs -Q option, and I see same
behaviour with permission properties with original wdired code, so I
guess it works properly (or as buggy as original). Someone please test
it though.
Attached is a patch for wdired based on current master.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lazy-wdired.patch --]
[-- Type: text/x-patch, Size: 9518 bytes --]
From cddace1dae6cb9e4367f1fad3d7bd3745282824d Mon Sep 17 00:00:00 2001
From: Arthur Miller <arthur.miller@live.com>
Date: Wed, 17 Mar 2021 23:24:10 +0100
Subject: [PATCH] Make wdired lazy
---
lisp/wdired.el | 156 +++++++++++++++++++++++--------------------------
1 file changed, 74 insertions(+), 82 deletions(-)
diff --git a/lisp/wdired.el b/lisp/wdired.el
index c495d8de34..ba71306e66 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -250,20 +250,11 @@ wdired-change-to-wdired-mode
(setq buffer-read-only nil)
(dired-unadvertise default-directory)
(add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t)
+ (add-hook 'before-change-functions 'wdired--preprocess-line nil t)
(add-hook 'after-change-functions 'wdired--restore-properties nil t)
(setq major-mode 'wdired-mode)
(setq mode-name "Editable Dired")
(setq revert-buffer-function 'wdired-revert)
- ;; I temp disable undo for performance: since I'm going to clear the
- ;; undo list, it can save more than a 9% of time with big
- ;; directories because setting properties modify the undo-list.
- (buffer-disable-undo)
- (wdired-preprocess-files)
- (if wdired-allow-to-change-permissions
- (wdired-preprocess-perms))
- (if (fboundp 'make-symbolic-link)
- (wdired-preprocess-symlinks))
- (buffer-enable-undo) ; Performance hack. See above.
(set-buffer-modified-p nil)
(setq buffer-undo-list nil)
(run-mode-hooks 'wdired-mode-hook)
@@ -278,25 +269,33 @@ wdired-isearch-filter-read-only
;; Protect the buffer so only the filenames can be changed, and put
;; properties so filenames (old and new) can be easily found.
-(defun wdired-preprocess-files ()
- (put-text-property (point-min) (1+ (point-min))'front-sticky t)
- (save-excursion
- (goto-char (point-min))
- (let ((b-protection (point))
- (used-F (dired-check-switches dired-actual-switches "F" "classify"))
- filename)
- (while (not (eobp))
- (setq filename (dired-get-filename nil t))
- (when (and filename
- (not (member (file-name-nondirectory filename) '("." ".."))))
- (dired-move-to-filename)
- ;; The rear-nonsticky property below shall ensure that text preceding
- ;; the filename can't be modified.
- (add-text-properties
- (1- (point)) (point) `(old-name ,filename rear-nonsticky (read-only)))
- (put-text-property b-protection (point) 'read-only t)
- (dired-move-to-end-of-filename t)
- (put-text-property (point) (1+ (point)) 'end-name t))
+(defun wdired--preprocess-line (beg end)
+ "Preprocess current line under point to make it writable. "
+ (let ((inhibit-read-only t))
+ (unless (get-text-property (line-beginning-position) 'front-sticky)
+ (buffer-disable-undo)
+ (put-text-property (line-beginning-position) (1+
+ (line-beginning-position))
+ 'front-sticky t)
+ (save-excursion
+ (goto-char (line-beginning-position))
+ (let ((b-protection (point))
+ (used-F (dired-check-switches
+ dired-actual-switches "F" "classify"))
+ filename)
+ (setq filename (dired-get-filename nil t))
+ (when (and filename
+ (not (member (file-name-nondirectory filename) '("."
+ ".."))))
+ (dired-move-to-filename)
+ ;; The rear-nonsticky property below shall ensure that text
+ ;; preceding the filename can't be modified.
+ (add-text-properties
+ (1- (point)) (point)
+ `(old-name ,filename rear-nonsticky (read-only)))
+ (put-text-property b-protection (point) 'read-only t)
+ (dired-move-to-end-of-filename t)
+ (put-text-property (point) (1+ (point)) 'end-name t))
(when (and used-F (looking-at "[*/@|=>]$")) (forward-char))
(when (save-excursion
(and (re-search-backward
@@ -304,9 +303,51 @@ wdired-preprocess-files
(looking-at "l")
(search-forward " -> " (line-end-position) t)))
(goto-char (line-end-position)))
- (setq b-protection (point))
- (forward-line))
- (put-text-property b-protection (point-max) 'read-only t))))
+ (setq b-protection (point))
+ (put-text-property b-protection (line-end-position)
+ 'read-only t))
+
+ ;; Put a keymap property to the permission bits of the files,
+ ;; and store the original name and permissions as a property
+ (when wdired-allow-to-change-permissions
+ (goto-char (line-beginning-position))
+ (setq-local wdired-col-perm nil)
+ (when (and (not (looking-at dired-re-sym))
+ (wdired-get-filename)
+ (re-search-forward dired-re-perms
+ (line-end-position) 'eol))
+ (let ((begin (match-beginning 0))
+ (end (match-end 0)))
+ (unless wdired-col-perm
+ (setq wdired-col-perm (- (current-column) 9)))
+ (if (eq wdired-allow-to-change-permissions 'advanced)
+ (progn
+ (put-text-property begin end 'read-only nil)
+ ;; make first permission bit writable
+ (put-text-property
+ (1- begin) begin 'rear-nonsticky '(read-only)))
+ ;; avoid that keymap applies to text following permissions
+ (add-text-properties
+ (1+ begin) end
+ `(keymap ,wdired-perm-mode-map rear-nonsticky (keymap))))
+ (put-text-property end (1+ end) 'end-perm t)
+ (put-text-property
+ begin (1+ begin) 'old-perm (match-string-no-properties 0)))))
+
+ ;; Put the needed properties to allow the user to change
+ ;; links' targets
+ (when (fboundp 'make-symbolic-link)
+ (goto-char (line-beginning-position))
+ (when (looking-at dired-re-sym)
+ (re-search-forward " -> \\(.*\\)$")
+ (put-text-property (1- (match-beginning 1))
+ (match-beginning 1) 'old-link
+ (match-string-no-properties 1))
+ (put-text-property (match-end 1) (1+ (match-end 1)) 'end-link t)
+ (unless wdired-allow-to-redirect-links
+ (put-text-property (match-beginning 0)
+ (match-end 1) 'read-only t))))))
+ (buffer-enable-undo)))
;; This code is a copy of some dired-get-filename lines.
(defsubst wdired-normalize-filename (file unquotep)
@@ -369,7 +410,6 @@ wdired-get-filename
(and file (> (length file) 0)
(concat (dired-current-directory) file))))))
-
(defun wdired-change-to-dired-mode ()
"Change the mode back to dired."
(or (eq major-mode 'wdired-mode)
@@ -390,10 +430,10 @@ wdired-change-to-dired-mode
(remove-hook 'after-change-functions 'wdired--restore-properties t)
(setq-local revert-buffer-function 'dired-revert))
-
(defun wdired-abort-changes ()
"Abort changes and return to dired mode."
(interactive)
+ (remove-hook 'before-change-functions 'wdired--preprocess-line t)
(let ((inhibit-read-only t))
(erase-buffer)
(insert wdired-old-content)
@@ -709,23 +749,6 @@ wdired-previous-line
(current-column)))))
(dired-move-to-filename)))
-;; Put the needed properties to allow the user to change links' targets
-(defun wdired-preprocess-symlinks ()
- (let ((inhibit-read-only t))
- (save-excursion
- (goto-char (point-min))
- (while (not (eobp))
- (when (looking-at dired-re-sym)
- (re-search-forward " -> \\(.*\\)$")
- (put-text-property (1- (match-beginning 1))
- (match-beginning 1) 'old-link
- (match-string-no-properties 1))
- (put-text-property (match-end 1) (1+ (match-end 1)) 'end-link t)
- (unless wdired-allow-to-redirect-links
- (put-text-property (match-beginning 0)
- (match-end 1) 'read-only t)))
- (forward-line)))))
-
(defun wdired-get-previous-link (&optional old move)
"Return the next symlink target.
If OLD, return the old target. If MOVE, move point before it."
@@ -828,37 +851,6 @@ wdired-perm-mode-map
(define-key map [down-mouse-1] 'wdired-mouse-toggle-bit)
map))
-;; Put a keymap property to the permission bits of the files, and store the
-;; original name and permissions as a property
-(defun wdired-preprocess-perms ()
- (let ((inhibit-read-only t))
- (setq-local wdired-col-perm nil)
- (save-excursion
- (goto-char (point-min))
- (while (not (eobp))
- (when (and (not (looking-at dired-re-sym))
- (wdired-get-filename)
- (re-search-forward dired-re-perms (line-end-position) 'eol))
- (let ((begin (match-beginning 0))
- (end (match-end 0)))
- (unless wdired-col-perm
- (setq wdired-col-perm (- (current-column) 9)))
- (if (eq wdired-allow-to-change-permissions 'advanced)
- (progn
- (put-text-property begin end 'read-only nil)
- ;; make first permission bit writable
- (put-text-property
- (1- begin) begin 'rear-nonsticky '(read-only)))
- ;; avoid that keymap applies to text following permissions
- (add-text-properties
- (1+ begin) end
- `(keymap ,wdired-perm-mode-map rear-nonsticky (keymap))))
- (put-text-property end (1+ end) 'end-perm t)
- (put-text-property
- begin (1+ begin) 'old-perm (match-string-no-properties 0))))
- (forward-line)
- (beginning-of-line)))))
-
(defun wdired-perm-allowed-in-pos (char pos)
(cond
((= char ?-) t)
--
2.31.0
next prev parent reply other threads:[~2021-03-17 22:40 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 18:23 Partial wdired (edit just filename at the point) Arthur Miller
2021-03-17 1:18 ` Stefan Monnier
2021-03-17 2:21 ` Arthur Miller
2021-03-17 2:34 ` Stefan Monnier
2021-03-17 13:58 ` Arthur Miller
2021-03-17 14:09 ` Stefan Monnier
2021-03-17 19:56 ` Arthur Miller
2021-03-17 22:40 ` Arthur Miller [this message]
2021-03-18 2:10 ` Stefan Monnier
2021-03-18 10:26 ` Arthur Miller
2021-03-18 10:32 ` Thierry Volpiatto
2021-03-18 11:00 ` Arthur Miller
2021-03-18 11:11 ` Thierry Volpiatto
2021-03-18 11:46 ` Arthur Miller
2021-03-23 23:32 ` Michael Heerdegen
2021-03-18 14:21 ` Stefan Monnier
2021-03-19 11:15 ` Arthur Miller
2021-03-19 16:18 ` Stefan Monnier
2021-03-19 20:40 ` Sv: " arthur miller
2021-03-19 21:58 ` Stefan Monnier
2021-03-20 11:23 ` Sv: " arthur miller
2021-03-21 22:17 ` Tomas Hlavaty
2021-03-22 8:12 ` tomas
2021-03-22 12:44 ` Arthur Miller
2021-03-22 14:50 ` tomas
2021-03-22 13:11 ` Stefan Monnier
2021-03-22 20:08 ` Tomas Hlavaty
2021-03-22 20:28 ` Andreas Schwab
2021-03-22 21:00 ` Stefan Monnier
2021-03-22 21:52 ` Tomas Hlavaty
2021-03-22 22:16 ` Stefan Monnier
2021-03-22 22:39 ` Tomas Hlavaty
2021-03-22 23:27 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM9PR09MB4977DF19DEE399844CA6C28E966A9@AM9PR09MB4977.eurprd09.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.