* Re: Emacs Lisp Programming Questions
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
` (6 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Pascal J. Bourguignon @ 2009-10-07 0:14 UTC (permalink / raw)
To: help-gnu-emacs
"clint.laskowski" <clint.laskowski@gmail.com> writes:
> 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.
Here should be good.
For real time interaction, there's also irc://irc.freenode.org/#emacs
> 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.
Read first the emacs lisp introduction.
http://www.gnu.org/software/emacs/emacs-lisp-intro/emacs-lisp-intro.html
Then it's a simple matter of implementing directly the algorithm as
you said.
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
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
` (5 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: mdj @ 2009-10-07 7:53 UTC (permalink / raw)
To: help-gnu-emacs
On Oct 7, 8:40 am, "clint.laskowski" <clint.laskow...@gmail.com>
wrote:
> 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.
My own (lazy) solution to this problem is to use the elisp function
shell-command-on-region to invoke the unix command 'uniq' which
implements the logic you want. Whether or not you consider this a
sufficiently 'emacsy' solution depends on your personal prejudices,
but it does have the advantage of being whipped up in a few seconds
with a quick lambda of the aforementioned function onto a global-set-
key
Matt
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
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
` (4 subsequent siblings)
7 siblings, 1 reply; 15+ messages in thread
From: David Kastrup @ 2009-10-07 8:40 UTC (permalink / raw)
To: help-gnu-emacs
"clint.laskowski" <clint.laskowski@gmail.com> writes:
> 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?
You can just walk through the buffer line and enter each line into a
hashtable.
If the respective puthash leads to a difference in hash-count, the line
was not in the hashtable before. Otherwise, delete the line. You might
want to do clrhash afterwards so that the strings can get garbage
collected without waiting for the hashtable to get collected first. Not
sure whether this really is necessary.
--
David Kastrup
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-07 8:40 ` David Kastrup
@ 2009-10-07 16:42 ` tomas
0 siblings, 0 replies; 15+ messages in thread
From: tomas @ 2009-10-07 16:42 UTC (permalink / raw)
To: David Kastrup; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, Oct 07, 2009 at 10:40:23AM +0200, David Kastrup wrote:
> "clint.laskowski" <clint.laskowski@gmail.com> writes:
[...]
> > 2. I want to write an interactive Elisp program to remove sequential
> > duplicate lines from a buffer [...]
[...]
> You can just walk through the buffer line and enter each line into a
> hashtable.
If I understood the OP correctly, by "sequential duplicate lines" he
means duplicates which are neighbours. The hash table approach would
remove duplicates over the whole file, AFAIU you.
I.e.
A A
B B
B --> C
C B
B C
C
versus
A A
B B
B --> C
C
B
C
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKzMTyBcgs9XrR2kYRApIgAJ4r8ZIlKh6YSIN7nB0MOfwDByqyKwCfa/+O
OMKXMs3xvhWibsu1VGYdcQg=
=7OSQ
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-06 22:40 Emacs Lisp Programming Questions clint.laskowski
` (2 preceding siblings ...)
2009-10-07 8:40 ` David Kastrup
@ 2009-10-07 8:55 ` djc
2009-10-07 13:19 ` Kevin Rodgers
` (3 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: djc @ 2009-10-07 8:55 UTC (permalink / raw)
To: help-gnu-emacs
> 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.
Here are some hints:
buffer-substring
regexp-quote
looking-at
forward-line
delete-region
djc
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-06 22:40 Emacs Lisp Programming Questions clint.laskowski
` (3 preceding siblings ...)
2009-10-07 8:55 ` djc
@ 2009-10-07 13:19 ` Kevin Rodgers
2009-10-07 20:54 ` Xah Lee
` (2 subsequent siblings)
7 siblings, 0 replies; 15+ messages in thread
From: Kevin Rodgers @ 2009-10-07 13:19 UTC (permalink / raw)
To: help-gnu-emacs
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.
Note that you can search for sequential duplicate lines using a
regular expression. So write a keyboard macro that removes just
1 (the next) such duplicate line -- it will be easy to wrap that
function call into a while loop that processes the whole buffer.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-06 22:40 Emacs Lisp Programming Questions clint.laskowski
` (4 preceding siblings ...)
2009-10-07 13:19 ` Kevin Rodgers
@ 2009-10-07 20:54 ` Xah Lee
2009-10-08 13:36 ` clint.laskowski
[not found] ` <mailman.8228.1254921577.2239.help-gnu-emacs@gnu.org>
7 siblings, 0 replies; 15+ messages in thread
From: Xah Lee @ 2009-10-07 20:54 UTC (permalink / raw)
To: help-gnu-emacs
On Oct 6, 3:40 pm, "clint.laskowski" <clint.laskow...@gmail.com>
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?
you might try my elisp tutorial, which is specifically focused for
text processing tasks, either as interactive commands or as batch
program like perl, python. (as opposed to, being focused on writing
major/minor modes, dealing with fonts, mouses, emacs's windown/frames
manipulation, writing ftp, email clients, or special modes like calc,
dired, etc.)
• Xah's Emacs Lisp Tutorial
http://xahlee.org/emacs/elisp.html
For asking emacs lisp questions, gnu.emacs.help and comp.emacs is the
best place. Alternative are comp.lang.lisp. For advanced emacs lisp
questions (say, you already have 3 years of elisp experience ), then
emacs dev mailing list is best.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-06 22:40 Emacs Lisp Programming Questions clint.laskowski
` (5 preceding siblings ...)
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>
7 siblings, 1 reply; 15+ messages in thread
From: clint.laskowski @ 2009-10-08 13:36 UTC (permalink / raw)
To: help-gnu-emacs
On Oct 6, 5:40 pm, "clint.laskowski" <clint.laskow...@gmail.com>
wrote:
> 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.
I appreciate all the pointers and ideas. I ended up finding a solution
(instead of learning it myself, but that's okay - since I actually
learned more from the responses here) which is now in my .emacs file:
(defun uniquify-region (beg end)
"remove duplicate adjacent lines in the given region"
(interactive "*r")
(goto-char beg)
(while (re-search-forward "^\\(.*\n\\)\\1+" end t)
(replace-match "\\1")))
(defun uniquify-buffer ()
(interactive)
(uniquify-region (point-min) (point-max)))
Thanks again for the help!
-- Clint
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-10-08 13:36 ` clint.laskowski
@ 2009-10-08 14:35 ` Andreas Politz
0 siblings, 0 replies; 15+ messages in thread
From: Andreas Politz @ 2009-10-08 14:35 UTC (permalink / raw)
To: help-gnu-emacs
"clint.laskowski" <clint.laskowski@gmail.com> writes:
> On Oct 6, 5:40 pm, "clint.laskowski" <clint.laskow...@gmail.com>
> wrote:
>
[...]
>
> I appreciate all the pointers and ideas. I ended up finding a solution
> (instead of learning it myself, but that's okay - since I actually
> learned more from the responses here) which is now in my .emacs file:
>
> (defun uniquify-region (beg end)
> "remove duplicate adjacent lines in the given region"
> (interactive "*r")
> (goto-char beg)
> (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
> (replace-match "\\1")))
>
[...]
But you still can improve it. Marking the first 4 lines of a's and
doing `M-x uniquify-region' leaves the buffer with 2 lines left, instead
of 3.
aaa
aaa
aaa
aaa
bbb
bbb
-ap
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.8228.1254921577.2239.help-gnu-emacs@gnu.org>]
* Re: Emacs Lisp Programming Questions
[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
` (3 more replies)
0 siblings, 4 replies; 15+ messages in thread
From: David Combs @ 2009-11-01 6:59 UTC (permalink / raw)
To: help-gnu-emacs
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?
>
>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 "$"?
Yes, PLEASE, I'd REALLY like to see an example of such a regexp!
And if indeed that *can* be done, can you use that within
a query-replace somehow?
(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?)
Anyway, an example would sure be nice, however you do it,
just so long as you do it via a regexp. THANKS!
So write a keyboard macro that removes just
>1 (the next) such duplicate line -- it will be easy to wrap that
>function call into a while loop that processes the whole buffer.
>
>--
>Kevin Rodgers
>Denver, Colorado, USA
>
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-11-01 6:59 ` David Combs
@ 2009-11-02 16:29 ` David Kastrup
2009-11-04 6:43 ` Kevin Rodgers
` (2 subsequent siblings)
3 siblings, 0 replies; 15+ messages in thread
From: David Kastrup @ 2009-11-02 16:29 UTC (permalink / raw)
To: help-gnu-emacs
dkcombs@panix.com (David Combs) writes:
> 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.
>
> 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 "$"?
>
> Yes, PLEASE, I'd REALLY like to see an example of such a regexp!
Uh, type C-q C-j to get a newline into a string at the search prompt.
That's not particularly magic.
--
David Kastrup
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-11-01 6:59 ` David Combs
2009-11-02 16:29 ` David Kastrup
@ 2009-11-04 6:43 ` Kevin Rodgers
2009-11-04 9:24 ` Andreas Röhler
2009-11-04 9:26 ` Andreas Röhler
3 siblings, 0 replies; 15+ messages in thread
From: Kevin Rodgers @ 2009-11-04 6:43 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-11-01 6:59 ` David Combs
2009-11-02 16:29 ` David Kastrup
2009-11-04 6:43 ` Kevin Rodgers
@ 2009-11-04 9:24 ` Andreas Röhler
2009-11-04 9:26 ` Andreas Röhler
3 siblings, 0 replies; 15+ messages in thread
From: Andreas Röhler @ 2009-11-04 9:24 UTC (permalink / raw)
To: David Combs; +Cc: help-gnu-emacs
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.
>>>
...
In use here
(defun just-one-empty-line (&optional beg end)
"Delete consecutive empty lines, retain just one. "
(interactive "*")
(let ((beg (cond (beg beg)
((region-active-p)
(region-beginning))
(t (point-min))))
(end (cond (end (copy-marker end))
((region-active-p)
(copy-marker (region-end)))
(t (copy-marker (point-max))))))
(save-excursion
(save-restriction
(narrow-to-region beg end)
(goto-char beg)
(while (not (eobp))
(while (looking-at "^\\([ \t]*\n\\)[ \t]*$")
(delete-region (match-beginning 1) (match-end 1)))
(forward-line 1)))
(widen))))
Andreas
--
https://code.launchpad.net/s-x-emacs-werkstatt/
http://bazaar.launchpad.net/~a-roehler/python-mode/python-mode.el/
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: Emacs Lisp Programming Questions
2009-11-01 6:59 ` David Combs
` (2 preceding siblings ...)
2009-11-04 9:24 ` Andreas Röhler
@ 2009-11-04 9:26 ` Andreas Röhler
3 siblings, 0 replies; 15+ messages in thread
From: Andreas Röhler @ 2009-11-04 9:26 UTC (permalink / raw)
To: David Combs; +Cc: help-gnu-emacs
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.
>>>
just see I used a private `region-active-p'
(unless (featurep 'xemacs)
(defun region-active-p ()
"and mark-active transient-mark-mode
(not (eq (region-beginning) (region-end)"
(and mark-active transient-mark-mode
(not (eq (condition-case nil (region-beginning)(error nil)) (condition-case nil (region-end) (error nil)))))))
^ permalink raw reply [flat|nested] 15+ messages in thread