emacs-devel
[Top][All Lists]
Advanced

[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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]