help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: In "C" mode, how do I turn off electric mode?


From: Alan Mackenzie
Subject: Re: In "C" mode, how do I turn off electric mode?
Date: 1 Dec 2007 00:10:38 +0100
Date: Sat, 1 Dec 2007 00:10:38 +0100 (CET)

Hi again, Bruce!

On Mon, 26 Nov 2007, Bruce Korb wrote:

I know I probably seem cranky.  I am feeling cranky, after all.
I mean, I've used this wonderful editor for over 20 years and
it has been getting better all the time.  Until I loaded version 22.1
that came with my SuSE installation.  I really do find it irritating
that I have to go find and eyeball parse this stuff:

Being cranky's OK. It means that you want things set up _right_, and aren't prepared to be palmed off with rubbish. That's why a lot of people come to Emacs in the first place.

Trouble is, what the "Right Thing" and "rubbish" are vary enormously from hacker to hacker. So it means you've got to put in some work to configure your own Emacs. Sometimes, this can be quite a lot of work. Let's get going!


;; Safe local variables:

[...snip...]

only to discover that there really does not seem to be any way
to shut up this damn "hack-local-variables-confirm" junk.
Except to rewrite the thing and have it do nothing.  What a pain.
I mean, really!  It is not a good interface to force all competent
users to say, "Mother, please may I?" every time some new variable
is encountered.  As best I can tell from my ability meander around
this stuff, there is no other way.  So, I surely hope you do not
change the name of that procedure that I am about to replace.

I'd be a little more gentle on this. The file local variables mechanism is powerful enough to run arbitrary code. This means it's powerful enough for somebody to crack your machine's security just by giving you a source file and have you load it into Emacs. This could include downloading a virus or Trojan Horse from some web site. The "hack-l-v-confirm" thing is a precaution against this. It's probably worth putting up with this irritation.

I'd also suggest that irritations don't add up, they multiply.  So, if you
get the other problems sorted out, the local variables thingy won't seem nearly as bad. Of course like you suggest, you could code your way around it if you're confident enough about the source files you'll be visiting.

And I would still like to be able to press the space bar and not
have my comment reformatted:

It seems you've got Auto Fill mode enabled, somehow. Check this by looking for the word "fill" in the mode line. The purpose of this mode is _precisely_ to reformat stuff when you press the space bar. ;-) It's just that CC Mode restricts this reformatting to comments, by default, since it would be silly to fill executable code.

If you've got Auto Fill on for all buffers, you could switch it off for CC Mode by putting this into your .emacs:

    (defun bk-cc-setup ()
      (auto-fill-mode -1))
    (add-hook 'c-mode-common-hook 'bk-cc-setup)

The hooks in CC Mode are described in chapter "CC Hooks" of the CC Mode manual. This manual was completely overhauled just before Emacs 22.1 was released. It's worth a read. ;-)

[ .... ]

Here is an example.  I pressed "enter" and "*" and got this:

   /*=event  power_fail_received
    * evt-sev:     debug
    * evt-class:   debug
    * display:     'received <evt_type> regarding <disk_id>'
    *              ' from node <src_node>: <text_id>'
    *
    * arg:  enum-pfail_evt_type_name, evt_type
    * arg:  enum-pfail_evt_type_desc, text_id
    *
    * arg:  tpd_u32, src_node
    * arg:  tpd_u32, disk_id
    * arg:  tpd_u32, tag_type   <===================
*
   =*/

OK, I'm guessing here that you pressed <enter> with point at the end of the line I've marked "<===========". Just as a matter of interest, you can type M-j to do this. (See the chapter "Filling and Breaking" in the CC Mode manual.)

Normally, I would expect the star to be "electric" and line up.

So would I. But you only get this effect when "electric mode" is enabled. Have a look at your mode line: electric mode is indicated by the "l" in "C/l". Try toggling this on and off with C-c C-l, then try typing this "*" again. This is all described in Chapter "Minor Modes" in the CC Mode manual.

If you got the above problem when electric mode was on, then you've found a bug. If this is the case, then to fix it, I'll need precise details of your CC Mode configuration, so that I can reproduce the failure. Would you please type C-c C-b from your C buffer, then post here the information it displays. Thanks in advance!

But I am also trying to disable electric mode because there is
simply too much magic involved.  So, okay, I had to press "tab",
but it is still weird:


    * arg:  tpd_u32, tag_type
   *
   =*/

Post your configuration (with C-c C-b and cut and paste, as described above), then the reason this happens should become clear.

So, I move the cursor in front of the "*" character and press "space-bar":


    * arg:  tpd_u32, tag_type

   *=*/

and the cursor remains on the this new star, but on the next line.
There is some magical property somewhere.  What nonsense is this?

It looks like you've got some automatic filling function running, though I don't think it's just plain Auto Fill Mode. Maybe it says on the mode line. Could you check this out, please, and let us know?

Also, this filling happens because the "=" on your comment closing line prevents CC Mode recognising the "*" as a "comment prefix". So Auto Fill Mode thinks it's just ordinary text, and it coalesces it with the line above. I'm suprised it didn't become "* =*/", though.

The thing here is to tell CC Mode that your comment prefixes can have an "=" sign. Put the following into your .emacs (instead of the bit above):

    (defun bk-cc-setup ()
      (auto-fill-mode -1)
      (setq c-comment-prefix-regexp
        '((pike-mode . "//+!?\\|\\**")
          (awk-mode . "#+")
          (other . "//+\\|=?\\**"))))
    (add-hook 'c-mode-common-hook 'bk-cc-setup)

[The critical bit is the "=?" on the "other" line.]

"describe-key" says that "space-bar" is still bound to "insert-self",
but that is obviously not true.  How can I do simple stuff without
resorting to X-clip/paste, changing modes to edit comments, reverting
my distribution to a back-rev emacs or just punting my favorite editor
and using VI?  :(  This is really way too painful.

VI?  That would indeed be painful.  ;-)

--
Alan Mackenzie (Ittersbach, Germany).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]