From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Arthur Miller Newsgroups: gmane.emacs.devel Subject: Re: Partial wdired (edit just filename at the point) Date: Wed, 17 Mar 2021 23:40:28 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12797"; 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: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 17 23:42:53 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 1lMesH-0002pE-O6 for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Mar 2021 23:42:45 +0100 Original-Received: from localhost ([::1]:54270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMesG-0002ii-Q1 for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Mar 2021 18:42:44 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMeqB-00082m-LQ for emacs-devel@gnu.org; Wed, 17 Mar 2021 18:40:36 -0400 Original-Received: from mail-oln040092072060.outbound.protection.outlook.com ([40.92.72.60]:3207 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMeq8-00021b-Kj for emacs-devel@gnu.org; Wed, 17 Mar 2021 18:40:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bpb64LdchDSuJaCunbE7BCEoLgIO6g4d/daMZeIoFXDCR+gPIzsfjz+fI5DrgzaB1lrj68aS2U+qjWIcxi5vEbSYElCD1ioZ7qMsrMF/3hV4Z3oKFKmgby18ks7EQg22j/JPnmmZt4+UEE4+L8D6Re+XHJT4N6IgBBjjIQ38k3hKTbSA3mwwUSmRSlR9i+oPG7QUG58qzerHaGi34uSlRCXdB3AxgkYukHdGR/Dj6ygF7JyH8NoJdiVvTn1NEoJV0rEQ4e4Peg+1azVEb2731j0sjlNKRTOkdZQbCXMhYCQaqUvvb5/linUrlAiKs3Ku6I/2cThZH1CxVir5/ASGiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/i6j8E75LJII/sTlWyEsPhyYppq3V2CBoa2Z4cwnFX0=; b=CHzPGy7bxw2rgTTrnbIrj5pe+L1VtU6FInaw7waD2TPBd7TIzxwOzBgxH32J3BWgmJmV8I/I6uNWkQ2ZsnNNIGx8rpfgCY2NVWW6FzLlMLy8NGU2QVud46YDoO2Uy/+3HzORny36Zm5QNOuWo5CF0M+D8yYz96foLEvFtet9fJbSwzOGGPhZGJ1jsuyXFV0QmsbkstPZHuJTN/t5/wEF4y/LpKz5f87xP5ctcZtBnMW1T0EHHIZDwAdRoxG3QYp+Vu7LWZAxUq5a8413FK+I2Vc8maimv6EKmiWS0Aw/9e+Q4upunx2gIIdMaVmswWxU3KsuPIFJ2cHN6MtDmC0D7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=live.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/i6j8E75LJII/sTlWyEsPhyYppq3V2CBoa2Z4cwnFX0=; b=TjniaHB55NuO0uvqv/v9EQ505oXeK2wz0+9GhOLPH2XbfeZXxxyL7jW3kdgkhQ6Ay2kx+cFMRTwRO+XeDxj85vO+5nZw4ijHEuG80jrRfaFe4OXuL7rQ6kBljM8eG5VUIPjoAt0vk1dbpU950mdGKccL8nt5mmoUq5XNcpjp6R8nkgEpAmqzKe3K+MzfbfK+al87DNQN+hGdZVPOY+bajPQ/L5NJH5dfIQh2OyO0ve/fx4D140eq/57j1UCZsdFbt9HYXnpZpAxsLItqRG7pan+29aLxS4tc/I1l8ek6ETkPDLbK6DlJCTkXaB3wgkaSiJWQNc1okTK0xWz+5hgEtQ== Original-Received: from AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e08::46) by AM5EUR03HT090.eop-EUR03.prod.protection.outlook.com (2a01:111:e400:7e08::248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 17 Mar 2021 22:40:29 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:7e08::52) by AM5EUR03FT052.mail.protection.outlook.com (2a01:111:e400:7e08::417) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 17 Mar 2021 22:40:29 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:D86732A3755E24FAE7E86688B43829219313CAFD7D2D2141A2A9CA0825D2DB73; UpperCasedChecksum:45BAC8C860600816D614ABF94B69B883073C61C82D7C4005D968D7E50A9B90D9; SizeAsReceived:7898; Count:46 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::2103:e705:bc0c:5a8b]) by AM9PR09MB4977.eurprd09.prod.outlook.com ([fe80::2103:e705:bc0c:5a8b%6]) with mapi id 15.20.3955.018; Wed, 17 Mar 2021 22:40:29 +0000 In-Reply-To: (Arthur Miller's message of "Wed, 17 Mar 2021 20:56:26 +0100") X-TMN: [qQcIn49G7JX1ztI8iaJEyHjJR0clN4tv] X-ClientProxiedBy: AM6P193CA0096.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::37) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87h7l9qu8z.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM6P193CA0096.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:88::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 17 Mar 2021 22:40:29 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 707b7c6d-ac2c-4f42-ea43-08d8e995aa6e X-MS-TrafficTypeDiagnostic: AM5EUR03HT090: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Iy+rr09IzMCZu5Bg0BzAa7EMYZ78qbfNCT6HGhDbJTigUO2K/1YPyxtdVFOdUbCkR/HC3nyCjkwQdjY24iIikYvfadbQRz1jUfCm4hvOHCWA3BoTYXRt80iyszuklQJrQpgq/zEZaVX6VOpRpR8zg9MuISoyT01YXBzm7xyXaowZSjlH3puV3R7udAHkPlrJudK7s9DBcoYVZ9y5QLD7jdlLWLer2d2GhXT71Z8vG86MOn/arABUwpLInPQw3+LXHmmA7xnc893RrEi6G3rf4e7Cg+O5tqY84eTIO7xsF7R13WfaiAAoqgsAelz2Q09CW4TJeYLDZ40LZWcz5LZHnQ0FPsB+I0yvaLhJgJ3YXcKEFM1VaVhX7rDVPANfDCi621kHzOXl+babaBNEnleJ7Q== X-MS-Exchange-AntiSpam-MessageData: Xx5YqOOpZFr52KP5Ex5fcJtRAv+am4Ol3AnHIrJjjWv6GqCOPXtD25xUEPXuJ2qs6JserjKNre/RI8BjcVGF1rrQyecn+Q0mW3k1uGcTxtWZsscycd9s4iATsTZicTZDQ0NkgzbSx/1LLNcnBKG7xQ== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: 707b7c6d-ac2c-4f42-ea43-08d8e995aa6e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2021 22:40:29.4427 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT052.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR03HT090 Received-SPF: pass client-ip=40.92.72.60; envelope-from=arthur.miller@live.com; helo=EUR03-VE1-obe.outbound.protection.outlook.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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:266537 Archived-At: --=-=-= Content-Type: text/plain Arthur Miller writes: > Stefan Monnier 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=lazy-wdired.patch >From cddace1dae6cb9e4367f1fad3d7bd3745282824d Mon Sep 17 00:00:00 2001 From: Arthur Miller 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 --=-=-=--