unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Emacs Lisp Programming Questions
Date: Tue, 03 Nov 2009 23:43:56 -0700	[thread overview]
Message-ID: <hcr7ra$18e$1@ger.gmane.org> (raw)
In-Reply-To: <hcjbjp$t1v$1@reader1.panix.com>

David Combs wrote:
> In article <mailman.8228.1254921577.2239.help-gnu-emacs@gnu.org>,
> Kevin Rodgers  <kevin.d.rodgers@gmail.com> 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





  parent reply	other threads:[~2009-11-04  6:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-06 22:40 Emacs Lisp Programming Questions clint.laskowski
2009-10-07  0:14 ` Pascal J. Bourguignon
2009-10-07  7:53 ` mdj
2009-10-07  8:40 ` David Kastrup
2009-10-07 16:42   ` tomas
2009-10-07  8:55 ` djc
2009-10-07 13:19 ` Kevin Rodgers
2009-10-07 20:54 ` Xah Lee
2009-10-08 13:36 ` clint.laskowski
2009-10-08 14:35   ` Andreas Politz
     [not found] ` <mailman.8228.1254921577.2239.help-gnu-emacs@gnu.org>
2009-11-01  6:59   ` David Combs
2009-11-02 16:29     ` David Kastrup
2009-11-04  6:43     ` Kevin Rodgers [this message]
2009-11-04  9:24     ` Andreas Röhler
2009-11-04  9:26     ` Andreas Röhler

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='hcr7ra$18e$1@ger.gmane.org' \
    --to=kevin.d.rodgers@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).