From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#30285: dired-do-chmod vs. top line of dired Date: Tue, 30 Jan 2018 08:21:36 +0900 Message-ID: <87d11sl08v.fsf@gmail.com> References: <87mv0wg80c.fsf@jidanni.org> <87efm8snnr.fsf@gmail.com> <83efm8irac.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1517268027 27628 195.159.176.226 (29 Jan 2018 23:20:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Jan 2018 23:20:27 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 30285@debbugs.gnu.org, jidanni@jidanni.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 30 00:20:22 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egIin-0006Yb-Jc for geb-bug-gnu-emacs@m.gmane.org; Tue, 30 Jan 2018 00:20:17 +0100 Original-Received: from localhost ([::1]:47654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egIko-0000vx-Cp for geb-bug-gnu-emacs@m.gmane.org; Mon, 29 Jan 2018 18:22:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1egIkY-0000ti-0c for bug-gnu-emacs@gnu.org; Mon, 29 Jan 2018 18:22:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1egIkU-0002hJ-R4 for bug-gnu-emacs@gnu.org; Mon, 29 Jan 2018 18:22:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40451) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1egIkU-0002hC-NV for bug-gnu-emacs@gnu.org; Mon, 29 Jan 2018 18:22:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1egIkU-0001wN-Hq for bug-gnu-emacs@gnu.org; Mon, 29 Jan 2018 18:22:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 29 Jan 2018 23:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 30285 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 30285-submit@debbugs.gnu.org id=B30285.15172681117427 (code B ref 30285); Mon, 29 Jan 2018 23:22:02 +0000 Original-Received: (at 30285) by debbugs.gnu.org; 29 Jan 2018 23:21:51 +0000 Original-Received: from localhost ([127.0.0.1]:48346 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egIkJ-0001vj-00 for submit@debbugs.gnu.org; Mon, 29 Jan 2018 18:21:51 -0500 Original-Received: from mail-pf0-f172.google.com ([209.85.192.172]:39263) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1egIkH-0001vO-8i for 30285@debbugs.gnu.org; Mon, 29 Jan 2018 18:21:49 -0500 Original-Received: by mail-pf0-f172.google.com with SMTP id e11so6848063pff.6 for <30285@debbugs.gnu.org>; Mon, 29 Jan 2018 15:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=WPBlMWkUJ19fpjvkt+/rp1Iu/ZEo3Exyfonhrabb6O4=; b=AJSyM2QRmT7Z3IKjkkE+s7r9pRt3p536bVSx1Fr3++bK5jugsLAMCQOEARKmGkn6iW AmFoKgyzoT4z7npuaT75LU62nfzQJdr1ztEcBpwgTkxOvv6hSJnCmlgE8XUvlnSWCO4/ nynWa0P5F2RJW9LTG55HNUS2tyW6k05quUmvqkl3hlwk/Mm9z6AT7ihfc/W5RWnwJZMv MXbP5/IOdLY7VyRGkLymII72KLUzO/0vdfZYDQA/e/7ZYQWL6LGCDXt56KKHBaTwzOlF DeB0KSDKeeXdom4h2JVgv4QEn40+6wflRozrs7McwGUsU1I+fj9ZVz1bvcUHqNX9Slx+ lh2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=WPBlMWkUJ19fpjvkt+/rp1Iu/ZEo3Exyfonhrabb6O4=; b=hCFYiNQ7jhqGTNBjsBS2XsX5SJ3ZFXOBlF/+/0C3tosPSUiQcBy7HsMCl+PGwaHlsc +7L5PQldg03rGRGYm48ZsetC+3zAbmdNAMOGY67uVgxLetNW5bNSHnY7jWkTxpuD1yb+ z9Dqhq+QV+IkIIJFZG4WJexXcRc+noPcPZ9fTscOwSnBHBxi0FkXhilax5THLSfQtdGN 9IMJhQ/Vqo5TR9HzqaBl4Tk4yyFa6p2x0tuCFtWAYWMrOHf8oSaI1JInsSUDNBCQq+PE KpKblHA8QNtf5u71ugGWXz/HPjtCpCOm04OYy7/aEWxQZC0Xbk/QXOh0TUtHdO9P9+ij Nrnw== X-Gm-Message-State: AKwxytfjfLSHZH/QfDazZeCvylXrxvLrO9mLV9Hy6jbullOjKNj1t/f5 nepSYBIVz5jzWiv8I0GrIFY= X-Google-Smtp-Source: AH8x226K3/j3ugx+IVoAYvV2ihzQfh9+vqnwJpco1jStiR0mLrQOjaija+tqPnGwDBXTdyKRGVCNNA== X-Received: by 2002:a17:902:51e9:: with SMTP id y96-v6mr3589040plh.344.1517268103418; Mon, 29 Jan 2018 15:21:43 -0800 (PST) Original-Received: from calancha-pc (FL1-125-193-170-29.tky.mesh.ad.jp. [125.193.170.29]) by smtp.gmail.com with ESMTPSA id l88sm35748018pfb.149.2018.01.29.15.21.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 29 Jan 2018 15:21:42 -0800 (PST) In-Reply-To: <83efm8irac.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 29 Jan 2018 18:05:47 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:142671 Archived-At: Eli Zaretskii writes: >> From: Tino Calancha >> Date: Tue, 30 Jan 2018 00:14:00 +0900 >> Cc: 30285@debbugs.gnu.org >> >> > (Why doesn't it just complain "can't operate on" like it does for the >> > third line, ".".) >> Following patch just do nothing in these cases. That's OK for me. >> Do you prefer to inform the user in this case that there is no file >> to change the mode? > > Yes, I think we should produce some message in these cases. OK. Then, we must adjust other siblings commands (dired-do-chgrp, dired-do-chown); otherwise they might become jealous. I propose to add a new predicate `dired-marked-files-or-file-at-point-p', and used it in all those commands. --8<-----------------------------cut here---------------start------------->8--- commit a66d02f56f3b1019009c21997b0064f1fb26a03f Author: tino calancha Date: Tue Jan 30 08:18:07 2018 +0900 dired-do-chmod: Avoid unecessary prompt Prompt user only if there are any marked files or a file at point (Bug#30285). * lisp/dired.el (dired-marked-files-or-file-at-point-p): New defun. * lisp/dired-aux.el (dired-do-chmod) (dired-do-chmod, dired-do-chgrp, dired-do-chown): Use it. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 55b68a372e..02febbe570 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -361,40 +361,42 @@ dired-do-chmod Type M-n to pull the file attributes of the file at point into the minibuffer." (interactive "P") - (let* ((files (dired-get-marked-files t arg)) - ;; The source of default file attributes is the file at point. - (default-file (dired-get-filename t t)) - (modestr (when default-file - (nth 8 (file-attributes default-file)))) - (default - (and (stringp modestr) - (string-match "^.\\(...\\)\\(...\\)\\(...\\)$" modestr) - (replace-regexp-in-string - "-" "" - (format "u=%s,g=%s,o=%s" - (match-string 1 modestr) - (match-string 2 modestr) - (match-string 3 modestr))))) - (modes (dired-mark-read-string - "Change mode of %s to: " - nil 'chmod arg files default)) - num-modes) - (cond ((or (equal modes "") - ;; Use `eq' instead of `equal' - ;; to detect empty input (bug#12399). - (eq modes default)) - ;; We used to treat empty input as DEFAULT, but that is not - ;; such a good idea (Bug#9361). - (error "No file mode specified")) - ((string-match-p "^[0-7]+" modes) - (setq num-modes (string-to-number modes 8)))) - - (dolist (file files) - (set-file-modes - file - (if num-modes num-modes - (file-modes-symbolic-to-number modes (file-modes file))))) - (dired-do-redisplay arg))) + (if (not (dired-marked-files-or-file-at-point-p)) + (user-error "No marked files") + (let* ((files (dired-get-marked-files t arg)) + ;; The source of default file attributes is the file at point. + (default-file (dired-get-filename t t)) + (modestr (when default-file + (nth 8 (file-attributes default-file)))) + (default + (and (stringp modestr) + (string-match "^.\\(...\\)\\(...\\)\\(...\\)$" modestr) + (replace-regexp-in-string + "-" "" + (format "u=%s,g=%s,o=%s" + (match-string 1 modestr) + (match-string 2 modestr) + (match-string 3 modestr))))) + (modes (dired-mark-read-string + "Change mode of %s to: " + nil 'chmod arg files default)) + num-modes) + (cond ((or (equal modes "") + ;; Use `eq' instead of `equal' + ;; to detect empty input (bug#12399). + (eq modes default)) + ;; We used to treat empty input as DEFAULT, but that is not + ;; such a good idea (Bug#9361). + (error "No file mode specified")) + ((string-match-p "^[0-7]+" modes) + (setq num-modes (string-to-number modes 8)))) + + (dolist (file files) + (set-file-modes + file + (if num-modes num-modes + (file-modes-symbolic-to-number modes (file-modes file))))) + (dired-do-redisplay arg)))) ;;;###autoload (defun dired-do-chgrp (&optional arg) @@ -404,7 +406,9 @@ dired-do-chgrp (interactive "P") (if (memq system-type '(ms-dos windows-nt)) (error "chgrp not supported on this system")) - (dired-do-chxxx "Group" "chgrp" 'chgrp arg)) + (if (not (dired-marked-files-or-file-at-point-p)) + (user-error "No marked files") + (dired-do-chxxx "Group" "chgrp" 'chgrp arg))) ;;;###autoload (defun dired-do-chown (&optional arg) @@ -414,7 +418,9 @@ dired-do-chown (interactive "P") (if (memq system-type '(ms-dos windows-nt)) (error "chown not supported on this system")) - (dired-do-chxxx "Owner" dired-chown-program 'chown arg)) + (if (not (dired-marked-files-or-file-at-point-p)) + (user-error "No marked files") + (dired-do-chxxx "Owner" dired-chown-program 'chown arg))) ;;;###autoload (defun dired-do-touch (&optional arg) @@ -423,7 +429,9 @@ dired-do-touch Type M-n to pull the file attributes of the file at point into the minibuffer." (interactive "P") - (dired-do-chxxx "Timestamp" dired-touch-program 'touch arg)) + (if (not (dired-marked-files-or-file-at-point-p)) + (user-error "No marked files") + (dired-do-chxxx "Timestamp" dired-touch-program 'touch arg))) ;; Process all the files in FILES in batches of a convenient size, ;; by means of (FUNCALL FUNCTION ARGS... SOME-FILES...). diff --git a/lisp/dired.el b/lisp/dired.el index eade11bc7f..79486c8b8e 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -2385,6 +2385,11 @@ dired-get-filename (t (concat (dired-current-directory localp) file))))) +(defun dired-marked-files-or-file-at-point-p () + "Return non-nil if there are marked files or a file at point." + (and (or (cdr (dired-get-marked-files nil nil nil 'distinguish-1-marked)) + (dired-get-filename nil 'no-error)) t)) + (defun dired-string-replace-match (regexp string newtext &optional literal global) "Replace first match of REGEXP in STRING with NEWTEXT. --8<-----------------------------cut here---------------end--------------->8--- In GNU Emacs 27.0.50 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) Repository revision: 29abae3572090a86beedb66822ccf34356c8a00c