From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: Find first line FOLLOWING a sequence of matches Date: Fri, 1 May 2015 13:30:50 -0600 Message-ID: <20150501125136680755063@bob.proulx.com> References: <20150428222841721866707@bob.proulx.com> <20150430151743082434507@bob.proulx.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1430508680 16498 80.91.229.3 (1 May 2015 19:31:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 May 2015 19:31:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri May 01 21:31:15 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YoGeY-0002VZ-Vz for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2015 21:31:15 +0200 Original-Received: from localhost ([::1]:55304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoGeY-0007ZG-1L for geh-help-gnu-emacs@m.gmane.org; Fri, 01 May 2015 15:31:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoGeK-0007VL-SB for help-gnu-emacs@gnu.org; Fri, 01 May 2015 15:31:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YoGeH-0002Rh-KZ for help-gnu-emacs@gnu.org; Fri, 01 May 2015 15:31:00 -0400 Original-Received: from joseki.proulx.com ([216.17.153.58]:46800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YoGeG-0002Qf-HZ for help-gnu-emacs@gnu.org; Fri, 01 May 2015 15:30:57 -0400 Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 55A3021217 for ; Fri, 1 May 2015 13:30:51 -0600 (MDT) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id 04EE62DC42; Fri, 1 May 2015 13:30:50 -0600 (MDT) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 216.17.153.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104149 Archived-At: Subhan Michael Tindall wrote: > I need to futz with it some more, hopefully tomorrow. > But, one issue that I'm having is that using C-w to yank word at > point doesn't cross punctuation, so I can't use c-w to grab the word Is it really C-w kill-region not yank word? The description confuses me a little so not really sure exactly what you need there. The suggestions about changing the syntax table to include punctuation in words seems like a good possibility. Especially if trying to M-@ mark-word or M-d kill-word which operate on words. The disadvantage is that one may like the previous definition for other things. I also like the emacs-lisp snippet since I think this might be an operation you will be doing periodically? If so then writing a small program in elisp to do the task will pay back rewards many times in the future. Especially when things become more complicated having a real program can be better than brute forcing through with the keyboard. But let me say a few words about emacs and creating a keyboard macro. It can do what you want. This is how I would do it. Everyone will edit the file differently. This is simply one example way. I would always search for the field separators. I would move the point to the next separator either forward or backward. That will leave the mark behind at the previous point location. When editing I would then use C-x C-x to exchange-point-and-mark to show the region between. (I eschew transient-mark-mode but I assume all new users are using it. In which case the region will be highlighted.) Once the region has been established then I would M-w kill-ring-save will copy it to the kill ring. (Or alternatively simply kill and yank to the same effect with C-w C-y (kill-region, yank) which is the same on a modified buffer.) M-w copies the region to the kill ring. By searching for the field separator it avoids differences in the field holding one word or two words or zero or more. You had previously said: Table like this: (abbreviated) |a|b|c| |a|d|e| |a|z|| |m|b|c| |m|c|d| |ab|c|d| I'm looking to write a macro to convert this table (on an occasionally recurring basis) To something like: ,* a |a|b|c| |a|d|e| |a|z|| ,* m |m|b|c| |m|c|d| ,* ab |ab|c|d| Can do. Grab the first field to use for the new header. C-f C-s | C-b M-w The first field is now in the kill ring. Build your header using it. C-a C-o ,* C-y C-f I am going to search for it using regular expressions C-u C-r. I need it for the '^' to anchor to the start of the line and not at other field locations. C-r is a non-RE search. C-u C-r is an RE search. M-> C-u C-r ^| C-y | C-a C-n Jump to the bottom of the file and search upward using a regular expression search. Anchor to the start of the line. Look for the separator. Yank in the saved pattern. Separator. That leaves you just to the right of the first field. The point will be sitting at the first position of the second field. Then C-a move-beginning-of-line. Then C-n for next line. Maybe at that point you will be on the next line. Maybe. Maybe not. It depends. Grr... Another peeve of mine. This is tricky due to the new emacs default of visual line mode. Up until recently next-line always took you to the next line. But in recent emacs the default is now visual line mode. I eschew line-move-visual for exactly the reason that next-line no longer takes you to the next line. Now with line-move-visual set it depends upon line length and window length. (The end condition also depends upon the value of next-line-add-newlines too.) If you have the new default value and the line is longer than your display and wraps then C-n won't put the point on the next line. It will put it somewhere in the wrapped area. I can only suggest (setq line-move-visual nil) to return to a sane state. Others obviously disagree with me. I can only note it here and you must deal with the behavior there. Having the point now on the next line where you want to start a new header. Terminate the macro. Call the macro. It should repeat. That should have you with a manual way to macro out an edit to add those headers to the table that you wanted to add. It does not depend upon changing the word character syntax table. > at point into the search buffer (which would be quick & easy. > IE zipc^odes_hold > Pt here > C-w pulls zipcodes, not zipcodes_hold > If there's a way I can define words to only be bounded by whitespace > I should be able to whip up a keyboard macro for the rest I > believe. Changing the word characters will work too. There is more than one way to do it. I prefer to search for the separator instead of counting on there being a certain type of field. Different (key)strokes for different folks. Bob