unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: cc-mode 5.31 doesn't like eval-after-load c-set-style
       [not found] <17302.64294.256799.692482@chlr5836.ch.intel.com>
@ 2005-12-07 17:08 ` Alan Mackenzie
  2005-12-07 19:08   ` Andrew M. Scott
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Mackenzie @ 2005-12-07 17:08 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel

Hi, Andrew!

On Wed, 7 Dec 2005, Andrew M. Scott wrote:

>FYI, I had also posted this on Dec 5th on the emacs-pretest-bug list
>(no response yet):
>http://lists.gnu.org/archive/html/emacs-pretest-bug/2005-12/msg00075.html

Sorry!  bug-cc-mode (even as a cc:) is always a better place, because
important emails there don't get swamped by other important emails.

>I've had the following code snippet in my .emacs file for ages, but
>only recently (since cc-mode 5.31?) has it produced errors like this
>one. I see the issue with both a Dec 5, 2005 and Nov 2004 CVS Emacs
>build I had available. I also tried cc-mode 5.31.1 that I saw on
>sourceforge, but get the same error.

>% emacs -q

>Eval the following code snippet:
>(eval-after-load "cc-mode"
>    '(progn
>      (c-set-style "gnu")
>      ))

OK, that code's wrong!  `c-set-style' applies to an individual buffer,
and if you do it in the eval-after-load form, the current buffer is
somewhat ill-defined.  For example, if you did (load-library 'cc-mode),
Bad Things might happen.

An extra check was added fairly recently to c-set-style because Bad
Things were happening when people called it for non-CC Mode buffers.

Are you sure you don't really want (setq c-default-style "gnu"),
[or even, (setq c-default-style '((java-mode . "java") (awk-mode .
"awk")))?]  You can even do this with customize-group <ret> c <ret>.

Or is it that you've got the default style set to "linux" and you want
the first buffer to be loaded, junk.c, to get "gnu"?

>C-x C-f junk.c

What happens is this:  this command loads junk.c, sees it needs c-mode,
so it loads cc-mode.elc.  It then tries to set the style "gnu" on junk.c
before it's had a chance to initialise c-mode on it. 

The error message in this case "Buffer junk.c is not a CC Mode buffer" is
perhaps suboptimal.  Do you think "Buffer junk.c is not a CC Mode buffer,
or hasn't been initialized yet" might be better?

What exactly do you see as the bug?  Is it the obscure error message, or 
do you really, really, absolutely unavoidably HAVE to set junk.c's style
in this eval-after-load? 

[ .... ]

>Thanks,
>Andy Scott

-- 
Alan Mackenzie (Munich, Germany)




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click


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

* Re: cc-mode 5.31 doesn't like eval-after-load c-set-style
  2005-12-07 17:08 ` cc-mode 5.31 doesn't like eval-after-load c-set-style Alan Mackenzie
@ 2005-12-07 19:08   ` Andrew M. Scott
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew M. Scott @ 2005-12-07 19:08 UTC (permalink / raw)
  Cc: Andrew M. Scott, bug-cc-mode, emacs-devel

>>>>> "Alan" == Alan Mackenzie <acm@muc.de> writes:

    Alan> Hi, Andrew! On Wed, 7 Dec 2005, Andrew M. Scott wrote:
    >> FYI, I had also posted this on Dec 5th on the emacs-pretest-bug
    >> list (no response yet):
    >> http://lists.gnu.org/archive/html/emacs-pretest-bug/2005-12/msg00075.html

    Alan> Sorry! bug-cc-mode (even as a cc:) is always a better place,
You're right :-) I should have cc'd bug-cc-mode on the original report.

    >> I've had the following code snippet in my .emacs file for ages,
    >> but only recently (since cc-mode 5.31?) has it produced errors
    >> like this one. I see the issue with both a Dec 5, 2005 and Nov
    >> 2004 CVS Emacs build I had available. I also tried cc-mode
    >> 5.31.1 that I saw on sourceforge, but get the same error.

    >> % emacs -q

    >> Eval the following code snippet: (eval-after-load "cc-mode"
    >> '(progn (c-set-style "gnu") ))

    Alan> OK, that code's wrong! `c-set-style' applies to an
    Alan> individual buffer, and if you do it in the eval-after-load
    Alan> form, the current buffer is somewhat ill-defined. For
    Alan> example, if you did (load-library 'cc-mode), Bad Things
    Alan> might happen.

Thanks. This was a legacy code fragment.

    Alan> An extra check was added fairly recently to c-set-style
    Alan> because Bad Things were happening when people called it for
    Alan> non-CC Mode buffers.

Which explains why I'm just seeing the error when the cc-mode 5.31
rotation showed up. Thanks.

    Alan> Are you sure you don't really want (setq c-default-style
    Alan> "gnu"), [or even, (setq c-default-style '((java-mode .
    Alan> "java") (awk-mode . "awk")))?] You can even do this with
    Alan> customize-group <ret> c <ret>.

Yes. These are the right way to do it.

    Alan> Or is it that you've got the default style set to "linux"
    Alan> and you want the first buffer to be loaded, junk.c, to get
    Alan> "gnu"?

    >> C-x C-f junk.c

    Alan> What happens is this: this command loads junk.c, sees it
    Alan> needs c-mode, so it loads cc-mode.elc. It then tries to set
    Alan> the style "gnu" on junk.c before it's had a chance to
    Alan> initialise c-mode on it.

    Alan> The error message in this case "Buffer junk.c is not a CC
    Alan> Mode buffer" is perhaps suboptimal. Do you think "Buffer
    Alan> junk.c is not a CC Mode buffer, or hasn't been initialized
    Alan> yet" might be better?

    Alan> What exactly do you see as the bug? Is it the obscure error
    Alan> message, or do you really, really, absolutely unavoidably
    Alan> HAVE to set junk.c's style in this eval-after-load?

I think the current "error message" is sufficient. I don't think any
cc-mode or Emacs code changes are needed for this issue. The fix is for
me to use setq c-default-style or c-set-style directly.

Thanks,
Andy Scott



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click


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

end of thread, other threads:[~2005-12-07 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <17302.64294.256799.692482@chlr5836.ch.intel.com>
2005-12-07 17:08 ` cc-mode 5.31 doesn't like eval-after-load c-set-style Alan Mackenzie
2005-12-07 19:08   ` Andrew M. Scott

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