unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* emacs: indent automatically on c, c++, php comments
@ 2003-09-06  9:30 Alex Braumann
  2003-09-06 10:37 ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Braumann @ 2003-09-06  9:30 UTC (permalink / raw)


Hi,

I am not familiar with all the functions provided by this wonderful
editor, also the configuration is not a task for 5 minutes :).

I have a simple need:
 If I type a '//' in my emacs, the cursor should jump to column number 30.
 
Is this practicable via the .emacs file in my home dir?

thanks! :)

tc,
alex.

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-06  9:30 emacs: indent automatically on c, c++, php comments Alex Braumann
@ 2003-09-06 10:37 ` Alan Mackenzie
  2003-09-13 12:04   ` Alex Braumann
  0 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2003-09-06 10:37 UTC (permalink / raw)


Alex Braumann <ab@msedv.at> wrote on Sat, 06 Sep 2003 09:30:47 GMT:
> Hi,

> I am not familiar with all the functions provided by this wonderful
> editor, also the configuration is not a task for 5 minutes :).

> I have a simple need:
>  If I type a '//' in my emacs, the cursor should jump to column number 30.

You're using C++ Mode, right?

> Is this practicable via the .emacs file in my home dir?

In essence, yes.  Instead of typing '//', use M-;  (that is, press the
semicolon key whilst holding the Meta key (probably the <alt> or <window>
key).  This will then insert the '//' at comment-column, which is by
default 32.  (if there's room on the line, that is.  If you've already
got a long statement on the line, M-; does the Right Thing).  You can
also use M-; to tidy up existing comments which have got ragged.

If you really, truly, absolutely want your comments at column 30 and not
32, change the value of comment-column in your C++ Mode hook.  If your
reaction to that is "My WHAT??", then the C++ Mode hook is that bit of
code, written by you, which gets executed each time a C++ buffer is
loaded.  Put the following into your .emacs:

(defun my-c++-mode-hook ()
  (setq comment-column 30))
(add-hook 'c++-mode-hook 'my-c++-mode-hook)

Hook functions (like my-c++-mode-hook) typically contain personal
settings for indentation style, tab width, and so on.  You can read all
about this in the CC Mode manual:  C-h i, select CC Mode, then select the
page "Sample .emacs File".

> thanks! :)

> tc,
> alex.

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-06 10:37 ` Alan Mackenzie
@ 2003-09-13 12:04   ` Alex Braumann
  2003-09-13 13:36     ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Braumann @ 2003-09-13 12:04 UTC (permalink / raw)


On Sat, 06 Sep 2003 10:37:40 +0000, Alan Mackenzie wrote:


> You're using C++ Mode, right?

No I'm using PHP Mode at the moment.

