* When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
@ 2016-12-06 2:58 s1ohy
2016-12-06 7:25 ` Bob Proulx
0 siblings, 1 reply; 7+ messages in thread
From: s1ohy @ 2016-12-06 2:58 UTC (permalink / raw)
To: help-gnu-emacs
Using rectangle-mark-mode[1] with rectangle-utils[2] I highlight a
region in an editable dired buffer and call the command
`upcase-initials-region`: http://gobin.io/WzjF but as you can see in
the minibuffer I get the message `Text is read-only`. Is there any way
I can edit the rectangle region?
I'm open to other ways of doing what I want as this upcases the 'F' in
'flac', which I don't want, but I'm still interested in my original
question as this could be used in other places.
[1]
https://www.gnu.org/software/emacs/manual/html_node/emacs/Rectangles.html
[2] https://github.com/thierryvolpiatto/rectangle-utils
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 2:58 When using rectangle-mark-mode in an editable dired buffer, how can I edit the region? s1ohy
@ 2016-12-06 7:25 ` Bob Proulx
2016-12-06 16:54 ` Michael Heerdegen
2016-12-06 22:26 ` s1ohy
0 siblings, 2 replies; 7+ messages in thread
From: Bob Proulx @ 2016-12-06 7:25 UTC (permalink / raw)
To: s1ohy; +Cc: help-gnu-emacs
s1ohy@waifu.club wrote:
> Using rectangle-mark-mode[1] with rectangle-utils[2] I highlight a
> region in an editable dired buffer and call the command
> `upcase-initials-region`: http://gobin.io/WzjF but as you can see in
> the minibuffer I get the message `Text is read-only`. Is there any way
> I can edit the rectangle region?
Rectangles support the rectangle commands. Here is the doc:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Rectangles.html#Rectangles
However what you are trying to do isn't something that works with
rectangles. That's why it isn't working. It isn't a rectangle
command. It isn't special to Editable Dired mode. The same behavior
is true on any rectangle.
I am not familiar with rectangle-utils but I think that also applies
to it too.
> I'm open to other ways of doing what I want as this upcases the 'F' in
> 'flac', which I don't want, but I'm still interested in my original
> question as this could be used in other places.
Perhaps one of the others will have a way to do what you want exactly
as you have asked it. However I don't know think it is possible.
I would use emacs macros. Position the point on the first character
of the first file. Make the directory editable if it is not. Then
start a macro with C-x ( and then make the edits to the line you wish
to make to the line. Then just before finishing the macro C-n to move
to the next file name below. Then finish the macro with C-x ) . That
will leave the first line edited as you desire. Your point is
positioned on the second line. Invoke the macro again C-x e . When
you have immediately invoked a macro you can invoke it again with 'e'
without the C-x prefix.
Let's walk through a simple edit case of capitalizing the first word
in the file name.
C-x C-q
C-x (
M-c
C-n
C-x )
C-x e
e
e
e
...
C-x C-q
You asked specifically about upcase-initials-region which needs a
region. I started simple above but macros can be written to call that
across the entire line. I set the mark, jump to the end of the line,
either move a word backward to jump backward over the suffix or
reverse search for the suffix to jump over it, move back one more to
get past the dot. At that point you have a region. Execute the
region operation you wish. Then once again as before move to the next
line and terminate the macro.
C-x C-q
C-x (
C-SPC
C-e M-b C-b
M-x upcase-initials-region RET
C-n
C-x )
C-x e
e
e
e
...
C-x C-q
At that point you might say, But I have 10,000 lines to edit. That is
a lot of 'e' characters to type in. This isn't so nice but you can
give C-x e a numeric argument and it will execute the macro that many
times. Set the point and mark at the two lines at the top and bottom
that are at the ends of what you want to act upon, M-= to count the
lines in that region, then use that number as an argument to invoke
the macro.
C-SPC C-> M-=
Region has 3431 lines, 5323 words, and 23234 characters.
C-u 3431 C-x e
...all done...all 3431 lines...
Or if the modification is something I can do with a query-replace or
better with a query-replace-regexp then I can run that substitution
across the entire buffer. I always use the regexp version so that I
can use anchors such as $ for end of line. I will push space a few
times to check that it is doing what I want and then ! to replace all
remaining replacements all of the way to the end of the file.
C-x C-q
C-M-% RET \.FLAC$ RET .flac RET SPC SPC !
C-x C-q
What I would like to make this really nice is a way to narrow the
region to the rectangle, then perform the edit on the rectangle
narrowed, then widen the narrowed region back again. That way I could
temporarily pull the rectangle of text out of the context where it
exists and edit it in a narrowed buffer and then put it back. But
unfortuantely narrowing only works on lines and not rectangles. Oh
well. An enhancement for another day. Until then the above is one
reasonably good way. Although perhaps I will learn something too if
someone else posts an even better way to do this type of thing.
Bob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 7:25 ` Bob Proulx
@ 2016-12-06 16:54 ` Michael Heerdegen
2016-12-06 17:02 ` Michael Heerdegen
2016-12-06 22:26 ` s1ohy
1 sibling, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2016-12-06 16:54 UTC (permalink / raw)
To: s1ohy; +Cc: help-gnu-emacs
Hi Bob,
some thoughts:
You could kill the rectangle from writable dired, paste it into a helper
buffer, do your modifications there, kill the modified text as a
rectangle from there, and paste the rectangle back to wdired. You may
have to handle introduced trailing whitespace, however.
Other options are keyboard macros, dired-map-over-marks,
dired-do-rename-regexp - or you might like to use "multiple-cursors.el",
I guess it comes closest to your initial idea, AFAIR it support multiple
regions (one separate pseudo-region per line) and can run commands once
per every pseudo-region.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 16:54 ` Michael Heerdegen
@ 2016-12-06 17:02 ` Michael Heerdegen
0 siblings, 0 replies; 7+ messages in thread
From: Michael Heerdegen @ 2016-12-06 17:02 UTC (permalink / raw)
To: s1ohy; +Cc: help-gnu-emacs
Bob and s1ohy,
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Hi Bob,
I'm sorry for the confusion, my intention was to answer to the message
of s1ohy.
Michael.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 7:25 ` Bob Proulx
2016-12-06 16:54 ` Michael Heerdegen
@ 2016-12-06 22:26 ` s1ohy
2016-12-07 4:52 ` B.V. Raghav
2016-12-07 7:00 ` Bob Proulx
1 sibling, 2 replies; 7+ messages in thread
From: s1ohy @ 2016-12-06 22:26 UTC (permalink / raw)
To: s1ohy; +Cc: help-gnu-emacs
On 2016-12-06 07:25, Bob Proulx wrote:
> C-x C-q
> C-x (
> C-SPC
> C-e M-b C-b
> M-x upcase-initials-region RET
> C-n
> C-x )
> C-x e
> e
> e
> e
> ...
> C-x C-q
Thanks for responding, Bob. Your suggestion of keyboard macros was
great, as I was unaware I could combine them with non-interactive
commands and mark-region. Unfortunately, your suggestion, quoted
above, only works if I manually position the cursor at the beginning
of the filename, thus not being able to quickly repeat it with F4 or
call it with a numeric argument.
But, to make your suggestion work I can use `dired-next-line`, which
places the cursor at the the beginning of the next filename.
C-x C-q
Place cursor at the beginning filename
F3
C-SPC
C-e M-b C-b
M-x upcase-initials-region RET
dired-next-line
F4
F4
F4
...
C-x C-s
Of course, I can call it with `M-1 M-4 F4`
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 22:26 ` s1ohy
@ 2016-12-07 4:52 ` B.V. Raghav
2016-12-07 7:00 ` Bob Proulx
1 sibling, 0 replies; 7+ messages in thread
From: B.V. Raghav @ 2016-12-07 4:52 UTC (permalink / raw)
To: help-gnu-emacs
s1ohy@waifu.club writes:
> above, only works if I manually position the cursor at the beginning
> of the filename, thus not being able to quickly repeat it with F4 or
> call it with a numeric argument.
This IMHO, is a common use case, and though you already have a solution,
I might have had a different view point, with an arbitrary tabular
data. So I suggest having a look at:
| (set-goal-column ARG)
| It is bound to C-x C-n.
| Set the current horizontal position as a goal for C-n and C-p.
| Those commands will move to this position in the line moved to
| rather than trying to keep the same horizontal position.
| With a non-nil argument ARG, clears out the goal column
| so that C-n and C-p resume vertical motion.
| The goal column is stored in the variable `goal-column'.
As mentioned, you may clear the goal column with `C-u C-x C-n'
My two cents.
--
(B.V. Raghav)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
2016-12-06 22:26 ` s1ohy
2016-12-07 4:52 ` B.V. Raghav
@ 2016-12-07 7:00 ` Bob Proulx
1 sibling, 0 replies; 7+ messages in thread
From: Bob Proulx @ 2016-12-07 7:00 UTC (permalink / raw)
To: s1ohy; +Cc: help-gnu-emacs
s1ohy@waifu.club wrote:
> On 2016-12-06 07:25, Bob Proulx wrote:
> > C-x C-q
> > C-x (
> > C-SPC
> > C-e M-b C-b
> > M-x upcase-initials-region RET
> > C-n
> > C-x )
> > C-x e
> > e
> > e
> > e
> > ...
> > C-x C-q
And as long as I am responding I made another mistake in the above. I
ended with C-x C-q, which will then ask you if you want to save the
result. I should have finished the dired edit using C-c C-c instead.
> Thanks for responding, Bob. Your suggestion of keyboard macros was
> great, as I was unaware I could combine them with non-interactive
> commands and mark-region.
I use regions with macros a lot. I consider complex macros somewhat a
brute force solution. But they do work and I use them a lot.
> Unfortunately, your suggestion, quoted above, only works if I
> manually position the cursor at the beginning of the filename, thus
> not being able to quickly repeat it with F4 or call it with a
> numeric argument.
And that was another mistake in the above. Because I was slightly
confused when I composed the macro above. Normally in dired mode both
C-n, n, and C-p, p (dired-next-line as you found) snap to the
beginning of the file entry. Therefore when I wrote the above that is
what I was thinking would happen. Oops. It's a bug in my example.
Sorry. But at least you figured it out and were able to add an
additional emacs tool into your toolbox. :-)
> But, to make your suggestion work I can use `dired-next-line`, which
> places the cursor at the the beginning of the next filename.
Good! I am glad you figured it out.
B.V. Raghav wrote:
> (set-goal-column ARG)
> It is bound to C-x C-n.
That is a good idea!
Bob
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-12-07 7:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-06 2:58 When using rectangle-mark-mode in an editable dired buffer, how can I edit the region? s1ohy
2016-12-06 7:25 ` Bob Proulx
2016-12-06 16:54 ` Michael Heerdegen
2016-12-06 17:02 ` Michael Heerdegen
2016-12-06 22:26 ` s1ohy
2016-12-07 4:52 ` B.V. Raghav
2016-12-07 7:00 ` Bob Proulx
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.