[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] factor out comment-or-uncomment feature from comment-dwim
From: |
Benjamin Rutt |
Subject: |
[patch] factor out comment-or-uncomment feature from comment-dwim |
Date: |
Sat, 06 Apr 2002 23:19:45 -0500 |
User-agent: |
Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.1 (sparc-sun-solaris2.6) |
During a discussion today on gnu.emacs.help, I lamented the fact that
only emacs users who were using `transient-mark-mode' could take
advantage of `comment-dwim's ability to detect whether a region is
commented, and uncomment the region if so and comment the region if
not. I personally don't use `transient-mark-mode', but I would hate
to lose out on `comment-dwim's neat feature just because I don't use
`transient-mark-mode'.
An idea that came out of that discussion was to factor the
comment-or-uncomment feature out of `comment-dwim' and place that code
in a new function named `comment-or-uncomment-region' that would be
callable interactively. And then have `comment-dwim' make a call to
`comment-or-uncomment-region' in the appropriate place. But since
`comment-or-uncomment-region' can also be called interactively, this
change would make me very happy because I could gain the "comment or
uncomment" feature of `comment-dwim' without having to use
`transient-mark-mode'.
So I guess the question is, have I convinced the maintainer of
newcomment.el that this change is worthwhile?
BTW, if necessary, I have signed papers for emacs already. Here
begins the patch, against tonight's cvs:
*** newcomment.el.~1.45.~ Sun Mar 3 20:10:55 2002
--- newcomment.el Sat Apr 6 22:00:07 2002
***************
*** 893,898 ****
--- 893,911 ----
(comment-region beg end (+ comment-add arg))))
;;;###autoload
+ (defun comment-or-uncomment-region (beg end &optional arg)
+ "Call `comment-region', unless the region only consists of comments,
+ in which case call `uncomment-region'. If a prefix arg is given, it
+ is passed on to the respective function."
+ (interactive "*r\nP")
+ (if (save-excursion ;; check for already commented region
+ (goto-char beg)
+ (comment-forward (point-max))
+ (<= end (point)))
+ (uncomment-region beg end arg)
+ (comment-region beg end arg)))
+
+ ;;;###autoload
(defun comment-dwim (arg)
"Call the comment command you want (Do What I Mean).
If the region is active and `transient-mark-mode' is on, call
***************
*** 906,917 ****
(if (and mark-active transient-mark-mode)
(let ((beg (min (point) (mark)))
(end (max (point) (mark))))
! (if (save-excursion ;; check for already commented region
! (goto-char beg)
! (comment-forward (point-max))
! (<= end (point)))
! (uncomment-region beg end arg)
! (comment-region beg end arg)))
(if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
;; FIXME: If there's no comment to kill on this line and ARG is
;; specified, calling comment-kill is not very clever.
--- 919,925 ----
(if (and mark-active transient-mark-mode)
(let ((beg (min (point) (mark)))
(end (max (point) (mark))))
! (comment-or-uncomment-region beg end))
(if (save-excursion (beginning-of-line) (not (looking-at "\\s-*$")))
;; FIXME: If there's no comment to kill on this line and ARG is
;; specified, calling comment-kill is not very clever.
--
Benjamin
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [patch] factor out comment-or-uncomment feature from comment-dwim,
Benjamin Rutt <=