[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: awesome feature (yet to be added?)
From: |
Stephen Berman |
Subject: |
Re: awesome feature (yet to be added?) |
Date: |
Sun, 04 May 2014 13:12:25 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.90 (gnu/linux) |
On Sat, 3 May 2014 21:23:37 -0400 (EDT) Bric <address@hidden> 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
- awesome feature (yet to be added?), Bric, 2014/05/03
- Re: awesome feature (yet to be added?), Bric, 2014/05/03
- Re: awesome feature (yet to be added?), Le Wang, 2014/05/05
- Re: awesome feature (yet to be added?), Davis Herring, 2014/05/05
- Re: awesome feature (yet to be added?), Stephen J. Turnbull, 2014/05/06
- Re: awesome feature (yet to be added?), Robert Thorpe, 2014/05/06
- Re: awesome feature (yet to be added?), Thorsten Jolitz, 2014/05/30
- Re: awesome feature (yet to be added?), Stefan Monnier, 2014/05/30
- Re: awesome feature (yet to be added?), Thorsten Jolitz, 2014/05/31
- Re: awesome feature (yet to be added?), Andreas Röhler, 2014/05/31
- Re: awesome feature (yet to be added?), Thorsten Jolitz, 2014/05/31