unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* automatic indentation in C,C++ modes
@ 2002-04-12 22:56 Tony Harbin
  2002-04-13  1:06 ` Greg Hill
  0 siblings, 1 reply; 8+ messages in thread
From: Tony Harbin @ 2002-04-12 22:56 UTC (permalink / raw)


How do I turn off all automatic indentation in C and C++ modes?  I find
this
behavior *VERY* annoying and would like to disable it permanently (i.e.
in the
.emacs file)

Thanks for your time.

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

* Re: automatic indentation in C,C++ modes
  2002-04-12 22:56 automatic indentation in C,C++ modes Tony Harbin
@ 2002-04-13  1:06 ` Greg Hill
  2002-04-15 16:51   ` Tony Harbin
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Hill @ 2002-04-13  1:06 UTC (permalink / raw)


At 5:56 PM -0500 4/12/02, Tony Harbin wrote:
>How do I turn off all automatic indentation in C and C++ modes?  I find
>this
>behavior *VERY* annoying and would like to disable it permanently (i.e.
>in the
>.emacs file)
>
>Thanks for your time.

Tony,

If all you want is to insert a tab character at the beginning of a 
line when you type the tab key, try adding this to your .emacs file:

(add-hook 'c-mode-hook
	(function (lambda ()
		(substitute-key-definition
		'c-indent-command 'self-insert-command c-mode-map))))

(add-hook 'c++-mode-hook
	(function (lambda ()
		(substitute-key-definition
		'c-indent-command 'self-insert-command c++-mode-map))))

If, while you are at it, you also want to define the size of a tab 
as, say, 3 spaces, make it:

(add-hook 'c-mode-hook
	(function (lambda ()
		(substitute-key-definition
		'c-indent-command 'self-insert-command c-mode-map)
		(setq tab-width 3))))


--Greg

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

* Re: automatic indentation in C,C++ modes
  2002-04-13  1:06 ` Greg Hill
@ 2002-04-15 16:51   ` Tony Harbin
  2002-04-15 18:47     ` Greg Hill
  0 siblings, 1 reply; 8+ messages in thread
From: Tony Harbin @ 2002-04-15 16:51 UTC (permalink / raw)
  Cc: help-gnu-emacs

Not quite.  C/C++ mode binds open-paren, open-brace, colon, and slash (among

others) to "electric" functions that, when the key is typed, automatically
change
the spacing and/or indentation on the line.  I would like to
disable/override/turn off this behavior.  I was able to do this in an older
version where I had to explicitly load the C/C++ mode modules, but in my
current version (20.7.1), the stuff was already compiled in and the same
tricks no longer work.

Basically, I would just like those keys above to just self-insert and not
run the
"electric" functions.  Is there a way to do this?

Thanks.

Greg Hill wrote:

> At 5:56 PM -0500 4/12/02, Tony Harbin wrote:
> >How do I turn off all automatic indentation in C and C++ modes?  I find
> >this
> >behavior *VERY* annoying and would like to disable it permanently (i.e.
> >in the
> >.emacs file)
> >
> >Thanks for your time.
>
> Tony,
>
> If all you want is to insert a tab character at the beginning of a
> line when you type the tab key, try adding this to your .emacs file:
>
> (add-hook 'c-mode-hook
>         (function (lambda ()
>                 (substitute-key-definition
>                 'c-indent-command 'self-insert-command c-mode-map))))
>
> (add-hook 'c++-mode-hook
>         (function (lambda ()
>                 (substitute-key-definition
>                 'c-indent-command 'self-insert-command c++-mode-map))))
>
> If, while you are at it, you also want to define the size of a tab
> as, say, 3 spaces, make it:
>
> (add-hook 'c-mode-hook
>         (function (lambda ()
>                 (substitute-key-definition
>                 'c-indent-command 'self-insert-command c-mode-map)
>                 (setq tab-width 3))))
>
> --Greg

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

