unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lawrence Mitchell <wence@gmx.li>
To: bug-gnu-emacs@gnu.org
Subject: bug#8150: 23.2; cperl-uncomment-region is NOT an inverse of cperl-comment-region
Date: Thu, 03 Mar 2011 10:06:53 +0000	[thread overview]
Message-ID: <m3tyfkecw2.fsf@e4300lm.epcc.ed.ac.uk> (raw)
In-Reply-To: <878vwxgb07.fsf@cds.caltech.edu>

Dima Kogan wrote:
> I can and I do, but the current behavior seems wrong. If
> (comment-region beg end -1) is no longer supported, it should generate
> an error instead of succeeding badly. Should we simply call
> (uncomment-region beg end 1) in that case? I can make the patch, but
> would need to know what the current plan is.

Note that the problem is that (uncomment-region A B 1) is not the
inverse of (comment-region A B 1).  Irrespective of the major
mode in effect:

emacs -Q

C-x h
C-1 M-x comment-region RET
C-x h
C-1 M-x uncomment-region RET

Note how there is now a space at the beginning of every line in
the *scratch* buffer.

This is due to the following code in uncomment-region-default:

|	  (if (null arg) (delete-region (point-min) (point))
|	    (skip-syntax-backward " ")
|	    (delete-char (- numarg))

   # foo bar
     ^ point is here when the above code is called.

If an argument is supplied, arg is non-nil and so to delete the
comment we first move backwards over whitespace and then delete
as many comment characters as specified by the argument (1 in
this case).

This patch appears to do the right thing from my minimal testing,
but I don't know if it will have any unfortunate side-effects:

2011-03-03  Lawrence Mitchell  <wence@gmx.li>

	Make uncomment-region the inverse of comment-region.

	* newcomment.el (uncomment-region-default): Delete
          skipped-over whitespace if all comment characters have
          been removed.

	This makes M-1 M-x uncomment-region RET the inverse of
	M-1 M-x comment-region RET.  Previously, commenting and
	then uncommenting a region with an argument would leave a
	space at the beginning of each line.

diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index d88b76a..bcdc1e6 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -871,15 +871,20 @@ comment markers."
 	  (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei)))
 	    (goto-char (match-end 0)))
 	  (if (null arg) (delete-region (point-min) (point))
-	    (skip-syntax-backward " ")
-	    (delete-char (- numarg))
-	    (unless (or (bobp)
-			(save-excursion (goto-char (point-min))
-					(looking-at comment-start-skip)))
-	      ;; If there's something left but it doesn't look like
-	      ;; a comment-start any more, just remove it.
-	      (delete-region (point-min) (point))))
-
+            (let* ((opoint (point-marker))
+                   (nchar (skip-syntax-backward " ")))
+              (delete-char (- numarg))
+              (unless (or (bobp)
+                          (save-excursion (goto-char (point-min))
+                                          (looking-at comment-start-skip)))
+                ;; If there's something left but it doesn't look like
+                ;; a comment-start any more, just remove it.
+                (delete-region (point-min) (point)))
+              (save-excursion
+                (goto-char (point-min))
+                (unless (looking-at comment-start-skip)
+                  (goto-char opoint)
+                  (delete-char nchar)))))
 	  ;; Remove the end-comment (and leading padding and such).
 	  (goto-char (point-max)) (comment-enter-backward)
 	  ;; Check for special `=' used sometimes in comment-box.


-- 
Lawrence Mitchell <wence@gmx.li>






  reply	other threads:[~2011-03-03 10:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02  8:52 bug#8150: 23.2; cperl-uncomment-region is NOT an inverse of cperl-comment-region Dima Kogan
2011-03-02 17:30 ` Glenn Morris
2011-03-03  4:38   ` Dima Kogan
2011-03-03 10:06     ` Lawrence Mitchell [this message]
2012-02-17 12:47       ` Lawrence Mitchell
2012-02-17 15:45         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3tyfkecw2.fsf@e4300lm.epcc.ed.ac.uk \
    --to=wence@gmx.li \
    --cc=bug-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).