From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "William Payne" Newsgroups: gmane.emacs.help Subject: Re: Hungry delete for C, C++ and Java? Date: Thu, 22 Apr 2004 18:18:28 +0200 Organization: Island, Linkoping University, Sweden Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: <68n36c.q5.ln@acm.acm> NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1082657653 24759 80.91.224.253 (22 Apr 2004 18:14:13 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 22 Apr 2004 18:14:13 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 22 20:14:00 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BGii0-0008FN-00 for ; Thu, 22 Apr 2004 20:14:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BGh6U-00025o-HE for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Apr 2004 12:31:10 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsmi-us.news.garr.it!newsmi-eu.news.garr.it!NewsITBone-GARR!feed.news.tiscali.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.tpinternet.pl!news-stoc.telia.net!news-stoa.telia.net!telia.net!newsfeed.sunet.se!news01.sunet.se!news.island.liu.se!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 118 Original-NNTP-Posting-Host: astmatix.ida.liu.se Original-X-Trace: news.island.liu.se 1082650704 3721 130.236.186.15 (22 Apr 2004 16:18:24 GMT) Original-X-Complaints-To: abuse@island.liu.se Original-NNTP-Posting-Date: Thu, 22 Apr 2004 16:18:24 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Original-Xref: shelby.stanford.edu gnu.emacs.help:122574 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:17871 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:17871 "Alan Mackenzie" wrote in message news:ipb86c.q5.ln@acm.acm... > William Payne wrote on Wed, 21 Apr > 2004 00:27:06 +0200: > > >> > .... and I was wondering how I turn on hungry delete per default for > >> > C, C++ and Java? > > >> In an appropriate hook function (probably on c-mode-common-hook) include: > > >> (c-toggle-hungry-state 1) > > >> [, and as a matter of interest, C-c C-d will execute > >> `c-toggle-hungry-state' interactively]. and C-d (but not > >> ) then do hungry deletion. It looks as thought the fine manual > >> could do with some clarification on this point. > > > Thanks for the reply, Alan. My .emacs file is as follows, where should > > I put (c-toggle-hungry-state 1)? Under (defun my-c++-mode () > > (interactive) and (defun my-java-mode () (interactive) ? > > > My .emacs file was created years and years ago by someone else, I wish I > > understood it better...I am guessing it could be cleaned-up/improved alot. > > > Fyi, I am using CC-Mode 5.30.8. > > A stable released version without bugs. (hah! :-) > > OK, a few comments on your .emacs file: > > > '("\\.pike$" . my-c++-mode) ; element of auto-mode-alist > > There is actually a Pike Mode within CC Mode. If that's the same > language that your files.pike are, it would be better than c++-mode. Thanks for noticing this. I have removed this entry completely. > Also, you're using C++ Mode for C files. Also not _so_ bad, but not > quite optimal. > Yes, I guess I should change that. First I will have to convert all my c++ header files to end in .hpp instead of .h. I also have to fix the indentation in some cases, it's not behaving as I want it to behave. > > (defun my-java-mode () (interactive) > > (java-mode) > > (require 'jdok) > > (c-toggle-hungry-state 1) ; <==================================== > > (setq c-basic-offset 3) ; Indent three columns. > > (setq c-offsets-alist > > It looks like you've already got c-toggle-hungry-state turned on, here. > Does it work? Have you inserted this line here in the last day or two, > perhaps? It ought to work. > I added that after your first reply and, yes, it works. =) > If it now works and you're happy about it, that's great, and just ignore > what follows. > > ######################################################################### > > However, if you're interested in getting to know Emacs and CC Mode a bit > better, the way you've got CC Mode configured is highly unusual, and > suggests the person who wrote the .emacs didn't fully understand the way > Emacs works. > > Your setup for C++ Mode looks like this in outline: > > (defun my-c++-mode () > (c++-mode) > (williams-customizations)) > > This compels you to add entries to auto-mode-alist (this is the list > which tells Emacs which mode to use for a filename). Normally C++ Mode > is configured by using "hooks" - you give c++-mode a list of functions > you want to get called whenever c++-mode runs. You then get the > customizations you want without need to have functions like my-c++-mode. > You could reformulate your code like this: > > (defun williams-c++-hook () > (williams-customizations)) > (add-hook 'c++-mode-hook 'williams-c++-hook) > > That way, you could get rid of all these entries to auto-mode-alist. > Customizations which are common to C, C++, Java, Pike, (such as the > call of c-toggle-hungry-state) you need only write once, in > c-mode-common-hook, like this: > > (defun williams-common-hook () > (c-toggle-hungry-state 1) > (other-customizations)) > (add-hook 'c-mode-common-hook 'williams-common-hook) > > This is extensively described on the page "Hooks" in the CC Mode manual, > and the page "Sample .emacs File" would also be of interest. > > > / WP > I am very interested in cleaning up my .emacs-file and understanding emacs and cc-mode better. I am not quite sure I follow you on the hooks (having done zero lisp coding), but I will try to understand it and incorporate your suggestions. > -- > 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"). > / William Payne