unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* c-like comments settings
@ 2013-01-03 19:45 Luca Ferrari
  2013-01-04  4:35 ` drain
  0 siblings, 1 reply; 3+ messages in thread
From: Luca Ferrari @ 2013-01-03 19:45 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,
this is surely trivial but I don't know how to do it. I'd like to know
if it is possible to configure the comments (M-;) in c and c-based
modes (e.g. php) to do the following:

1) if a comment is started on a blank line to open it with a
decorator, so that the following

    /* here-the-cursor */

becomes like the following:

   /*
    * here-the-cursor
    */

but keeping the normal commenting for code lines as follows:

   int my_variable:  /* here the cursor within comment with no decorators */

2) to indent comments so that are all aligned depending on the
rightmost one, so that the following:

    int a_very_long_variable_name = 0; /* comment 1 */
    int i = 2; /* comment */

becomes like the following:

    int a_very_long_variable_name = 0; /* comment 1 */
    int i = 2;                                             /* comment */

3) if it is possible to activate a kind of electric "/" when editing a
comment so that a "/" on an empty line will automatically
close the comment so that the following:

/*
 * blah
 * blah
 * /

is translated to

/*
 * blah
 * blah
 */

Any hint is appreciated.

Thanks,
Luca



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

* Re: c-like comments settings
  2013-01-03 19:45 c-like comments settings Luca Ferrari
@ 2013-01-04  4:35 ` drain
  2013-01-04  7:52   ` Luca Ferrari
  0 siblings, 1 reply; 3+ messages in thread
From: drain @ 2013-01-04  4:35 UTC (permalink / raw)
  To: Help-gnu-emacs

Very lazy hint: take a look at the comment-region source code:

(defun comment-region (beg end &optional arg)
  "Comment or uncomment each line in the region.
With just \\[universal-argument] prefix arg, uncomment each line in region
BEG .. END.
Numeric prefix ARG means use ARG comment characters.
If ARG is negative, delete that many comment characters instead.

The strings used as comment starts are built from `comment-start'
and `comment-padding'; the strings used as comment ends are built
from `comment-end' and `comment-padding'.

By default, the `comment-start' markers are inserted at the
current indentation of the region, and comments are terminated on
each line (even for syntaxes in which newline does not end the
comment and blank lines do not get comments).  This can be
changed with `comment-style'."
  (interactive "*r\nP")
  (comment-normalize-vars)
  (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
  (save-excursion
    ;; FIXME: maybe we should call uncomment depending on ARG.
    (funcall comment-region-function beg end arg)))




--
View this message in context: http://emacs.1067599.n5.nabble.com/c-like-comments-settings-tp274365p274418.html
Sent from the Emacs - Help mailing list archive at Nabble.com.



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

* Re: c-like comments settings
  2013-01-04  4:35 ` drain
@ 2013-01-04  7:52   ` Luca Ferrari
  0 siblings, 0 replies; 3+ messages in thread
From: Luca Ferrari @ 2013-01-04  7:52 UTC (permalink / raw)
  To: drain; +Cc: Help-gnu-emacs

Thanks for help, but I'm not so lisp-expert to understand what I have
to do by myself just reading the documentation, so any other clue is
appreciated. In the meantime I found the "comment-close-slash"
variable that, if added to the cleanup list, should at least close the
comment with a single slash. Unluckily I tried to do the following:

(add-hook 'c-mode-common-hook
          '(lambda ()
             (add-to-list* 'c-cleanup-list
                           'comment-close-slash)))

which does not work, so I'm getting something wrong....

Luca

On Fri, Jan 4, 2013 at 5:35 AM, drain <aeuster@gmail.com> wrote:
> Very lazy hint: take a look at the comment-region source code:
>
> (defun comment-region (beg end &optional arg)
>   "Comment or uncomment each line in the region.
> With just \\[universal-argument] prefix arg, uncomment each line in region
> BEG .. END.
> Numeric prefix ARG means use ARG comment characters.
> If ARG is negative, delete that many comment characters instead.
>
> The strings used as comment starts are built from `comment-start'
> and `comment-padding'; the strings used as comment ends are built
> from `comment-end' and `comment-padding'.
>
> By default, the `comment-start' markers are inserted at the
> current indentation of the region, and comments are terminated on
> each line (even for syntaxes in which newline does not end the
> comment and blank lines do not get comments).  This can be
> changed with `comment-style'."
>   (interactive "*r\nP")
>   (comment-normalize-vars)
>   (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
>   (save-excursion
>     ;; FIXME: maybe we should call uncomment depending on ARG.
>     (funcall comment-region-function beg end arg)))
>
>
>
>
> --
> View this message in context: http://emacs.1067599.n5.nabble.com/c-like-comments-settings-tp274365p274418.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>



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

end of thread, other threads:[~2013-01-04  7:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-03 19:45 c-like comments settings Luca Ferrari
2013-01-04  4:35 ` drain
2013-01-04  7:52   ` Luca Ferrari

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).