> 
>Instead of typing '//', use M-;  (that is, press the
> semicolon key whilst holding the Meta key (probably the <alt> or <window>
> key).  This will then insert the '//' at comment-column, which is by
> default 32.  

M- (alt + ;) produces '//' at column 0!
That's my problem and I don't know how to fix it -> that '//' will appear
on line 32;


> (defun my-c++-mode-hook ()
>   (setq comment-column 30))
> (add-hook 'c++-mode-hook 'my-c++-mode-hook)
> 

This doens't work, unfortunately.

(defun my-php-mode-hook ( )
   (setq comment-column 30))
  (add-hook 'c++-mode-hook 'my-php-mode-hook)

Is it possible that php-mode doens't know comment-column??

Well, as I said, I'm an emacs-rookie.

tc,
alex.

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-13 12:04   ` Alex Braumann
@ 2003-09-13 13:36     ` Alan Mackenzie
  2003-09-13 15:38       ` Alex Braumann
  0 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2003-09-13 13:36 UTC (permalink / raw)


Alex Braumann <ab@msedv.at> wrote on Sat, 13 Sep 2003 12:04:19 GMT:
> On Sat, 06 Sep 2003 10:37:40 +0000, Alan Mackenzie wrote:

> I'm using PHP Mode at the moment.

>> Instead of typing '//', use M-;  (that is, press the semicolon key
>> whilst holding the Meta key (probably the <alt> or <window> key).
>> This will then insert the '//' at comment-column, which is by default
>> 32.  

> M- (alt + ;) produces '//' at column 0!
> That's my problem and I don't know how to fix it -> that '//' will appear
> on line 32;

> This doens't work, unfortunately.

> (defun my-php-mode-hook ( )
>    (setq comment-column 30))
>   (add-hook 'c++-mode-hook 'my-php-mode-hook)

It's your third line that's at fault.

(add-hook 'c++-mode-hook 'my-php-mode-hook) says "Add the function
my-php-mode-hook to the list of functions which is called whenever
C++ MODE is started."

Replace "c++-mode-hook" with "php-mode-hook", giving this:
(add-hook 'php-mode-hook 'my-php-mode-hook)

[Or, if you'd already written that and merely made a typo when composing
your article (it happens to the best of us) come back again!]

> Is it possible that php-mode doens't know comment-column??

No, comment-column is part of the Emacs base itself.  (Note: variables
which are part of a package have a prefix indicating this:  If
current-column had belonged to CC Mode, it would have been called
"c-comment-column"). 

> Well, as I said, I'm an emacs-rookie.

Keep learning, keep having fun!

> tc,
> alex.

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-13 13:36     ` Alan Mackenzie
@ 2003-09-13 15:38       ` Alex Braumann
  2003-09-13 18:59         ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Braumann @ 2003-09-13 15:38 UTC (permalink / raw)


On Sat, 13 Sep 2003 13:36:52 +0000, Alan Mackenzie wrote:



>> (defun my-php-mode-hook ( )
>>    (setq comment-column 30))
>>   (add-hook 'c++-mode-hook 'my-php-mode-hook)
> 
> It's your third line that's at fault.
> 
> (add-hook 'c++-mode-hook 'my-php-mode-hook) says "Add the function
> my-php-mode-hook to the list of functions which is called whenever C++
> MODE is started."
> 
> Replace "c++-mode-hook" with "php-mode-hook", giving this: (add-hook
> 'php-mode-hook 'my-php-mode-hook)
> 
> [Or, if you'd already written that and merely made a typo when composing
> your article (it happens to the best of us) come back again!]
> 
> 
It has been a typo :)

so, here I am!

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-13 15:38       ` Alex Braumann
@ 2003-09-13 18:59         ` Alan Mackenzie
  2003-09-14 13:33           ` Alex Braumann
  0 siblings, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2003-09-13 18:59 UTC (permalink / raw)


Alex Braumann <ab@msedv.at> wrote on Sat, 13 Sep 2003 15:38:38 GMT:
> On Sat, 13 Sep 2003 13:36:52 +0000, Alan Mackenzie wrote:

>>> (defun my-php-mode-hook ( )
>>>    (setq comment-column 30))
>>>   (add-hook 'c++-mode-hook 'my-php-mode-hook)

>> It's your third line that's at fault.

>> (add-hook 'c++-mode-hook 'my-php-mode-hook) says "Add the function
>> my-php-mode-hook to the list of functions which is called whenever C++
>> MODE is started."

>> Replace "c++-mode-hook" with "php-mode-hook", giving this: (add-hook
>> 'php-mode-hook 'my-php-mode-hook)

>> [Or, if you'd already written that and merely made a typo when composing
>> your article (it happens to the best of us) come back again!]


> It has been a typo :)

> so, here I am!

Hi, there!

