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: Partial wdired (edit just filename at the point) Date: Wed, 17 Mar 2021 22:10: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="30560"; 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 Thu Mar 18 03:11:26 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 1lMi8C-0007qW-KL for ged-emacs-devel@m.gmane-mx.org; Thu, 18 Mar 2021 03:11:24 +0100 Original-Received: from localhost ([::1]:34842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMi8B-0003P2-Ir for ged-emacs-devel@m.gmane-mx.org; Wed, 17 Mar 2021 22:11:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMi7R-0002y4-Bw for emacs-devel@gnu.org; Wed, 17 Mar 2021 22:10:37 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:17633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMi7K-00072h-WF for emacs-devel@gnu.org; Wed, 17 Mar 2021 22:10:36 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 2883C440AF9; Wed, 17 Mar 2021 22:10:29 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 5BDB5440A13; Wed, 17 Mar 2021 22:10:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1616033427; bh=3DV93oDZLzqRYbENlXvBifEBIS3WlWn6jWq+959bjxc=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Z0MRRH3xSnNvzEqi7wd6jbMWOc1SxV12F+TTRDsr0BxgiKpE0nTCojKaZFZSHDlzT iurfY0DxALtS2lSKP6d5WOWnq1ZIuMKQ6UvMSTL4jmCQZxhEdE9g1tSQNmULE/fQGl /DPYPk1Vkdt1VvVa2buKNp1ddkeO8YBsm5bNXdADlaEpaIe8IUAZYJ93ijZcnO5Vy0 QwORSi+JaKnFYzuiqnCijdjcpqtIv4yQE1RNCOYr8CN2hBjCYLBdZUthNG5/l4ICC+ zhUZH/vUzlzH94giboZGXXvlm5Pb0MaqfVqzLL/tZU2fik8c1Cdcq9Q1zkBTp0E7eH uV7Uz6ZssbQnQ== Original-Received: from alfajor (unknown [216.154.43.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id F249B1203E4; Wed, 17 Mar 2021 22:10:26 -0400 (EDT) In-Reply-To: (Arthur Miller's message of "Wed, 17 Mar 2021 23:40:28 +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:266540 Archived-At: Hi, These changes are looking quite good. There are a few things to fix before we can install it, tho: > 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) [ Nitpick: Please use #' rather than ' to quote functions (I know the rest of the code here doesn't (yet), but we should move towards more systematic use of #' so as to better catch obsolete functions and other issues). ] > +(defun wdired--preprocess-line (beg end) > + "Preprocess current line under point to make it writable. " This is incorrect: what it *should* do is to preprocess an area that covers BEG..END. That's why I suggested to name it "...lines" rather than "...line" ;-) And the "current point" is not really relevant (it will *usually* be in the vicinity, but not always). > + (let ((inhibit-read-only t)) > + (unless (get-text-property (line-beginning-position) 'front-sticky) > + (buffer-disable-undo) As you can guess from the previous comment, we should loop over BEG...END to process all the lines involved. Also, I recommend you use `with-silent-modifications` which will cover both `inhibit-read-only` and the undo (and a few more potential problems, which admittedly should hopefully not matter here). [ That macro didn't exist back when wdired.el was written. ] > @@ -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))) To minimize code changes (and to avoid making such a large function (which are sadly frequent in Emacs's code base)), I think you can keep the `wdired-preprocess-perms` and `wdired-preprocess-symlinks` (tho you'll want to change them by making them take the beg..end arguments.) and call them from here instead of moving their code into this new function. Stefan