From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Emacs Lisp Programming Questions Date: Tue, 03 Nov 2009 23:43:56 -0700 Message-ID: References: <58e09c24-7598-4920-9318-dc21b9226023@a6g2000vbp.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1257317110 1555 80.91.229.12 (4 Nov 2009 06:45:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 Nov 2009 06:45:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 04 07:45:02 2009 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 1N5Zc2-0002jA-N6 for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Nov 2009 07:44:58 +0100 Original-Received: from localhost ([127.0.0.1]:42815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N5Zc1-0001xK-RM for geh-help-gnu-emacs@m.gmane.org; Wed, 04 Nov 2009 01:44:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N5ZbS-0001wW-Ml for help-gnu-emacs@gnu.org; Wed, 04 Nov 2009 01:44:22 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N5ZbN-0001rH-GV for help-gnu-emacs@gnu.org; Wed, 04 Nov 2009 01:44:21 -0500 Original-Received: from [199.232.76.173] (port=41690 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N5ZbN-0001qx-7S for help-gnu-emacs@gnu.org; Wed, 04 Nov 2009 01:44:17 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:39637) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1N5ZbM-0005oE-HB for help-gnu-emacs@gnu.org; Wed, 04 Nov 2009 01:44:17 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1N5ZbL-0002UK-3F for help-gnu-emacs@gnu.org; Wed, 04 Nov 2009 07:44:15 +0100 Original-Received: from c-71-237-24-138.hsd1.co.comcast.net ([71.237.24.138]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 04 Nov 2009 07:44:15 +0100 Original-Received: from kevin.d.rodgers by c-71-237-24-138.hsd1.co.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 04 Nov 2009 07:44:15 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 80 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-71-237-24-138.hsd1.co.comcast.net User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) 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:69465 Archived-At: David Combs wrote: > In article , > Kevin Rodgers wrote: >> clint.laskowski wrote: >>> Hello, gnu.emacs.help. I have a few questions about programming in >>> Emacs Lisp. I hope you can help. Here they are: >>> >>> 1. Is this a good place to ask questions about programming in Emacs >>> Lisp, especially with regards to text processing? If there's a better >>> place, I'd appreciate knowing. >>> >>> 2. I want to write an interactive Elisp program to remove sequential >>> duplicate lines from a buffer. This buffer is not sorted, and it >>> should not be sorted. The program should simply look for two >>> sequential lines that are identical, delete one, and then move on to >>> the next line and do it over until it reaches the end of the buffer. >>> >>> BUT, I do not want the answer to this problem (i.e., I don't want an >>> Elisp answer) ... I want hints on how to program it. I want to learn >>> the answer myself, if possible. >>> >>> Any ideas or pointers? >> Start by writing a keyboard macro that does what you want. Then you >> can translate the commands invoked interactively into function calls. > > I guess "edit-kbd-macro" and grabbing what it types out > would be the way to start that translation? Yes, and use `C-h f' to find the precise calling convention for each function. >> Note that you can search for sequential duplicate lines using a >> regular expression. > > Please show an example -- I myself will learn something > from it. > > It'd be cool to be able to get a regexp to extend past the > end of the line, yes? > > BUT WAIT! THIS IS *EMACS* -- doesn't work by lines -- > whole buffer is just one huge long string, with newlines > interspersed here and there. So, how to refer to a newline > as a plain old ordinary character, not "end of line" via "$"? LFD aka control-J > Yes, PLEASE, I'd REALLY like to see an example of such a regexp! ^\(.*\) LFD \1 LFD (the spaces are just for readability) > And if indeed that *can* be done, can you use that within > a query-replace somehow? Not query-replace (M-%), but query-replace-regexp (C-M-%): C-M-% ^\(.*\) C-q C-j \1 C-q C-j RET \1 C-q C-j RET > (Or will that miss every other one or something, because > if it sees two identical lines and replaces the 2nd > by "", then what if there is a third one also identical -- > can't get the qr to back up to make a match?) Yes, that could be a problem. This might work: C-M-% ^\(.*\) C-q C-j \(\1 C-q C-j \)+ RET \1 C-q C-j RET > Anyway, an example would sure be nice, however you do it, > just so long as you do it via a regexp. THANKS! Hope that helps! -- Kevin Rodgers Denver, Colorado, USA