all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Problem with removing comments
@ 2007-12-18  9:09 Markus Grunwald
  2007-12-18 15:20 ` Tyler Smith
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Grunwald @ 2007-12-18  9:09 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

my transition from xemacs to emacs virtually done, thanks to this group :)
Now and then there is a minor problem that I can solve on my own, but this
one here puzzles me: I can't uncomment single lines of code with any of
the emacs functions... This is my setting:

comment-start's value is "//"
comment-padding's value is " "
comment-end's value is ""

;; Function to uncomment a region or a line. Got that some time ago:
(defun chb-uncomment-region-or-line ()
  (interactive)
  (let ((beg 0)
	(end 0))
    (if (region-exists-p)
	(setq beg (region-beginning)
	      end (region-end))
      (save-excursion
	(beginning-of-line)
	(setq beg (point))
	(forward-line)
	(setq end (point))))
    (comment-region beg end -1)))

When I use this function on a commented line (no region marked) or a
commented region, I only get this in the *messages* buffer:
"uncomment-region: Beginning of buffer" and the comment is not changed. No
debugger messages.

So I thougt, maybe commenting works different in emacs and I read the info
file, "21.5.1 Comment Commands". Ok, so there a numerous ways to COMMENT a
line or a region and even a function to kill a comment (hmmm). Not much
help. comment-dwim doesn't do what I mean ;)

What helped a bit was the documentation for comment-region: Now I can
uncomment a region with C-u M-x comment-region. But I don't know how to
"simulate" the "C-u" part in the "chb-uncomment-region-or-line" function.
If that worked, I think everything should be ok...

Don't get me wrong: I know next to nothing about emacs and I willingly
admit that there may be better ways to do this - that's where I need your
help, please...

cu
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Problem with removing comments
  2007-12-18  9:09 Problem with removing comments Markus Grunwald
@ 2007-12-18 15:20 ` Tyler Smith
  0 siblings, 0 replies; 2+ messages in thread
From: Tyler Smith @ 2007-12-18 15:20 UTC (permalink / raw)
  To: help-gnu-emacs

On 2007-12-18, Markus Grunwald <markus.grunwald@gmx.de> wrote:
>
> What helped a bit was the documentation for comment-region: Now I can
> uncomment a region with C-u M-x comment-region. But I don't know how to
> "simulate" the "C-u" part in the "chb-uncomment-region-or-line" function.
> If that worked, I think everything should be ok...

I think you really do want comment-dwim, you just don't know it yet ;)
You can access comment-dwim with M-; so you can uncomment a line with
a few key strokes: "C-a C-spc C-e M-;" If that's too many key strokes,
it should be easy to wrap this in a function similar to what you've
tried, using either comment-dwim for a general case, or
uncomment-region for a function that only uncomments.

From the help:

comment-dwim is an interactive compiled Lisp function in `newcomment.el'.
It is bound to M-;.
(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
  `comment-region' (unless it only consists of comments, in which
  case it calls `uncomment-region').
Else, if the current line is empty, insert a comment and indent it.
Else if a prefix arg is specified, call `comment-kill'.
Else, call `comment-indent'.
You can configure `comment-style' to change the way regions are commented.

HTH,

Tyler

*Written from Emacs22, but I don't think this changed from Emacs21?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-12-18 15:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-18  9:09 Problem with removing comments Markus Grunwald
2007-12-18 15:20 ` Tyler Smith

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.