[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Lazy wdired preprocessing
From: |
Stefan Monnier |
Subject: |
Re: [PATCH] Lazy wdired preprocessing |
Date: |
Fri, 26 Mar 2021 15:37:25 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> +(defvar wdired-perm-beg) ;; Column where the permission bits start
> +(defvar wdired-perm-end) ;; Column where the permission bits stop
I think this should use "--" in the names since they are internal variables.
> (setq mode-name "Editable Dired")
> - (add-function :override (local '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.
> + (setq revert-buffer-function 'wdired-revert)
> (set-buffer-modified-p nil)
This reverts part of my recent change to the way we set
`revert-buffer-function` (most likely an oversight while merging my changes).
> (setq buffer-undo-list nil)
> + ;; find one column with permissions and set permision text boundaries
> + (save-excursion
> + (goto-char (point-min))
> + (unless (re-search-forward dired-re-perms nil t 1)
> + (wdired-abort-changes)
> + (error "No files to be renamed - Exiting to Dired mode."))
> + (goto-char (match-beginning 0))
> + (setq-local wdired-perm-beg (current-column))
> + (goto-char (match-end 0))
> + (setq-local wdired-perm-end (current-column)))
I'd recommend you put this in a separate function.
> + (define-key wdired-mode-map [remap self-insert-command]
> #'wdired--self-insert)
Why is this done here instead of in the definition of `wdired-mode-map`?
> +(defun wdired--point-at-perms-p ()
> + (and (>= (current-column) wdired-perm-beg)
> + (<= (current-column) wdired-perm-end)))
`current-column` can be somewhat costly, so we should refrain from
calling it twice gratuitously. And here we can even take advantage of
the (rarely used and rarely applicable) multi-arg form of `<=` to fix
that "for free":
(<= wdired-perm-beg (current-column) wdired-perm-end)
> +(defun wdired--self-insert ()
> + (interactive)
> + (if (wdired--point-at-perms-p)
> + (when (not (get-text-property (line-beginning-position) 'front-sticky))
> + (wdired--before-change-fn (line-beginning-position)
> (line-end-position))
> + (setq unread-command-events (nconc (listify-key-sequence
> + (this-command-keys))
> + unread-command-events)))
> + (call-interactively 'self-insert-command)))
I think this deserves a comment about why we look at `front-sticky`.
Better yet: move this test to a helper function to which you can give
a meaningful name (like `wdired--processed-p`).
Also, instead of using `unread-command-events`, you can just call the
appropriate command directly, no?
> - (remove-hook 'kill-buffer-hook #'wdired-check-kill-buffer t)
> - (remove-hook 'after-change-functions #'wdired--restore-properties t)
> - (remove-function (local 'revert-buffer-function) #'wdired-revert))
> + (remove-hook 'kill-buffer-hook 'wdired-check-kill-buffer t)
> + (remove-hook 'before-change-functions 'wdired--before-change-fn t)
> + (remove-hook 'after-change-functions 'wdired--restore-properties t)
> + (setq-local revert-buffer-function 'dired-revert))
This also look like the merge wasn't done right.
> (defun wdired-abort-changes ()
> - "Abort changes and return to dired mode."
> + "Abort changes and return to dired mode. "
What happened here?
Stefan
- [PATCH] Lazy wdired preprocessing, Arthur Miller, 2021/03/25
- Re: [PATCH] Lazy wdired preprocessing, Stefan Kangas, 2021/03/26
- Re: [PATCH] Lazy wdired preprocessing,
Stefan Monnier <=
- Re: [PATCH] Lazy wdired preprocessing - BUG, Arthur Miller, 2021/03/27
- Re: [PATCH] Lazy wdired preprocessing - BUG, Stefan Monnier, 2021/03/27
- Re: [PATCH] Lazy wdired preprocessing - BUG, Arthur Miller, 2021/03/27