New proposed function doesn't do what I want
tom.capey at edina.co.uk
Mon Aug 16 11:34:22 CEST 2004
* Rodney Sparapani <rsparapa at post.its.mcw.edu> writes:
> Does anyone know why this function doesn't quite work? I want to change all
> multiple blank lines into one blank line.
> (defun ess-delete-blank-lines ()
> "Convert 2 or more lines of white space into one. This function
> works as you might expect, except that it must be terminated by C-g
> for some reason and it also removes single blank lines?!?"
> (goto-char (point-min))
> (while (search-forward-regexp "^[ \t]*$" nil 'eof 2)
the found search-string is an empty string (= (match-beginning)
(match-end)), so the COUNT argument will automatically be
(re-search-forward "" nil t 30)
which will return the current point.
the function removes the single blank lines because a single
blank line satisfies the search conditions. I'd go for two
explicit lines, and go to the beginning of the found regular
expression in case I'm at the beginning of a non-blank line
(`delete-blank-lines' will do nothing in that case):
(defun ess-delete-blank-lines ()
"Convert 2 or more lines of white space into one."
(while (search-forward-regexp "^[ \t]*\n[ \t]*\n" nil t)
(goto-char (match-beginning 0))
I for one welcome our new key-chord-requiring self-documenting
extensible OS-in-an-editor Emacs overlord. -- Jock Cooper
--- Disclaimer ---
Unless otherwise agreed expressly in writing by a Director of Edina Software, this communication is to be treated as confidential and the information in it may not be used or disclosed except for the purpose for which it has been sent. If you have reason to believe that you are not the intended recipient of this communication, please contact the sender immediately.
More information about the ESS-help