unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 22457@debbugs.gnu.org
Subject: bug#22457: 24.5; [PATCH] `dired-mark-if' should not count non-changes
Date: Tue, 25 Jun 2019 08:33:14 -0700 (PDT)	[thread overview]
Message-ID: <cc9a652c-1fe7-4abb-b227-706dbda937b5@default> (raw)
In-Reply-To: <m3ef3h7mlo.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 2338 bytes --]

> > Here is a fixed version of the macro.  The diff is trivial.
> 
> No diff was included, which, as usual, is a shame, because the macro has
> changed slightly in the meantime.

That makes no difference. ;-)  And the diff is still
trivial. ("The macro has changed slightly" == ?\040
became ?\s.  Nothing more)

> Your lines are also too wide; they should be less than 80 characters
> wide.

Oh, lines 92 chars are too wide for dired.el?
Then why does it have lots of lines wider than
80 chars, including lines up to 103 chars wide?

> Could you re-spin your change and submit a patch?

diff -u dired.el dired-2019-06-25a-patched.el
--- dired.el	2019-06-25 07:57:35.886354900 -0700
+++ dired-2019-06-25a-patched.el	2019-06-25 08:09:23.058466400 -0700
@@ -538,7 +538,7 @@
 ;;; Macros must be defined before they are used, for the byte compiler.
 
 (defmacro dired-mark-if (predicate msg)
-  "Mark all files for which PREDICATE evals to non-nil.
+  "Mark files for PREDICATE, according to `dired-marker-char'.
 PREDICATE is evaluated on each line, with point at beginning of line.
 MSG is a noun phrase for the type of files being marked.
 It should end with a noun that can be pluralized by adding `s'.
@@ -558,13 +558,11 @@
 		   "")))
       (goto-char (point-min))
       (while (not (eobp))
-        (if ,predicate
-            (progn
-              (delete-char 1)
-              (insert dired-marker-char)
-              (setq count (1+ count))))
+        (when ,predicate
+          (unless (looking-at-p (char-to-string dired-marker-char))
+            (delete-char 1) (insert dired-marker-char) (setq count (1+ count))))
         (forward-line 1))
-      (if ,msg (message "%s %s%s %s%s."
+      (when ,msg (message "%s %s%s %s%s"
                         count
                         ,msg
                         (dired-plural-s count)

----

Actually, the _attached_ definition is much better than
this - it's what I use in `dired+.el'.  The value returned
and the message indicate both the number matched and the
number changed.  And it has optional arg PLURAL, for
irregular plurals (e.g. "directories").

But if you want this one you'll have to do your own line
shortening, `diff', and adjustment of any callers you
might to want to pass an irregular PLURAL form.

[-- Attachment #2: throw-dired-mark-if.el --]
[-- Type: application/octet-stream, Size: 2330 bytes --]

;; 1. Value returned and message indicate both the number matched and the number changed.
;; 2. Added optional arg PLURAL, for irregular plurals (e.g. "directories").
;;
(defmacro dired-mark-if (predicate singular &optional plural)
  "Mark files for PREDICATE, according to `dired-marker-char'.
PREDICATE is evaluated on each line, with point at beginning of line.
SINGULAR is a singular noun phrase for the type of files being marked.
Optional arg PLURAL is a plural noun phrase for the type of files
 being marked.
If PLURAL is nil then SINGULAR should end with a noun that can be
pluralized by adding `s'.

Return nil if no files matched PREDICATE.
Otherwise return a cons (CHANGED . MATCHED), where:
 CHANGED is the number of markings that were changed by the operation.
 MATCHED is the number of files that matched PREDICATE."
  `(let ((inhibit-read-only  t)
         changed matched)
     (save-excursion
       (setq matched  0
             changed  0)
       (when ,singular (message "%s %s%s..."
                                (cond ((eq dired-marker-char ?\040)            "Unmarking")
                                      ((eq dired-del-marker dired-marker-char) "Flagging")
                                      (t                                       "Marking"))
                                (or ,plural  (concat ,singular "s"))
                                (if (eq dired-del-marker dired-marker-char) " for deletion" "")))
       (goto-char (point-min))
       (while (not (eobp))
         (when ,predicate
           (setq matched  (1+ matched))
           (unless (diredp-looking-at-p (char-to-string dired-marker-char))
             (delete-char 1) (insert dired-marker-char) (setq changed  (1+ changed))))
         (forward-line 1))
       (when ,singular (message "%s %s%s%s newly %s%s"
                                matched
                                (if (= matched 1) ,singular (or ,plural  (concat ,singular "s")))
                                (if (not (= matched changed)) " matched, " "")
                                (if (not (= matched changed)) changed "")
                                (if (eq dired-marker-char ?\040) "un" "")
                                (if (eq dired-marker-char dired-del-marker) "flagged" "marked"))))
     (and (> matched 0)  (cons changed matched))))

  reply	other threads:[~2019-06-25 15:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-24 18:05 bug#22457: 24.5; [PATCH] `dired-mark-if' should not count non-changes Drew Adams
2019-06-25 14:42 ` Lars Ingebrigtsen
2019-06-25 15:33   ` Drew Adams [this message]
2019-06-25 15:44     ` Lars Ingebrigtsen
2019-06-25 22:47       ` Michael Heerdegen
2019-06-25 22:53         ` Lars Ingebrigtsen
2019-06-25 23:02           ` Michael Heerdegen
2019-06-25 23:12             ` Lars Ingebrigtsen
2019-06-25 23:26             ` Drew Adams
2019-06-25 23:30               ` Michael Heerdegen
2019-06-26  0:00                 ` Drew Adams
2019-06-26  8:50               ` Andreas Schwab
2019-06-26 13:32                 ` Drew Adams
2019-06-25 23:17         ` Drew Adams
2019-06-25 23:28           ` Michael Heerdegen
2019-06-25 15:46     ` Lars Ingebrigtsen
2019-06-25 16:06       ` Drew Adams

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=cc9a652c-1fe7-4abb-b227-706dbda937b5@default \
    --to=drew.adams@oracle.com \
    --cc=22457@debbugs.gnu.org \
    --cc=larsi@gnus.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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).