help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How make comment-region NOT ignore blank lines but comment out those


From: Kevin Rodgers
Subject: Re: How make comment-region NOT ignore blank lines but comment out those too?
Date: Thu, 28 Aug 2003 10:49:32 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Christian Seberino wrote:

Thanks.

Is it possible to do a search and replace automatically as a "hook" to
comment-region????

The file will have this problem as "\n#  \n".
I just have to replace that with "\n#\n".

I believe this is called a regular expression??

Can they be run every time we do a comment-region?

You can always try (this is completely untested):

(defadvice comment-region (after unpad-blank-line-comments)
  "If blank lines are commented, delete `comment-padding' on those lines."
  (if (and (null (ad-get-arg 2))        ; (null ARG), (null current-prefix-arg)
           comment-empty-lines)
      ;; We are commenting, not uncommenting.
      (let ((empty-comment-regexp (format "^[ \t]*\\(%s\\)\\(%s\\)$"
                                          comment-start
                                          comment-padding)))
        (save-restriction
          (narrow-to-region (ad-get-arg 0) (ad-get-arg 1)) ; (... BEG END)
          (goto-char (point-min))
          (while (re-search-forward empty-comment-regexp nil t)
            (replace-match "" nil nil nil 2))))))

--
Kevin Rodgers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]