* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
@ 2016-02-27 14:27 Tino Calancha
2016-02-28 5:36 ` Lars Ingebrigtsen
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-02-27 14:27 UTC (permalink / raw)
To: 22828
[-- Attachment #1: Type: text/plain, Size: 325 bytes --]
dired-mark-files-regexp checks the NAME of a symbolic link.
Its useful to introduce one function which look for a match
in the TARGET of the symbolic links.
Such function could be bound to '%@'.
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29)
Repository revision: 25c5651951ef39f650927652dac8b4bbfccb60fa
[-- Attachment #2: Type: text/plain, Size: 2475 bytes --]
diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..5f7a484 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1493,6 +1493,7 @@ dired-mode-map
(define-key map "%d" 'dired-flag-files-regexp)
(define-key map "%g" 'dired-mark-files-containing-regexp)
(define-key map "%m" 'dired-mark-files-regexp)
+ (define-key map "%@" 'dired-mark-symlinks-regexp)
(define-key map "%r" 'dired-do-rename-regexp)
(define-key map "%C" 'dired-do-copy-regexp)
(define-key map "%H" 'dired-do-hardlink-regexp)
@@ -1730,6 +1731,9 @@ dired-mode-map
(define-key map [menu-bar regexp flag]
'(menu-item "Flag..." dired-flag-files-regexp
:help "Flag files matching regexp for deletion"))
+ (define-key map [menu-bar regexp mark-sym]
+ '(menu-item "Mark Symlinks Target..." dired-mark-symlinks-regexp
+ :help "Mark symbolic links whose target matches regexp for future operations"))
(define-key map [menu-bar regexp mark]
'(menu-item "Mark..." dired-mark-files-regexp
:help "Mark files matching regexp for future operations"))
@@ -3345,6 +3349,31 @@ dired-mark-files-regexp
(and fn (string-match-p regexp fn))))
"matching file")))
+(defun dired-mark-symlinks-regexp (regexp &optional marker-char)
+ "Mark all symbolic links whose target file matches REGEXP
+for use in later commands.
+A prefix argument means to unmark them instead.
+
+REGEXP is an Emacs regexp, not a shell wildcard. Thus, use ‘\.o$’ for
+object files--just ‘.o’ will mark more than you might think."
+ (interactive
+ (list (read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
+ " symlinks target (regexp): ")
+ nil 'dired-regexp-history)
+ (if current-prefix-arg ?\040)))
+ (let ((dired-marker-char (or marker-char dired-marker-char)))
+ (dired-mark-if
+ (and (looking-at-p dired-re-sym)
+ (not (looking-at-p dired-re-dot))
+ (not (eolp)) ; empty line
+
+ (let* ((eol (line-end-position))
+ (fn (save-excursion
+ (search-forward " -> " eol t)
+ (buffer-substring-no-properties (point) eol))))
+ (and fn (string-match-p regexp fn))))
+ "matching symbolic link")))
+
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
"Mark all files with contents containing REGEXP for use in later commands.
A prefix argument means to unmark them instead.
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-27 14:27 bug#22828: 25.1.50; Mark symlinks whose target matches regexp Tino Calancha
@ 2016-02-28 5:36 ` Lars Ingebrigtsen
2016-02-28 6:48 ` Tino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-28 5:36 UTC (permalink / raw)
To: Tino Calancha; +Cc: 22828
Tino Calancha <f92capac@gmail.com> writes:
> dired-mark-files-regexp checks the NAME of a symbolic link.
> Its useful to introduce one function which look for a match
> in the TARGET of the symbolic links.
> Such function could be bound to '%@'.
I'm not sure whether that's generally useful enough to include in
dired... I can't say that I remember ever wanting something like that.
[...]
> + (dired-mark-if
> + (and (looking-at-p dired-re-sym)
> + (not (looking-at-p dired-re-dot))
> + (not (eolp)) ; empty line
> +
> + (let* ((eol (line-end-position))
> + (fn (save-excursion
> + (search-forward " -> " eol t)
> + (buffer-substring-no-properties (point) eol))))
> + (and fn (string-match-p regexp fn))))
> + "matching symbolic link")))
And this implementation also seems quite fragile. Will symlinks always
be presented as " -> "? And can " -> " be a valid part of a file name.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-28 5:36 ` Lars Ingebrigtsen
@ 2016-02-28 6:48 ` Tino Calancha
2016-02-28 9:55 ` Andreas Schwab
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-02-28 6:48 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: Tino Calancha, 22828
> I'm not sure whether that's generally useful enough to include in
> dired... I can't say that I remember ever wanting something like that.
Sometimes the meaninful part of the symbolic link is in the target.
Let's say you have a lot of files (thousands of them), in different
locations and you create links to them:
t1
t2
...
ti
...
to all those files under the same directory for whatever
processing/editing that you have in mind.
In such case, the only mark which has sense to pick up some
particular files with a regexp is something like the proposed
command in this thread.
> And this implementation also seems quite fragile. Will symlinks always
> be presented as " -> "? And can " -> " be a valid part of a file name.
Good point. I agree with this.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-28 6:48 ` Tino Calancha
@ 2016-02-28 9:55 ` Andreas Schwab
2016-02-28 10:38 ` Tino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2016-02-28 9:55 UTC (permalink / raw)
To: Tino Calancha; +Cc: Lars Ingebrigtsen, 22828
Tino Calancha <f92capac@gmail.com> writes:
>> And this implementation also seems quite fragile. Will symlinks always
>> be presented as " -> "? And can " -> " be a valid part of a file name.
> Good point. I agree with this.
Use dired-move-to-end-of-filename to find the proper place.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-28 9:55 ` Andreas Schwab
@ 2016-02-28 10:38 ` Tino Calancha
2016-02-29 2:18 ` Lars Ingebrigtsen
0 siblings, 1 reply; 7+ messages in thread
From: Tino Calancha @ 2016-02-28 10:38 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Tino Calancha, Lars Ingebrigtsen, 22828
[-- Attachment #1: Type: text/plain, Size: 386 bytes --]
> Use dired-move-to-end-of-filename to find the proper place.
I see, this way we forget about the '@ -> ' or ' -> '
(or any other?).
Do you think is ok that fn contains such ' -> ' thing?
I would prefer if fn doesn't contain that.
So, the question is:
do we have a portable way to get the target of one link?
We may introduce something like:
dired-symlink-target (if doesn't exist)
[-- Attachment #2: Type: text/plain, Size: 2580 bytes --]
diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..6e70cd9 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1493,6 +1493,7 @@ dired-mode-map
(define-key map "%d" 'dired-flag-files-regexp)
(define-key map "%g" 'dired-mark-files-containing-regexp)
(define-key map "%m" 'dired-mark-files-regexp)
+ (define-key map "%@" 'dired-mark-symlinks-regexp)
(define-key map "%r" 'dired-do-rename-regexp)
(define-key map "%C" 'dired-do-copy-regexp)
(define-key map "%H" 'dired-do-hardlink-regexp)
@@ -1730,6 +1731,9 @@ dired-mode-map
(define-key map [menu-bar regexp flag]
'(menu-item "Flag..." dired-flag-files-regexp
:help "Flag files matching regexp for deletion"))
+ (define-key map [menu-bar regexp mark-sym]
+ '(menu-item "Mark Symlinks Target..." dired-mark-symlinks-regexp
+ :help "Mark symbolic links whose target matches regexp for future operations"))
(define-key map [menu-bar regexp mark]
'(menu-item "Mark..." dired-mark-files-regexp
:help "Mark files matching regexp for future operations"))
@@ -3345,6 +3349,31 @@ dired-mark-files-regexp
(and fn (string-match-p regexp fn))))
"matching file")))
+(defun dired-mark-symlinks-regexp (regexp &optional marker-char)
+ "Mark all symbolic links whose target file matches REGEXP
+for use in later commands.
+A prefix argument means to unmark them instead.
+
+REGEXP is an Emacs regexp, not a shell wildcard. Thus, use ‘\.o$’ for
+object files--just ‘.o’ will mark more than you might think."
+ (interactive
+ (list (read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
+ " symlinks target (regexp): ")
+ nil 'dired-regexp-history)
+ (if current-prefix-arg ?\040)))
+ (let ((dired-marker-char (or marker-char dired-marker-char)))
+ (dired-mark-if
+ (and (looking-at-p dired-re-sym)
+ (not (looking-at-p dired-re-dot))
+ (not (eolp)) ; empty line
+
+ (let* ((eol (line-end-position))
+ (fn (save-excursion
+ (and (dired-move-to-end-of-filename 'noerror)
+ (buffer-substring-no-properties (point) eol)))))
+ (and fn (string-match-p regexp fn))))
+ "matching symbolic link")))
+
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
"Mark all files with contents containing REGEXP for use in later commands.
A prefix argument means to unmark them instead.
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-28 10:38 ` Tino Calancha
@ 2016-02-29 2:18 ` Lars Ingebrigtsen
2016-03-01 11:12 ` Constantino Calancha
0 siblings, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-29 2:18 UTC (permalink / raw)
To: Tino Calancha; +Cc: Andreas Schwab, 22828
Tino Calancha <f92capac@gmail.com> writes:
>> Use dired-move-to-end-of-filename to find the proper place.
> I see, this way we forget about the '@ -> ' or ' -> ' (or any other?).
>
> Do you think is ok that fn contains such ' -> ' thing?
> I would prefer if fn doesn't contain that.
> So, the question is:
> do we have a portable way to get the target of one link?
> We may introduce something like:
> dired-symlink-target (if doesn't exist)
I thin kyou should just call `(dired-get-filename nil t)' on each line
to get the file names, and then call `file-truename' to get the name of
the target. Inspecting the text in the buffer with regexps is bound to
be fragile.
But I'm still not sure this is a function that would be generally
useful. :-)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#22828: 25.1.50; Mark symlinks whose target matches regexp
2016-02-29 2:18 ` Lars Ingebrigtsen
@ 2016-03-01 11:12 ` Constantino Calancha
0 siblings, 0 replies; 7+ messages in thread
From: Constantino Calancha @ 2016-03-01 11:12 UTC (permalink / raw)
To: 22828@debbugs.gnu.org
> I thin kyou should just call `(dired-get-filename nil t)' on each line
> to get the file names, and then call `file-truename' to get the name of
> the target.
Very good. I wasn't aware about this function.
> But I'm still not sure this is a function that would be generally
> useful. :-)
In that case let's forget about it and let's close this thread. No problem.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-03-01 11:12 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-27 14:27 bug#22828: 25.1.50; Mark symlinks whose target matches regexp Tino Calancha
2016-02-28 5:36 ` Lars Ingebrigtsen
2016-02-28 6:48 ` Tino Calancha
2016-02-28 9:55 ` Andreas Schwab
2016-02-28 10:38 ` Tino Calancha
2016-02-29 2:18 ` Lars Ingebrigtsen
2016-03-01 11:12 ` Constantino Calancha
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.