From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Politz Newsgroups: gmane.emacs.help Subject: Re: Requested function: just-one-empty-line() Date: Mon, 06 Oct 2008 17:24:33 +0200 Organization: FH-Trier Message-ID: <1223306994.390780@arno.fh-trier.de> References: <1223294124.550402@arno.fh-trier.de> <53d33bfd-58a1-4e06-aee0-7a74cd3c604c@m36g2000hse.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1223308238 30242 80.91.229.12 (6 Oct 2008 15:50:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 6 Oct 2008 15:50:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 06 17:51:34 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KmsEk-0004Xl-9L for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Oct 2008 17:43:06 +0200 Original-Received: from localhost ([127.0.0.1]:45722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KmsDg-0007Zf-N0 for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Oct 2008 11:42:00 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.belwue.de!news.uni-kl.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 65 Original-NNTP-Posting-Host: 143-93-54-11.arno.fh-trier.de Original-X-Trace: news.uni-kl.de 1223307012 17527 143.93.54.11 (6 Oct 2008 15:30:12 GMT) Original-X-Complaints-To: usenet@news.uni-kl.de Original-NNTP-Posting-Date: Mon, 6 Oct 2008 15:30:12 +0000 (UTC) User-Agent: Mozilla-Thunderbird 2.0.0.16 (X11/20080724) In-Reply-To: Cache-Post-Path: arno.fh-trier.de!unknown@dslb-084-059-203-042.pools.arcor-ip.net X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) Original-Xref: news.stanford.edu gnu.emacs.help:163098 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58440 Archived-At: Xah wrote: > On Oct 6, 5:14 am, Nordlöw wrote: >> On 6 Okt, 13:50, Andreas Politz 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/ > > ☄ Is the parenstyle part of your 'Modernization of emacs' program or are you just trying to offend 'tech-geekers' ? ;O) -ap