From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Arthur Miller <arthur.miller@live.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Lazy wdired preprocessing
Date: Fri, 26 Mar 2021 15:37:25 -0400 [thread overview]
Message-ID: <jwvy2e920mi.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <AM9PR09MB49779174BEE1FA612D22024896629@AM9PR09MB4977.eurprd09.prod.outlook.com> (Arthur Miller's message of "Thu, 25 Mar 2021 17:06:36 +0100")
> +(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
next prev parent reply other threads:[~2021-03-26 19:37 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-25 16:06 [PATCH] Lazy wdired preprocessing Arthur Miller
2021-03-25 23:09 ` Michael Heerdegen
2021-03-26 1:00 ` Arthur Miller
2021-03-26 3:27 ` Michael Heerdegen
2021-03-26 12:15 ` Arthur Miller
2021-03-26 12:21 ` Arthur Miller
2021-03-27 23:49 ` Michael Heerdegen
2021-03-28 1:51 ` Stefan Monnier
2021-03-28 1:56 ` Michael Heerdegen
2021-03-28 2:00 ` Stefan Monnier
2021-03-28 7:50 ` Sv: " arthur miller
2021-03-28 13:51 ` Stefan Monnier
2021-03-28 16:22 ` Sv: " arthur miller
[not found] ` <87y2e6242i.fsf@web.de>
2021-03-29 8:35 ` arthur miller
2021-03-26 10:18 ` Stefan Kangas
2021-03-26 19:37 ` Stefan Monnier [this message]
2021-03-27 7:39 ` Arthur Miller
2021-03-27 14:56 ` Stefan Monnier
2021-03-27 15:17 ` Arthur Miller
2021-03-27 15:56 ` Stefan Monnier
2021-03-27 17:01 ` Arthur Miller
2021-03-27 18:20 ` [PATCH] Lazy wdired preprocessing - BUG Arthur Miller
2021-03-27 18:32 ` Stefan Monnier
2021-03-27 18:50 ` Arthur Miller
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvy2e920mi.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).