From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: c-mode and underscore Date: Wed, 8 Jul 2009 10:52:14 +0000 (UTC) Organization: muc.de e.V. Message-ID: References: <9168430a-e1d0-4f6c-8b4f-4eae95e4b239@h2g2000yqg.googlegroups.com> <03ed2840-29a9-4ee2-95f4-df57bcd2e985@z4g2000prh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1247053261 15120 80.91.229.12 (8 Jul 2009 11:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 8 Jul 2009 11:41:01 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 08 13:40:54 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MOVW9-0001TM-Cw for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Jul 2009 13:40:54 +0200 Original-Received: from localhost ([127.0.0.1]:54487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOVW8-00086F-C2 for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Jul 2009 07:40:52 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!newsfeed.freenet.de!news.space.net!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 84 Original-NNTP-Posting-Host: marvin.muc.de Original-X-Trace: colin2.muc.de 1247050334 12124 2001:608:1000::2 (8 Jul 2009 10:52:14 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: Wed, 8 Jul 2009 10:52:14 +0000 (UTC) User-Agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE (i386)) Original-Xref: news.stanford.edu gnu.emacs.help:170641 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65842 Archived-At: Hi, Kevin! Kevin Rodgers wrote: > Xah Lee wrote: >> On Jul 7, 3:56 pm, geophile wrote: >>> I am trying to get c-mode to treat underscore as a word, so that >>> forward-word backward-word don't stop on underscores. >>> My .emacs file includes: >>> (modify-syntax-entry ?_ "w" c-mode-syntax-table) >>> which does not appear to be effective. But if I run this command >>> manually, it is effective. >>> I'm pretty sure that the line above is being reached in my .emacs >>> file, as later commands are effective. > How could c-mode-syntax-table refer to the current (not global) syntax > table? > It is consistent with the hypothesis that the problem is that > c-mode-syntax-table does not have its correct value when .emacs is > loaded. Indeed, this code from progmodes/cc-mode.el reveals why it > is nil when .emacs is loaded and thus does refer to the current syntax > table as you said: > ;;;###autoload > (defvar c-mode-syntax-table nil > "Syntax table used in c-mode buffers.") > (or c-mode-syntax-table > (setq c-mode-syntax-table > (funcall (c-lang-const c-make-mode-syntax-table c)))) > The autoload cookie causes the defvar to be copied into loaddefs.el > and thus dumped into the emacs executable. Why does cc-mode.el do that > instead of the obvious > (defvar c-mode-syntax-table (funcall (c-lang-const > c-make-mode-syntax-table c)) > "Syntax table used in c-mode buffers.") Can't really say, but I suppose I can guess. This construct goes back to the very beginning of CC Mode. Version 1.1 of cc-mode.c from 1992-03-13 contains these lines: (defvar c++-mode-syntax-table nil "Syntax table in use in C++-mode buffers.") (if c++-mode-syntax-table () (setq c++-mode-syntax-table (copy-syntax-table c-mode-syntax-table)) (modify-syntax-entry ?/ ". 12" c++-mode-syntax-table) (modify-syntax-entry ?\n ">" c++-mode-syntax-table) (modify-syntax-entry ?\' "." c++-mode-syntax-table)) The XEmacs (or was it still Lucid Emacs?) of the time may have lacked the ability to initialise a variable from an arbitrary expression. The maintainer at the time, Barry Warsaw, was engaged in a massive exercise merging his C++ Mode with "Boring Old C Mode" to create the new shiny CC Mode. (It's still shining 17 years later, so he must have done a good job.) At such times, exactly how you initialise a variable seems trivial and unimportant, and perhaps Barry was intending to make that change, but never got round to it. After all, it worked, and there was plenty of other stuff to do. > If you're going to use a hook, you may as well just refer to the current > syntax table with (syntax-table) instead of by name. That's kind of a bit awkward from .emacs. I think the best way is to use c-initialization-hook. Such as: (defun jo-init-function () "Doc string ....." (modify-syntax-entry ?_ "w" c-mode-syntax-table)) (add-hook 'c-initialization-hook 'jo-init-function) To the OP: make sure this appears in your .emacs BEFORE anything which loads CC Mode. -- Alan Mackenzie (Nuremberg, Germany).