* Re: automatic indentation in C,C++ modes
  2002-04-15 16:51   ` Tony Harbin
@ 2002-04-15 18:47     ` Greg Hill
  2002-04-19 17:30       ` Tony Harbin
  0 siblings, 1 reply; 8+ messages in thread
From: Greg Hill @ 2002-04-15 18:47 UTC (permalink / raw)
  Cc: help-gnu-emacs

Tony,

It just takes more of the same, e.g.:

(add-hook 'c-mode-hook
          (function (lambda ()
                  (substitute-key-definition
                  'c-indent-command 'self-insert-command c-mode-map)
                  (substitute-key-definition
                  'c-electric-paren 'self-insert-command c-mode-map))))

M-x apropos
	c-electric

will give you a list of all the c-electric-  commands.  Just use 
substitute-key-definition in your c-mode-hook and c++-mode-hook 
lambdas to replace any of them that you don't want with 
self-insert-command.  If you want to keep the automatic indentation 
performed by the TAB key and ditch only the "electric" stuff, then 
just leave the substitution for c-indent-command out of your lambdas.

--Greg



At 11:51 AM -0500 4/15/02, Tony Harbin wrote:
>Not quite.  C/C++ mode binds open-paren, open-brace, colon, and slash (among
>
>others) to "electric" functions that, when the key is typed, automatically
>change
>the spacing and/or indentation on the line.  I would like to
>disable/override/turn off this behavior.  I was able to do this in an older
>version where I had to explicitly load the C/C++ mode modules, but in my
>current version (20.7.1), the stuff was already compiled in and the same
>tricks no longer work.
>
>Basically, I would just like those keys above to just self-insert and not
>run the
>"electric" functions.  Is there a way to do this?

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

* Re: automatic indentation in C,C++ modes
  2002-04-15 18:47     ` Greg Hill
@ 2002-04-19 17:30       ` Tony Harbin
  2002-04-22 17:08         ` Emacs as web server Greg Hill
  2002-04-23  2:01         ` automatic indentation in C,C++ modes G Anna
  0 siblings, 2 replies; 8+ messages in thread
From: Tony Harbin @ 2002-04-19 17:30 UTC (permalink / raw)
  Cc: Greg Hill, help-gnu-emacs

No go.  I've inserted these commands into my .emacs file, but still, when I type
a "(", the line gets re-indented.  Also, when I do a "C-h k (", the key is still
described as running c-electric-paren.

I had this behavior turned off in an older version on Solaris, but the methods
that I used there no longer work.  The best solution would be to remap the
'(', '{', ':', and '/' keys to simple self-insert-command functions.  I have a
particular indentation style that is common where I work and I *hate* some
software trying to enforce it's own style.

Any other suggestions?  Thanks in advance.

Greg Hill wrote:

> Tony,
>
> It just takes more of the same, e.g.:
>
> (add-hook 'c-mode-hook
>           (function (lambda ()
>                   (substitute-key-definition
>                   'c-indent-command 'self-insert-command c-mode-map)
>                   (substitute-key-definition
>                   'c-electric-paren 'self-insert-command c-mode-map))))
>
> M-x apropos
>         c-electric
>
> will give you a list of all the c-electric-  commands.  Just use
> substitute-key-definition in your c-mode-hook and c++-mode-hook
> lambdas to replace any of them that you don't want with
> self-insert-command.  If you want to keep the automatic indentation
> performed by the TAB key and ditch only the "electric" stuff, then
> just leave the substitution for c-indent-command out of your lambdas.
>
> --Greg
>
> At 11:51 AM -0500 4/15/02, Tony Harbin wrote:
> >Not quite.  C/C++ mode binds open-paren, open-brace, colon, and slash (among
> >
> >others) to "electric" functions that, when the key is typed, automatically
> >change
> >the spacing and/or indentation on the line.  I would like to
> >disable/override/turn off this behavior.  I was able to do this in an older
> >version where I had to explicitly load the C/C++ mode modules, but in my
> >current version (20.7.1), the stuff was already compiled in and the same
> >tricks no longer work.
> >
> >Basically, I would just like those keys above to just self-insert and not
> >run the
> >"electric" functions.  Is there a way to do this?
>
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Emacs as web server
  2002-04-19 17:30       ` Tony Harbin
