From: "weber" <hugows@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Keep-only-column
Date: 9 Feb 2007 02:47:44 -0800 [thread overview]
Message-ID: <1171018064.772195.132380@a34g2000cwb.googlegroups.com> (raw)
In-Reply-To: <531k72F1qnjq5U3@mid.individual.net>
On 8 fev, 18:55, Marc Tfardy <m...@web.de> wrote:
> 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
Here's mine, but I guess we were thinking different things...
Now I must apply it to a region
(defun keep-column (&optional arg)
"Considering space-separated columns, keep only column ARG."
(interactive "p")
(save-excursion
(let ((cnt-col 0))
(while (not (eolp))
(if (looking-at "[ \t\r\n]")
(progn
(incf cnt-col)
(delete-char 1)
(while (and (not (eolp)) (looking-at "[ \t\n\r]"))
(delete-char 1)))
(progn
(if (= cnt-col arg)
(forward-char)
(delete-char 1))))))))
Cheers
weber
next prev parent reply other threads:[~2007-02-09 10:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-08 19:15 Keep-only-column weber
2007-02-08 19:23 ` Keep-only-column weber
2007-02-08 19:43 ` Keep-only-column Joost Kremers
2007-02-08 19:46 ` Keep-only-column weber
2007-02-08 21:55 ` Keep-only-column Marc Tfardy
2007-02-09 10:47 ` weber [this message]
2007-02-09 10:58 ` Keep-only-column Marc Tfardy
2007-02-09 11:10 ` Keep-only-column weber
2007-02-09 12:35 ` Keep-only-column weber
2007-02-09 12:49 ` Keep-only-column Marc Tfardy
2007-02-09 13:00 ` Keep-only-column weber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1171018064.772195.132380@a34g2000cwb.googlegroups.com \
--to=hugows@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).