* [patch] factor out comment-or-uncomment feature from comment-dwim
@ 2002-04-07 4:19 Benjamin Rutt
0 siblings, 0 replies; only message in thread
From: Benjamin Rutt @ 2002-04-07 4:19 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-04-07 4:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-07 4:19 [patch] factor out comment-or-uncomment feature from comment-dwim Benjamin Rutt
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.