* How to use c-style to comment a region?
@ 2007-05-10 1:46 William Xue
2007-05-10 8:50 ` martin rudalics
2007-05-10 21:14 ` Alan Mackenzie
0 siblings, 2 replies; 7+ messages in thread
From: William Xue @ 2007-05-10 1:46 UTC (permalink / raw)
To: emacs-devel
Hi,
In cpp files, in following code, for e.g.:
ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * 1000 * 5);
I wanted to modify the second 1000 to 2000 for testing, but wanted to keep
the orignal value for restoring it later.
after selected 1000 and pressed C-c C-c :
ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * // 1000
* 5); // 1 second
Can it be:
ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * /* 1000
*/ * 5); // 1 second
Maybe there are some settings for it, but I havn't found them.
I know that add /* -*- C -*- */ at the beginning of the file can affect
the comment style for the whole file.
That's not my request, I only want a command or a keybinding.
Thanks!
--
Sincerely yours,
William
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 1:46 How to use c-style to comment a region? William Xue
@ 2007-05-10 8:50 ` martin rudalics
2007-05-10 17:22 ` Stefan Monnier
2007-05-11 2:04 ` William Xue
2007-05-10 21:14 ` Alan Mackenzie
1 sibling, 2 replies; 7+ messages in thread
From: martin rudalics @ 2007-05-10 8:50 UTC (permalink / raw)
To: William Xue; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 473 bytes --]
> That's not my request, I only want a command or a keybinding.
You could try to bind
(defun my-cpp-comment-region (beg end &optional arg)
(interactive "*r\nP")
(let ((comment-start "/* ")
(comment-end " */"))
(comment-region beg end arg)))
to a key.
BTW with comment-styles box / box-multi and newline terminated comment
syntax `comment-region' comments out the entire text from the beginning
of the region till EOL. The attached patch should cure that.
[-- Attachment #2: new-comment.patch --]
[-- Type: text/plain, Size: 3162 bytes --]
*** newcomment.el.~1.101.~ Mon Apr 2 07:45:08 2007
--- newcomment.el Thu May 10 10:38:22 2007
***************
*** 926,941 ****
the region rather than at left margin."
;;(assert (< beg end))
(let ((no-empty (not (or (eq comment-empty-lines t)
! (and comment-empty-lines (zerop (length ce)))))))
;; Sanitize CE and CCE.
(if (and (stringp ce) (string= "" ce)) (setq ce nil))
(if (and (stringp cce) (string= "" cce)) (setq cce nil))
;; If CE is empty, multiline cannot be used.
(unless ce (setq ccs nil cce nil))
;; Should we mark empty lines as well ?
(if (or ccs block lines) (setq no-empty nil))
;; Make sure we have end-markers for BLOCK mode.
! (when block (unless ce (setq ce (comment-string-reverse cs))))
;; If BLOCK is not requested, we don't need CCE.
(unless block (setq cce nil))
;; Continuation defaults to the same as CS and CE.
--- 926,943 ----
the region rather than at left margin."
;;(assert (< beg end))
(let ((no-empty (not (or (eq comment-empty-lines t)
! (and comment-empty-lines (zerop (length ce))))))
! ce-sanitized)
;; Sanitize CE and CCE.
(if (and (stringp ce) (string= "" ce)) (setq ce nil))
+ (setq ce-sanitized ce)
(if (and (stringp cce) (string= "" cce)) (setq cce nil))
;; If CE is empty, multiline cannot be used.
(unless ce (setq ccs nil cce nil))
;; Should we mark empty lines as well ?
(if (or ccs block lines) (setq no-empty nil))
;; Make sure we have end-markers for BLOCK mode.
! (when (and block (not ce)) (setq ce (comment-string-reverse cs)))
;; If BLOCK is not requested, we don't need CCE.
(unless block (setq cce nil))
;; Continuation defaults to the same as CS and CE.
***************
*** 945,951 ****
(goto-char end)
;; If the end is not at the end of a line and the comment-end
;; is implicit (i.e. a newline), explicitly insert a newline.
! (unless (or ce (eolp)) (insert "\n") (indent-according-to-mode))
(comment-with-narrowing beg end
(let ((min-indent (point-max))
(max-indent 0))
--- 947,954 ----
(goto-char end)
;; If the end is not at the end of a line and the comment-end
;; is implicit (i.e. a newline), explicitly insert a newline.
! (unless (or ce-sanitized (eolp))
! (insert "\n") (indent-according-to-mode))
(comment-with-narrowing beg end
(let ((min-indent (point-max))
(max-indent 0))
***************
*** 1163,1169 ****
(buffer-substring (point)
(progn (move-to-left-margin)
(point)))))))))))))
!
;;;###autoload
(defun comment-indent-new-line (&optional soft)
--- 1166,1172 ----
(buffer-substring (point)
(progn (move-to-left-margin)
(point)))))))))))))
!
;;;###autoload
(defun comment-indent-new-line (&optional soft)
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 8:50 ` martin rudalics
@ 2007-05-10 17:22 ` Stefan Monnier
2007-05-10 21:40 ` martin rudalics
2007-05-11 2:04 ` William Xue
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2007-05-10 17:22 UTC (permalink / raw)
To: martin rudalics; +Cc: William Xue, emacs-devel
> BTW with comment-styles box / box-multi and newline terminated comment
> syntax `comment-region' comments out the entire text from the beginning
> of the region till EOL. The attached patch should cure that.
I'm not sure I understand the problem (and hence the solution). Can you
show me a recipe to reproduce this problem?
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 1:46 How to use c-style to comment a region? William Xue
2007-05-10 8:50 ` martin rudalics
@ 2007-05-10 21:14 ` Alan Mackenzie
2007-05-11 2:10 ` William Xue
1 sibling, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2007-05-10 21:14 UTC (permalink / raw)
To: William Xue; +Cc: emacs-devel
Hi, William!
On Thu, May 10, 2007 at 09:46:34AM +0800, William Xue wrote:
> Hi,
> In cpp files, in following code, for e.g.:
> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * 1000 * 5);
> I wanted to modify the second 1000 to 2000 for testing, but wanted to
> keep the orignal value for restoring it later.
> after selected 1000 and pressed C-c C-c :
> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * // 1000
> * 5); // 1 second
> Can it be:
> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * /* 1000
> */ * 5); // 1 second
> Maybe there are some settings for it, but I havn't found them.
No, there aren't any such settings.
> I know that add /* -*- C -*- */ at the beginning of the file can affect
> the comment style for the whole file.
> That's not my request, I only want a command or a keybinding.
No, you certainly wouldn't want to have to use C mode just to get the
right sort of comments.
Some while ago, a CC Mode user requested a feature to toggle the type of
comment that M-; inserts within C Mode (i.e. /* ... */ <-> // ... \n).
I intend to write a new command to do just this, probably binding it to
C-c C-;. This will hopefully get implemented in CC Mode 5.32, which I am
hoping to release shortly after both Emacs 22.1 and GPLv3 are done.
> Thanks!
> Sincerely yours,
> William
--
Alan Mackenzie (Ittersbach, Germany).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 17:22 ` Stefan Monnier
@ 2007-05-10 21:40 ` martin rudalics
0 siblings, 0 replies; 7+ messages in thread
From: martin rudalics @ 2007-05-10 21:40 UTC (permalink / raw)
To: Stefan Monnier; +Cc: William Xue, emacs-devel
> I'm not sure I understand the problem (and hence the solution). Can you
> show me a recipe to reproduce this problem?
Sorry for being cryptic. With emacs -Q customize `comment-style' to box
or box-multi. In *scratch* insert
(foo bar baz)
set the region around bar and do `comment-region'. Gets you
(foo ;; bar ;; baz)
instead of
(foo ;; bar ;;
baz)
Responsible is the
(when block (unless ce (setq ce (comment-string-reverse cs))))
line in `comment-region-internal' which makes the subsequent
(unless (or ce (eolp)) (insert "\n") (indent-according-to-mode))
fail. Obviously it fails in the cpp example of the OP as well.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 8:50 ` martin rudalics
2007-05-10 17:22 ` Stefan Monnier
@ 2007-05-11 2:04 ` William Xue
1 sibling, 0 replies; 7+ messages in thread
From: William Xue @ 2007-05-11 2:04 UTC (permalink / raw)
To: martin rudalics; +Cc: emacs-devel
On Thu, 10 May 2007 16:50:20 +0800, martin rudalics <rudalics@gmx.at>
wrote:
> > That's not my request, I only want a command or a keybinding.
>
> You could try to bind
>
> (defun my-cpp-comment-region (beg end &optional arg)
> (interactive "*r\nP")
> (let ((comment-start "/* ")
> (comment-end " */"))
> (comment-region beg end arg)))
>
> to a key.
I bind it to C-; and it works very well.
Thank you very much!
>
> BTW with comment-styles box / box-multi and newline terminated comment
> syntax `comment-region' comments out the entire text from the beginning
> of the region till EOL. The attached patch should cure that.
--
Sincerely yours,
William
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to use c-style to comment a region?
2007-05-10 21:14 ` Alan Mackenzie
@ 2007-05-11 2:10 ` William Xue
0 siblings, 0 replies; 7+ messages in thread
From: William Xue @ 2007-05-11 2:10 UTC (permalink / raw)
To: Alan Mackenzie; +Cc: emacs-devel
On Fri, 11 May 2007 05:14:02 +0800, Alan Mackenzie <acm@muc.de> wrote:
> Hi, William!
>
> On Thu, May 10, 2007 at 09:46:34AM +0800, William Xue wrote:
>> Hi,
>
>> In cpp files, in following code, for e.g.:
>
>> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * 1000 * 5);
>
>> I wanted to modify the second 1000 to 2000 for testing, but wanted to
>> keep the orignal value for restoring it later.
>
>> after selected 1000 and pressed C-c C-c :
>
>> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * // 1000
>> * 5); // 1 second
>
>> Can it be:
>
>> ln_time_out.QuadPart = -((LONGLONG) 10 * 1000 * /* 1000
>> */ * 5); // 1 second
>
>> Maybe there are some settings for it, but I havn't found them.
>
> No, there aren't any such settings.
>
>> I know that add /* -*- C -*- */ at the beginning of the file can affect
>> the comment style for the whole file.
>> That's not my request, I only want a command or a keybinding.
>
> No, you certainly wouldn't want to have to use C mode just to get the
> right sort of comments.
>
> Some while ago, a CC Mode user requested a feature to toggle the type of
> comment that M-; inserts within C Mode (i.e. /* ... */ <-> // ... \n).
> I intend to write a new command to do just this, probably binding it to
> C-c C-;. This will hopefully get implemented in CC Mode 5.32, which I am
> hoping to release shortly after both Emacs 22.1 and GPLv3 are done.
That's a good news for us. We'll wait for it!
Thanks!
:)
>
>> Thanks!
>
>> Sincerely yours,
>> William
>
--
Sincerely yours,
William
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-05-11 2:10 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-10 1:46 How to use c-style to comment a region? William Xue
2007-05-10 8:50 ` martin rudalics
2007-05-10 17:22 ` Stefan Monnier
2007-05-10 21:40 ` martin rudalics
2007-05-11 2:04 ` William Xue
2007-05-10 21:14 ` Alan Mackenzie
2007-05-11 2:10 ` William Xue
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).