From: Bob Proulx <bob@proulx.com>
To: s1ohy@waifu.club
Cc: help-gnu-emacs@gnu.org
Subject: Re: When using rectangle-mark-mode in an editable dired buffer, how can I edit the region?
Date: Tue, 6 Dec 2016 00:25:06 -0700 [thread overview]
Message-ID: <20161205233431659351400@bob.proulx.com> (raw)
In-Reply-To: <d803b154dcc827f4154b1d893e5b0851@waifu.club>
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
next prev parent reply other threads:[~2016-12-06 7:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161205233431659351400@bob.proulx.com \
--to=bob@proulx.com \
--cc=help-gnu-emacs@gnu.org \
--cc=s1ohy@waifu.club \
/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 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.