[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Dired: Improve symmetry in mark/unmark commands bound to keys
From: |
Tino Calancha |
Subject: |
Dired: Improve symmetry in mark/unmark commands bound to keys |
Date: |
Sun, 25 Sep 2016 02:31:30 +0900 (JST) |
User-agent: |
Alpine 2.20 (DEB 67 2015-01-07) |
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 <address@hidden>
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
- Dired: Improve symmetry in mark/unmark commands bound to keys,
Tino Calancha <=
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Eli Zaretskii, 2016/09/24
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Andreas Schwab, 2016/09/24
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Eli Zaretskii, 2016/09/24
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Andreas Schwab, 2016/09/24
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Eli Zaretskii, 2016/09/24
- Re: Dired: Improve symmetry in mark/unmark commands bound to keys, Andreas Schwab, 2016/09/24
- RE: Dired: Improve symmetry in mark/unmark commands bound to keys, Drew Adams, 2016/09/24
- RE: Dired: Improve symmetry in mark/unmark commands bound to keys, Tino Calancha, 2016/09/25