help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When using rectangle-mark-mode in an editable dired buffer, how can


From: Bob Proulx
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
User-agent: NeoMutt/20161126 (1.7.1)

address@hidden 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]