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

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

Re: Find first line FOLLOWING a sequence of matches


From: tomas
Subject: Re: Find first line FOLLOWING a sequence of matches
Date: Fri, 1 May 2015 16:57:04 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, Apr 28, 2015 at 04:53:58PM +0000, Subhan Michael Tindall wrote:
> Table like this: (abbreviated)
> |a|b|c|
> |a|d|e|
> |a|z||
> |m|b|c|
> |m|c|d|
> |ab|c|d|

Here's a little Emacs Lisp snippet to get you started:

  (defun my-segmentize-table ()
    (interactive)
    (let ((curr-fc nil)) ;; current first col
      (while (looking-at "^|\\([^|]*\\)")
        (let ((fc (match-string 1)))
          (unless (equal fc curr-fc)
            ;; we are at the start of a line with a "new" first column
            (insert (format ",* %s\n" fc))
            (setq curr-fc fc)))
        ;; advance one line:
        (beginning-of-line 2))))

Season to taste :-)

If you don't know what to do with it, here are some instructions:

 - Paste into a spare buffer (the *scratch* buffer is fine for that)
 - Evaluate the whole thing by going to its end and keying C-x C-e
   (aka "eval-last-sexp"). Now your Emacs should know a new command
   "my-segmentize-table"
 - Go to the first line of the table you want to transform
 - Type there "M-x my-segmentize-table"

Make first a backup of your valuable buffers ;-)

Enjoy
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlVDlEAACgkQBcgs9XrR2kbFMQCdFbGodLScRS87XFBc8JT6rQTl
UI4An24LpRgeyjZ8gOPwCQSGEqbyOsKI
=HDE1
-----END PGP SIGNATURE-----



reply via email to

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