all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Cc: 30285@debbugs.gnu.org
Subject: bug#30285: dired-do-chmod vs. top line of dired
Date: Tue, 30 Jan 2018 00:14:00 +0900	[thread overview]
Message-ID: <87efm8snnr.fsf@gmail.com> (raw)
In-Reply-To: <87mv0wg80c.fsf@jidanni.org> ("積丹尼 Dan Jacobson"'s message of "Mon, 29 Jan 2018 20:32:51 +0800")

積丹尼 Dan Jacobson <jidanni@jidanni.org> writes:

Thank you for your report.
> M runs the command dired-do-chmod.
> If used on the very top line of dired
> (the directory name,) it says:
> "Change mode of * [0 files] to: "
> which doesn't make a lot of sense.
Agreed.
> emacs-version "25.2.2"
>
> Same problem if used on the second line, (total...).
>
> (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?

--8<-----------------------------cut here---------------start------------->8---
commit 9b10f6ef6fbb3e6c50ffb04b97fc5b0b86d3e559
Author: tino calancha <tino.calancha@gmail.com>
Date:   Tue Jan 30 00:02:00 2018 +0900

    dired-do-chmod: Avoid unecessary prompt
    
    * lisp/dired-aux.el (dired-do-chmod): Offer to change mode just if
    there are any marked files or there is a file at point (Bug#30285).

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 55b68a372e..3868efe0c1 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)))
+  (when (or (cdr (dired-get-marked-files nil nil nil 'distinguish-1-marked))
+            (dired-get-filename t t))
+    (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)

--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 27.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
Repository revision: ea8c0e1b9eaa6651919fb4e039e3fcb5a1fa73db





  reply	other threads:[~2018-01-29 15:14 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 12:32 bug#30285: dired-do-chmod vs. top line of dired 積丹尼 Dan Jacobson
2018-01-29 15:14 ` Tino Calancha [this message]
2018-01-29 16:05   ` Eli Zaretskii
2018-01-29 23:21     ` Tino Calancha
2018-01-29 23:42       ` Drew Adams
2018-01-30  3:53         ` Tino Calancha
2018-01-30  4:43           ` Drew Adams
2018-01-30 15:15             ` Drew Adams
2018-01-31  9:49               ` Tino Calancha
2018-01-31 19:04                 ` Drew Adams
2018-01-31 21:35         ` Juri Linkov
2018-01-31 23:20           ` Drew Adams
2018-02-01  8:16           ` Tino Calancha
2018-02-01  9:17             ` Tino Calancha
2018-02-01 16:10             ` Drew Adams
2018-02-04 23:12               ` Tino Calancha
2018-02-05 16:45                 ` Drew Adams
2018-02-01 20:07             ` Juri Linkov
2018-02-01 20:50               ` Drew Adams
2018-02-01 21:35                 ` Juri Linkov
2018-02-01 22:23                   ` Drew Adams
2018-02-03 22:23                     ` Juri Linkov
2018-02-04 10:02                       ` martin rudalics
2018-02-04 21:44                         ` Juri Linkov
2018-02-06 21:32                         ` Juri Linkov
2018-02-04 23:08                   ` Tino Calancha
2018-02-05 21:01                     ` Juri Linkov
2018-02-05 21:52                       ` Drew Adams
2018-01-29 15:24 ` 積丹尼 Dan Jacobson
2018-01-29 23:14   ` Tino Calancha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87efm8snnr.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=30285@debbugs.gnu.org \
    --cc=jidanni@jidanni.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.