unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Dired: Improve symmetry in mark/unmark commands bound to keys
@ 2016-09-24 17:31 Tino Calancha
  2016-09-24 18:12 ` Eli Zaretskii
  2016-09-24 19:31 ` Andreas Schwab
  0 siblings, 2 replies; 31+ messages in thread
From: Tino Calancha @ 2016-09-24 17:31 UTC (permalink / raw)
  To: Emacs developers; +Cc: tino.calancha


Dear all,

in Dired we have several commmands for mark files
bound to keys (the order is irrelevant):
1) * /
2) * @
3) % m
4) % g
5) * *
6) * s
If you load `dired-x' you get more:
7) M-(
8) * .

From that list all but 6) and 8) will _unmark_ in an
interactive call with prefix argument.  That is, they mark
files or unmark them.
I have suggested in Bug#24518 that 8) should follow the same idiom
with no success :-(

Let's see my new proposal:

I) Add optional argument in 6) unflag-p to behave as the others.
II) Add a new command `dired-mark-or-unmark-extension', as
`dired-mark-extension' but, in interactive calls:
* A prefix argument _unmark_ files.
I propose to rebind '* .' to this command instead of the
`dired-mark-extension'.
After I) and II) we have an uniform behaviour for all
commands marking files which are bound to keys.  Powerful and easy
to remember.

What do you think?
Regards,
Tino

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From 33847d0f96356c6c09a78f391e27fa6a5b4f7628 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Sun, 25 Sep 2016 02:26:37 +0900
Subject: [PATCH] All Dired commands marking files, with prefix arg unmark

* lisp/dired-aux.el (dired-mark-subdir-files): Add optional
argument UNFLAG-P; if non-nil unmark files instead.
Save the point, call dired-mark-extension' but interactively with prefix arg
unmark files.  Rebind '*.' to this command.
(dired-mark-sexp): Say 'Unmark' in the prompt for interactive calls
with prefix arg.
---
  lisp/dired-aux.el | 11 +++++++----
  lisp/dired-x.el   | 28 ++++++++++++++++++++++++++--
  2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 9e0943a..a817f74 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2523,13 +2523,16 @@ dired-goto-subdir
  		(point)))))

  ;;;###autoload
-(defun dired-mark-subdir-files ()
+(defun dired-mark-subdir-files (&optional unflag-p)
    "Mark all files except `.' and `..' in current subdirectory.
+With prefix argument, unmark or unflag all those files.
  If the Dired buffer shows multiple directories, this command
  marks the files listed in the subdirectory that point is in."
-  (interactive)
-  (let ((p-min (dired-subdir-min)))
-    (dired-mark-files-in-region p-min (dired-subdir-max))))
+  (interactive "P")
+  (let ((dired-marker-char (or (and unflag-p ?\s) dired-marker-char))
+        (p-min (dired-subdir-min)))
+    (save-excursion
+      (dired-mark-files-in-region p-min (dired-subdir-max)))))

  ;;;###autoload
  (defun dired-kill-subdir (&optional remember-marks)
diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 7d73c42..0656b47 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -245,7 +245,7 @@ dired-mode-map
  (define-key dired-mode-map "*O" 'dired-mark-omitted)
  (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
  (define-key dired-mode-map "*(" 'dired-mark-sexp)
-(define-key dired-mode-map "*." 'dired-mark-extension)
+(define-key dired-mode-map "*." 'dired-mark-or-unmark-extension)
  (define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
  (define-key dired-mode-map "\M-G" 'dired-goto-subdir)
  (define-key dired-mode-map "F" 'dired-do-find-marked-files)
@@ -354,6 +354,26 @@ dired-mark-extension
             "\\)$")
     marker-char))

+(defun dired-mark-or-unmark-extension (extension &optional marker-char)
+  "Mark all files with a certain EXTENSION for use in later commands.
+With prefix argument, unmark or unflag all those files.
+A `.' is *not* automatically prepended to the string entered.
+EXTENSION may also be a list of extensions instead of a single one.
+Interactively, ask for EXTENSION."
+  (interactive
+   (list (read-string
+          (format "%s extension: "
+                  (if current-prefix-arg "Unmarking" "Marking")))
+         (and current-prefix-arg ?\s)))
+  (or (listp extension)
+      (setq extension (list extension)))
+  (dired-mark-files-regexp
+   (concat ".";; don't match names with nothing but an extension
+           "\\("
+           (mapconcat 'regexp-quote extension "\\|")
+           "\\)$")
+   marker-char))
+
  (defun dired-flag-extension (extension)
    "In Dired, flag all files with a certain EXTENSION for deletion.
  A `.' is *not* automatically prepended to the string entered."
@@ -1470,7 +1490,11 @@ dired-mark-sexp
    ;; (string-match "foo" sym) into which a user would soon fall.
    ;; Give `equal' instead of `=' in the example, as this works on
    ;; integers and strings.
-  (interactive "xMark if (lisp expr): \nP")
+  (interactive
+   (list (read--expression
+          (format "%s if (lisp expr): "
+                  (if current-prefix-arg "Unmark" "Mark")))
+         current-prefix-arg))
    (message "%s" predicate)
    (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))
          inode s mode nlink uid gid size time name sym)
-- 
2.9.3

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

In GNU Emacs 25.2.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.0)
  of 2016-09-25
Repository revision: 5ee56c4613e9380dbbe4bbaa97b29dd377e2134c



^ permalink raw reply related	[flat|nested] 31+ messages in thread
[parent not found: <<alpine.DEB.2.20.1609250230400.4103@calancha-pc>]

end of thread, other threads:[~2016-10-03 11:15 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-24 17:31 Dired: Improve symmetry in mark/unmark commands bound to keys Tino Calancha
2016-09-24 18:12 ` Eli Zaretskii
2016-09-24 18:25   ` Tino Calancha
2016-09-24 19:31 ` Andreas Schwab
2016-09-24 19:39   ` Eli Zaretskii
2016-09-24 19:46     ` Andreas Schwab
2016-09-24 19:58       ` Eli Zaretskii
2016-09-24 20:07         ` Andreas Schwab
2016-09-24 23:49           ` Drew Adams
2016-09-25  9:06             ` Tino Calancha
2016-09-25 18:55           ` John Wiegley
2016-09-26  9:23             ` Tino Calancha
2016-09-26 11:05               ` Tino Calancha
2016-09-26 15:02               ` Eli Zaretskii
2016-09-26 15:06               ` Eli Zaretskii
2016-09-26 15:47               ` John Wiegley
2016-09-26 16:30                 ` Tino Calancha
2016-09-26 19:02                   ` Eli Zaretskii
2016-10-03  9:21                     ` Tino Calancha
2016-10-03  9:54                       ` Eli Zaretskii
2016-10-03 11:15                         ` Tino Calancha
2016-09-26 21:52                   ` John Wiegley
2016-09-25 19:14           ` Eli Zaretskii
2016-09-25 22:43             ` Andreas Schwab
2016-09-25 22:58             ` Andreas Schwab
2016-09-25 23:00             ` Andreas Schwab
2016-09-26  2:38               ` Eli Zaretskii
2016-09-26  8:33                 ` Andreas Schwab
2016-09-26 14:59                   ` Eli Zaretskii
2016-09-24 19:49     ` Tino Calancha
     [not found] <<alpine.DEB.2.20.1609250230400.4103@calancha-pc>
     [not found] ` <<83oa3db20a.fsf@gnu.org>
2016-09-24 18:53   ` Drew Adams

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).