unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Bric <bric@flight.us>
Cc: emacs-devel@gnu.org
Subject: Re: awesome feature (yet to be added?)
Date: Sun, 04 May 2014 13:12:25 +0200	[thread overview]
Message-ID: <87r449hk6e.fsf@rosalinde.fritz.box> (raw)
In-Reply-To: <660280578.1034380.1399166618013.open-xchange@email.1and1.com> (bric@flight.us's message of "Sat, 3 May 2014 21:23:37 -0400 (EDT)")

On Sat, 3 May 2014 21:23:37 -0400 (EDT) Bric <bric@flight.us> wrote:

> I had some private responses that suggest my original post wasn't too clear; i
> left my main idea obscurely implied:
>
> I am suggesting an INVERSION or reversal of whatever commented/uncommented state
> of EVERY LINE in the selected region.
>
> See my example below:  the before and after states are inverted.  The before
> state has a commented block then an uncommented block. 
>
> My hypothetical command reverses that: the after state has an uncommented block
> followed by a commented block.  That effect should take place in one command,
> with the entire eight lines of code selected a single selected block to which to
> apply the command.
>
> hope this clarifies it...

I don't know if it's worth adding to Emacs, but this seems to do what
you want:

(defun srb-comment-region-invert (beg end)
  "Comment lines in region if uncommented, uncomment them if commented."
  (interactive "r")
  (setq end (save-excursion (goto-char end) (point-marker)))
  (goto-char beg)
    (while (< (point) end)
      (let ((beg0 (line-beginning-position))
	    (end0 (line-end-position)))
	(if (progn
	      (skip-syntax-forward " " end0)
	      (looking-at (regexp-quote comment-start)))
	    (uncomment-region beg0 end0)
	  (when (> end0 beg0)(comment-region beg0 end0)))
	(forward-line)))
    (font-lock-fontify-region beg end))

Steve Berman



  reply	other threads:[~2014-05-04 11:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-03 18:47 awesome feature (yet to be added?) Bric
2014-05-04  1:23 ` Bric
2014-05-04 11:12   ` Stephen Berman [this message]
2014-05-04 18:33   ` Andreas Röhler
2014-05-06  2:32 ` Le Wang
2014-05-06  2:45   ` Davis Herring
2014-05-06  8:19     ` Stephen J. Turnbull
2014-05-06 22:27     ` Robert Thorpe
2014-05-30 21:35     ` Thorsten Jolitz
2014-05-31  1:30       ` Stefan Monnier
2014-05-31 10:46         ` Thorsten Jolitz
2014-06-09 11:01         ` Thorsten Jolitz
2014-06-09 15:30           ` Stefan Monnier
2014-05-31  6:26       ` Andreas Röhler
2014-05-31 10:52         ` Thorsten Jolitz
2014-05-31 17:20           ` Andreas Röhler
2014-05-31 20:04             ` Thorsten Jolitz
2014-06-01  7:00               ` Andreas Röhler

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=87r449hk6e.fsf@rosalinde.fritz.box \
    --to=stephen.berman@gmx.net \
    --cc=bric@flight.us \
    --cc=emacs-devel@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).