[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Keep-only-column
From: |
Marc Tfardy |
Subject: |
Re: Keep-only-column |
Date: |
Thu, 08 Feb 2007 22:55:27 +0100 |
User-agent: |
Thunderbird 1.5 (X11/20051201) |
weber wrote:
> On 8 fev, 16:15, "weber" <hug...@gmail.com> wrote:
>> hello again!
>> Quite frequently I paste stuff which is space-separated.
>> I would really like a function that would let me select a region and
>> keep only a column, deleting all the rest.
>> Anyone knows how I could implement something like this?
>> I can do it with regexps, but then I have to come up with a new one
>> every time...
>> TIA
>> HS
>
> I think the format of "stuff" can't be understood from above :) Here
> it is:
>
> variable BLABLA = 438438
> variable LABLAC = 312
> variable DAUSH = 43538
>
> Apply to that region: keep-only-column 2 makes it:
> BLABLA
> LABLAC
> DAUSHD
Here my draft. Probalby inefficient, but it does the job.
(defun trim-rectangle (start end)
"Trims region to rectangle."
(interactive "r")
(save-excursion
(let ((offset 0)
(width 0)
(lines (count-lines start end))
(i 0))
(goto-char start)
(beginning-of-line)
(setq offset (- start (point)))
(goto-char end)
(beginning-of-line)
(forward-char offset)
(setq width (- end (point)))
(goto-char start)
(while (< i lines)
(beginning-of-line)
(delete-region (point) (+ (point) offset))
(forward-char width)
(delete-region (point) (line-end-position))
(end-of-line)
(forward-char)
(setq i (+ i 1))))))
HTH
regards
Marc
- Keep-only-column, weber, 2007/02/08
- Re: Keep-only-column, weber, 2007/02/08
- Re: Keep-only-column, Joost Kremers, 2007/02/08
- Re: Keep-only-column,
Marc Tfardy <=
- Re: Keep-only-column, weber, 2007/02/09
- Re: Keep-only-column, Marc Tfardy, 2007/02/09
- Re: Keep-only-column, weber, 2007/02/09
- Re: Keep-only-column, weber, 2007/02/09
- Re: Keep-only-column, Marc Tfardy, 2007/02/09
- Re: Keep-only-column, weber, 2007/02/09