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 20:56:26 +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="24545"; 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 21:13:34 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 1lMcXs-0006G6-2J for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Mar 2021 21:13:32 +0100 Original-Received: from localhost ([::1]:36480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMcXr-0005tZ-4i for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Mar 2021 16:13:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMcW5-0004Ud-8t for emacs-devel@gnu.org; Wed, 17 Mar 2021 16:11:41 -0400 Original-Received: from mail-vi1eur06olkn2040.outbound.protection.outlook.com ([40.92.17.40]:32641 helo=EUR06-VI1-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 1lMcW0-0001DW-Dv for emacs-devel@gnu.org; Wed, 17 Mar 2021 16:11:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j3B6L44vNbur7SJOBKYmnRmnVpn/Yi+A23iNfrh4M3tUV7vvwQZEqyds03XMuVznygAAiIhaJ69NeqV05bsL58+MxNnVtNRo5tSD8xVa9ebS7q3G8ACNEpYm8IyItnjwX4WQAYZYEmfcIOEkiiO1xsmmAeDZiyv22hrxLqqKGm/cvOaBKNGjytfB0gNthblw3zo6qRcROqf/Nl92PitqTiBts0Cv+f4WMY5D18hgaeNFz1crM4OsOTZxXzCs1kFLDfTtZNjF0fpXjCdE4DB74tn21SK8zXFkuk3r2pnsWulhBgNBQ8pDxRxx2O723p5lenUnqPpMlOtjHOj66izf5Q== 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=Ww53tby9mpiyf2ntzb8H50w2Jx4mACLUrbOxf1NNmVo=; b=eRgme7LMP0V5dc3/IXRXNAlfZ4shwei0A10H1C3TUxLYRIbB11zCm3TnZLLIv5zH/Qs+TFvuC0pwSejAiGFE0bTAeLbOUE6hAzXHvrjIiaUbwjWhBxxAoCPeSfcPPRALGEM1fcI9oPMgY+VftUHytpMeH98aNH1a9q38A6A3pa4FxOepezCWJd7hn72doGwDnAgE61NLzb3OhI2v49ZjgVNB+E637baZn7SRb+zQzaoLBQG84BSLUDKCyfLGOmD21qb8hxqqnD5A5+iRSnKU4na42/UW1W7mmzvnK7oR2dmrRX9Kuj8/3aZKo62jrdonvI28YQbiyGb6uqaeLqEcpg== 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=Ww53tby9mpiyf2ntzb8H50w2Jx4mACLUrbOxf1NNmVo=; b=cDjT6QpVKi7fblMRN/S4x0oJ7k418jHRFK3iOE+b0sfMfu4JZ0qoEmIYON4RsogA39tTK1eYprxBEBFH059wPYtvbnqrPC+UjepF2PA8C1Mma10epBwwKMGJFPu6dzlxqxDUHtGHKRaTjPLtbHs7SVnMFYX8/UBP9VjUiRvqcu3kqcfLOZuyOb3dJlcUwYqjwg9/9yb4Z3WnPDtSx7HThLp+N161K0W2Io2e+MKu1NuLYhI1PREkUqzg7SMRno5ATnQyQ4ypICzDVsL37qDjZiG/Bg6+8oVd1AT4UgSsAs/5vsoeJ4GFX8ktxlfGwSBpwpFBFfDbwnRdsVXwjEM/lg== Original-Received: from DB8EUR06FT009.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::52) by DB8EUR06HT172.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc35::504) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3933.31; Wed, 17 Mar 2021 19:56:27 +0000 Original-Received: from AM9PR09MB4977.eurprd09.prod.outlook.com (2a01:111:e400:fc35::53) by DB8EUR06FT009.mail.protection.outlook.com (2a01:111:e400:fc35::62) 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 19:56:27 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:067DCE0859324C7C28241CA1314BC52ADA64C1D60197935C6162836BFEB9A8CB; UpperCasedChecksum:2B6A408DF782BA8A80EFDF02B41DAEE35913B332CF01AFA626A2CD1A9C5E19AC; SizeAsReceived:7766; 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 19:56:26 +0000 In-Reply-To: (Stefan Monnier's message of "Wed, 17 Mar 2021 10:09:22 -0400") X-TMN: [z0imZWOS76OsmGOwYbKvu5/v4LBbtYb4] X-ClientProxiedBy: AM6P193CA0047.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::24) To AM9PR09MB4977.eurprd09.prod.outlook.com (2603:10a6:20b:304::20) X-Microsoft-Original-Message-ID: <87lfalr1ud.fsf@live.com> X-MS-Exchange-MessageSentRepresentingType: 1 Original-Received: from pascal.homepc (90.230.29.56) by AM6P193CA0047.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:8e::24) 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 19:56:26 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: a124d84b-50cd-4c75-ae06-08d8e97ebfd4 X-MS-TrafficTypeDiagnostic: DB8EUR06HT172: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MD0qV9G5Yi9p8+G3phPRPTuT2d6ccKOoXHq0C7DWAIKAv0JIWBNr5ZiU3xxWbXWmi9ddIjEiQMlx5xIw9EnC0yHL3MyCWiBdvS76RVycDqiiPra0qV5+m7vsb8i+1suGFRSPQztarT9uDpVWx90PwXac4boS8oQ5mhk1uyGYDGX800yI55UBMWWqwZhvfvGdJ58RFDGFAjotHv1p1qD3xME+HleAufKgRY5/LNjFFZwTSH9DygAEaO1YPkWUy1tuvKlM6s5xqiO0KxhYQ8t5LVU4hluyEaB8sWrZV79bYJwzm44FfpiKwaCdvEIjxLUv3G53jcTMCsyh1BfxQS9JDk34LD3xfz21gjPDAby1PlUd0h86uRdf03VhHfFyVPYUkl+VjvFmttJve4TUdOT/Jg== X-MS-Exchange-AntiSpam-MessageData: hgcCiAqWp7xvM3NmZVIAZzkChKdwEsR5h1NWy7oKWNB3FCYytR+/vkHMXE8VzoHYFob2P35FJPMwpltK1Be1Urs9xF2OXHq07XH19+HHHoHIrv2CQX8CJuLX+tkBJDfrk4di3YUcbuvrTFGEFSkbIA== X-OriginatorOrg: live.com X-MS-Exchange-CrossTenant-Network-Message-Id: a124d84b-50cd-4c75-ae06-08d8e97ebfd4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2021 19:56:26.9359 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB8EUR06FT009.eop-eur06.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: DB8EUR06HT172 Received-SPF: pass client-ip=40.92.17.40; envelope-from=arthur.miller@live.com; helo=EUR06-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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:266531 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=partial-wdired.el ;;; partial-wdired.el --- -*- lexical-binding: t; -*- ;; Copyright (C) 2020 Arthur Miller ;; Author: Arthur Miller ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;;; Enable editing of file name and properties only at the point. ;;; Code: (require 'wdired) ;;;###autoload (defun wdired-change-to-partial-wdired-mode () "Put a Dired buffer in Writable Dired (WDired) mode. \\ In WDired mode, you can edit the names of the files in the buffer, the target of the links, and the permission bits of the files. After typing \\[wdired-finish-edit], Emacs modifies the files and directories to reflect your edits. See `wdired-mode'." (interactive) (unless (derived-mode-p 'dired-mode) (error "Not a Dired buffer")) (setq-local wdired-old-content (buffer-substring (point-min) (point-max))) (setq-local wdired-old-marks (dired-remember-marks (point-min) (point-max))) (setq-local wdired-old-point (point)) (setq-local query-replace-skip-read-only t) (add-function :after-while (local 'isearch-filter-predicate) #'wdired-isearch-filter-read-only) (use-local-map wdired-mode-map) (force-mode-line-update) (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) (set-buffer-modified-p nil) (setq buffer-undo-list nil) (run-mode-hooks 'wdired-mode-hook) (message "%s" (substitute-command-keys "Press \\[wdired-finish-edit] when finished \ or \\[wdired-abort-changes] to abort changes"))) (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 dired-permission-flags-regexp nil t) (looking-at "l") (search-forward " -> " (line-end-position) t))) (goto-char (line-end-position))) (setq b-protection (point)) (put-text-property b-protection (line-end-position) 'read-only t)) (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))))) (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))) (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) (goto-char wdired-old-point)) (wdired-change-to-dired-mode) (set-buffer-modified-p nil) (setq buffer-undo-list nil) (message "Changes aborted")) (provide 'partial-wdired) --=-=-=--