From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Lazy wdired preprocessing Date: Fri, 26 Mar 2021 15:37:25 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16391"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Arthur Miller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Mar 26 20:42:00 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lPsLH-00047Y-UN for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Mar 2021 20:41:59 +0100 Original-Received: from localhost ([::1]:53678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPsLG-0001U1-Qp for ged-emacs-devel@m.gmane-mx.org; Fri, 26 Mar 2021 15:41:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsGz-00069H-Ej for emacs-devel@gnu.org; Fri, 26 Mar 2021 15:37:33 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:10632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPsGw-0000y8-Oy for emacs-devel@gnu.org; Fri, 26 Mar 2021 15:37:32 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 34DE5100241; Fri, 26 Mar 2021 15:37:28 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 6825110021B; Fri, 26 Mar 2021 15:37:26 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1616787446; bh=2S1w0JIOkXisUhoah+bxvCYD4G4zE42gQfgDVVlgdgs=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=NnTBaUzw0JRV9lOnb/d+MYG4bnpyKPPYZuvHMuI+BKhp0vI0WtrRdsi67NWDQifGI ALVlsagK9NFrkS4Y1DT1LTswmY5CPdLEv+X5psqu4OHqFuIRmDsCGi8yUkR1B3293z W9SkKcKYlr9q8Uh/am4h413PN8Shu8LzYFhCJ0NvlaB1244PemA+WF2Yy3V8ms8Ffy TZ2Y2aYvpyYAGKHvBl14CaqgvzaRNP6Iv0e/WJrbMYUvvkxYcNYIh4x+mtFi2X3jmb vzoTi7jJwRi23LFtkQC/nH0TOSm5ASXVl04XMmxRHfvAWC9BsehhukTlMy50pMt/l0 BY++B6eH8zcNw== Original-Received: from alfajor (unknown [216.154.43.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 33F4E1203E5; Fri, 26 Mar 2021 15:37:26 -0400 (EDT) In-Reply-To: (Arthur Miller's message of "Thu, 25 Mar 2021 17:06:36 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:267085 Archived-At: > +(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