[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Requested function: just-one-empty-line()
From: |
Xah |
Subject: |
Re: Requested function: just-one-empty-line() |
Date: |
Mon, 6 Oct 2008 07:27:52 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Oct 6, 5:14 am, Nordlöw <per.nord...@gmail.com> wrote:
> On 6 Okt, 13:50, Andreas Politz <poli...@fh-trier.de> wrote:
> > Nordlöw wrote:
> > > I'm looking for a function just-one-empty-line(), or empty-lines() for
> > > the multi-line-variant, that does kind of what just-one-space() does
> > > but instead works on empty lines. Any suggestions?
>
> > > Example:
>
> > > pre;\n
> > > \n
> > > \n
> > > post;
>
> > > is converted to
>
> > > pre;\n
> > > \n
> > > post;
>
> > > Thanks in advance,
> > > Nordlöw
>
> > ,----[ C-h f delete-blank-lines RET ]
> > | delete-blank-lines is an interactive compiled Lisp function in
> > `simple.el'.
> > | It is bound to C-x C-o.
> > | (delete-blank-lines)
> > |
> > | On blank line, delete all surrounding blank lines, leaving just one.
> > | On isolated blank line, delete that one.
> > | On nonblank line, delete any immediately following blank lines.
> > `----
Since delete-blank-lines and just-one-space are similar in function
from user point of view, i combined them into one single function,
that calls each depending on the context. So, a single key is assigned
to this command, saving up shortcut spaces.
(defun shrink-whitespaces ()
"Collapse all white spaces around point, depending on context.
White space here includes space, tabs, and any end of line char.
This commands either calls just-one-space or delete-blank-lines."
(interactive)
(let (p1 p2 mytext)
(save-excursion
(skip-chars-backward "\t \n")
(setq p1 (point))
(skip-chars-forward "\t \n")
(setq p2 (point))
(setq mytext (buffer-substring-no-properties p1 p2))
)
(if (string-match "[\t ]*\n[\t ]*\n" mytext)
(progn (delete-blank-lines))
(progn (just-one-space))
)
)
)
http://xahlee.org/emacs/ergonomic_emacs_keybinding.html
Xah
∑ http://xahlee.org/
☄