I created some functions for Emacs because I really didn't want to do this stuff by hand. I have here four functions: count-occurences, line-empty?, unfill-region, unfill-buffer. You can either read the rest of this post, or click here to get the file.
Here's the code for each:
count-occurences
(defun count-occurences (string)
"Counts the number of occurences of STRING in the buffer."
(interactive (list (read-string "Count: ")))
(let ((point (point))
(counter 0))
(beginning-of-buffer)
(loop with pos = t
until (not (search-forward string (point-max) t))
do (incf counter))
(goto-char point)
(message (format "%d occurences" counter))
counter))
line-empty?
(defun line-empty? () "Returns true if the current line is empty." (eq (line-beginning-position) (line-end-position)))
unfill-region
(defun unfill-region (min max)
"Joins the lines in the paragraphs inside a
region defined by MIN and MAX. If this is called
interactively then the mark and point are used to
define the region."
(interactive (list (mark)
(point)))
(if (> min max)
(let ((temp min))
(setq min max)
(setq max temp)))
(goto-char min)
(message (format "%d %d" min max))
(let ((empty nil))
(message "Unfilling...")
(loop with end = min
always (< end max)
do
(setq end (line-end-position))
(setq empty (line-empty?))
(next-line 1)
(if (not empty)
(if (not (line-empty?))
(join-line))))
(message "Unfilled")))
unfill-buffer
(defun unfill-buffer ()
"Joins the lines of all the paragraphs of a buffer."
(interactive)
(let ((point (point)))
(unfill-region (point-min) (point-max))
(goto-char point)))


