DoubleSpaceDefuns

Here’s my function to insert/remove lines between function definitions so that there is exactly 1 blank line separating them:

    (defun double-space-defuns ()
      (interactive "*")
      (save-excursion
        (goto-char (point-min))
        (while (search-forward "defun" nil t)
          (end-of-defun)
          (cond ((and (line-empty-p) (line-empty-p 2))
                 (delete-blank-lines))
                ((not (line-empty-p))
                 (insert-string "\n"))))))
    
    (defun line-empty-p (&optional offset)
      (= (line-beginning-position offset)
         (line-end-position offset)))