From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help 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 Message-ID: <20161205233431659351400@bob.proulx.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1481009144 12372 195.159.176.226 (6 Dec 2016 07:25:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 6 Dec 2016 07:25:44 +0000 (UTC) User-Agent: NeoMutt/20161126 (1.7.1) Cc: help-gnu-emacs@gnu.org To: s1ohy@waifu.club Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 06 08:25:39 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEA89-0001o5-2p for geh-help-gnu-emacs@m.gmane.org; Tue, 06 Dec 2016 08:25:37 +0100 Original-Received: from localhost ([::1]:46525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEA8B-00032W-2m for geh-help-gnu-emacs@m.gmane.org; Tue, 06 Dec 2016 02:25:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55286) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEA7j-00032O-Ph for help-gnu-emacs@gnu.org; Tue, 06 Dec 2016 02:25:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEA7f-0000Mt-Mc for help-gnu-emacs@gnu.org; Tue, 06 Dec 2016 02:25:11 -0500 Original-Received: from havoc.proulx.com ([96.88.95.61]:42640) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEA7f-0000MY-Gq for help-gnu-emacs@gnu.org; Tue, 06 Dec 2016 02:25:07 -0500 Original-Received: from joseki.proulx.com (localhost [127.0.0.1]) by havoc.proulx.com (Postfix) with ESMTP id 18A64D6B; Tue, 6 Dec 2016 00:25:07 -0700 (MST) Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id C6FA321931; Tue, 6 Dec 2016 00:25:06 -0700 (MST) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id B5D652DC60; Tue, 6 Dec 2016 00:25:06 -0700 (MST) Mail-Followup-To: s1ohy@waifu.club, help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 96.88.95.61 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111876 Archived-At: 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