I've actually loaded up the mode and tried it out.  I should have done
this earlier.  :-(

What I see is that M-; on a _blank_ line leaves the "//" at column zero.
On a non-blank line (even if it's only got a single space), the "//" does
indeed go to column 32 (or 30).

So if you want a comment at C30 on an otherwise blank line, type a single
space followed by M-;

If you have a line with a comment at C0, and you want to reallign it to
C30, type a single space at the start of the line, followed by M-;  .
This will move the existing comment rather than creating a silly "second
comment" on the line.

Finally, a useful command if you've got a comment at C30 but you really
wanted it at C0 is M-\ 'delete-horizontal-space', which does what it
says.  [Yes, I know M-\ is awkward to type on a German keyboard layout.
You can use <esc> \ (two separate key actions) instead.]

Hope all this works as described and does what you want.  If not, come
back yet again!

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-13 18:59         ` Alan Mackenzie
@ 2003-09-14 13:33           ` Alex Braumann
  2003-09-15 15:21             ` Stefan Monnier
  2003-09-17 13:42             ` Alan Mackenzie
  0 siblings, 2 replies; 12+ messages in thread
From: Alex Braumann @ 2003-09-14 13:33 UTC (permalink / raw)




yes you're right, concerning the character. unfortunately does a single
blank not satisfy my php-mode :(.

To get a line-30/32 comment, I have to do the following:

c M-+';' 	//c stands for a character
<blank> M- ';' doesn't work...

It's not very helpful to get this.

d                    //This is a comment.
-> Everytime I write a comment, I have to delete the character afterwards
at column 0??? That's a little bit nerving.


alex.

Besides: I'm using an English keyboard - so: M-s is not that hard for me :)

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-14 13:33           ` Alex Braumann
@ 2003-09-15 15:21             ` Stefan Monnier
  2003-09-15 19:50               ` Alex Braumann
  2003-09-17 13:42             ` Alan Mackenzie
  1 sibling, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2003-09-15 15:21 UTC (permalink / raw)


> <blank> M- ';' doesn't work...

It is unusual to want to indent comments to column 30 when there's no other
text on the line.  Could you describe a bit more of what you want the whole
code with comments to look like ?


        Stefan

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-15 15:21             ` Stefan Monnier
@ 2003-09-15 19:50               ` Alex Braumann
  2003-09-15 20:13                 ` Stefan Monnier
  0 siblings, 1 reply; 12+ messages in thread
From: Alex Braumann @ 2003-09-15 19:50 UTC (permalink / raw)


On Mon, 15 Sep 2003 15:21:03 +0000, Stefan Monnier wrote:

>> <blank> M- ';' doesn't work...
> 
> It is unusual to want to indent comments to column 30 when there's no other
> text on the line.  Could you describe a bit more of what you want the whole
> code with comments to look like ?
> 

It's programming-layout-stuff. There code should be fluent, not
interrupted by comments.

Therefore the comments are put at c30 on every line, regardless from begin
a pure comment line or not.

alex.

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-15 19:50               ` Alex Braumann
@ 2003-09-15 20:13                 ` Stefan Monnier
  0 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2003-09-15 20:13 UTC (permalink / raw)


> Therefore the comments are put at c30 on every line, regardless from begin
> a pure comment line or not.

I think that you can use M-x indent-for-comment to do what you want.

TAB will probably mess up your alignment, but you might be able to
adjust the indentation rules for // comments as well.  See the CC-mode
manual to figure out how to adjust indentation rules.


        Stefan

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-14 13:33           ` Alex Braumann
  2003-09-15 15:21             ` Stefan Monnier
@ 2003-09-17 13:42             ` Alan Mackenzie
  2003-09-18  7:44               ` Alex Braumann
  1 sibling, 1 reply; 12+ messages in thread
From: Alan Mackenzie @ 2003-09-17 13:42 UTC (permalink / raw)


[cc: to poster]

Alex Braumann <ab@msedv.at> wrote on Sun, 14 Sep 2003 13:33:02 GMT:

> yes you're right, concerning the character. unfortunately does a single
> blank not satisfy my php-mode :(.

It doesn't for me any more.  It did on Saturday.  I don't know why.  :-(
Sorry.

I've been having at look at this over the last few days.  I think I've
got the answer.  Could you put the following into your .emacs, please:

(defun my-php-setup-hook ()
  (setq c-comment-only-line-offset '(30 . 30))
  (c-set-offset 'comment-intro 'c-lineup-comment))
(add-hook 'php-mode-user-hook 'my-php-setup-hook)

I think it does what you want.

> alex.

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: emacs: indent automatically on c, c++, php comments
  2003-09-17 13:42             ` Alan Mackenzie
@ 2003-09-18  7:44               ` Alex Braumann
  0 siblings, 0 replies; 12+ messages in thread
From: Alex Braumann @ 2003-09-18  7:44 UTC (permalink / raw)


On Wed, 17 Sep 2003 13:42:30 +0000, Alan Mackenzie wrote:

>
> 
> (defun my-php-setup-hook ()
>   (setq c-comment-only-line-offset '(30 . 30))
>   (c-set-offset 'comment-intro 'c-lineup-comment))
> (add-hook 'php-mode-user-hook 'my-php-setup-hook)
> 
> I think it does what you want.

It doens't - not for me! :). IMHO, php-mode depends on c++-mode, because
my c++-mode has the same problem with comments.

c-mode produces: /*  */

yes, that's the way it is.

alex.

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

end of thread, other threads:[~2003-09-18  7:44 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-06  9:30 emacs: indent automatically on c, c++, php comments Alex Braumann
2003-09-06 10:37 ` Alan Mackenzie
2003-09-13 12:04   ` Alex Braumann
2003-09-13 13:36     ` Alan Mackenzie
2003-09-13 15:38       ` Alex Braumann
2003-09-13 18:59         ` Alan Mackenzie
2003-09-14 13:33           ` Alex Braumann
2003-09-15 15:21             ` Stefan Monnier
2003-09-15 19:50               ` Alex Braumann
2003-09-15 20:13                 ` Stefan Monnier
2003-09-17 13:42             ` Alan Mackenzie
2003-09-18  7:44               ` Alex Braumann

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