@ 2002-04-22 17:08         ` Greg Hill
  2002-04-23  2:01         ` automatic indentation in C,C++ modes G Anna
  1 sibling, 0 replies; 8+ messages in thread
From: Greg Hill @ 2002-04-22 17:08 UTC (permalink / raw)


If anyone has any experience using Emacs as a web server, I would be 
delighted to talk with you about it off-forum.  I am not having any 
particular problems.  I would just like to compare notes and possibly 
exchange relevant Lisp code.

--Greg

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

* Re: automatic indentation in C,C++ modes
  2002-04-19 17:30       ` Tony Harbin
  2002-04-22 17:08         ` Emacs as web server Greg Hill
@ 2002-04-23  2:01         ` G Anna
  2002-04-24 15:53           ` Tony Harbin
  1 sibling, 1 reply; 8+ messages in thread
From: G Anna @ 2002-04-23  2:01 UTC (permalink / raw)
  Cc: help-gnu-emacs


> Date: Fri, 19 Apr 2002 12:30:46 -0500
> From: Tony Harbin <tharbin@hiwaay.net>
> Subj: Re: automatic indentation in C,C++ modes

[snip]

> self-insert-command functions.  I have a particular indentation
> style that is common where I work and I *hate* some software trying
> to enforce it's own style.

My understanding is that GNU Emacs doesn't do anything unless its
asked to do so.  Below, I am quoting an extract from the Emacs info
documentation.  Is this of any help?

<info>
Electric C Characters

   In C mode and related modes, certain printing characters are
"electric"--in addition to inserting themselves, they also reindent
the current line and may insert newlines.  This feature is controlled
by the variable `c-auto-newline'.  The "electric" characters are `{',
`}', `:', `#', `;', `,', `<', `>', `/', `*', `(', and `)'.

   Electric characters insert newlines only when the "auto-newline"
feature is enabled (indicated by `/a' in the mode line after the mode
name).  This feature is controlled by the variable `c-auto-newline'.
You can turn this feature on or off with the command `C-c C-a':

`C-c C-a'
     Toggle the auto-newline feature (`c-toggle-auto-state').  With a
     prefix argument, this command turns the auto-newline feature on if
     the argument is positive, and off if it is negative.
</info>

HTH

anna

-- 

Get your free e-mail account at http://www.linuxmail.org

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

* Re: automatic indentation in C,C++ modes
  2002-04-23  2:01         ` automatic indentation in C,C++ modes G Anna
@ 2002-04-24 15:53           ` Tony Harbin
  0 siblings, 0 replies; 8+ messages in thread
From: Tony Harbin @ 2002-04-24 15:53 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 814 bytes --]

Thanks to all who helped with this.  I finally found the answer.

In my .emacs file, I had 2 lines:

(autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
(autoload 'c-mode   "cc-mode" "C Editing Mode" t)

However, near as I can tell, these did not actually load anything until a
file matching the mode criteria was visited.  Any lines referencing any
variables
defined by those modes were not defined in emacs' scope until a file of the
mode type was visited.  By then it's too late to affect any of the
variables.  By changing
the lines to:

(load "cplus-md.elc")
(load "c-mode.elc")

The variables (especially c-auto-newline...thanks G Anna!) are now defined
and can be manipulated; in my case, to turn off the auto-indentation
feature:

(setq c-auto-newline nil)

This gets me what I need, but is it wasteful?



[-- Attachment #2: Type: text/html, Size: 1029 bytes --]

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

end of thread, other threads:[~2002-04-24 15:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-12 22:56 automatic indentation in C,C++ modes Tony Harbin
2002-04-13  1:06 ` Greg Hill
2002-04-15 16:51   ` Tony Harbin
2002-04-15 18:47     ` Greg Hill
2002-04-19 17:30       ` Tony Harbin
2002-04-22 17:08         ` Emacs as web server Greg Hill
2002-04-23  2:01         ` automatic indentation in C,C++ modes G Anna
2002-04-24 15:53           ` Tony Harbin

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