all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie<none@example.invalid>
Subject: Re: Hungry delete for C, C++ and Java?
Date: Thu, 22 Apr 2004 11:54:26 +0000	[thread overview]
Message-ID: <ipb86c.q5.ln@acm.acm> (raw)
In-Reply-To: c6483p$pt0$1@news.island.liu.se

William Payne <mikas_n_o_s_p_a_m_493@student.liu.se> 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].  <backspace> and C-d (but not
>> <del>) 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.
Also, you're using C++ Mode for C files.  Also not _so_ bad, but not
quite optimal.

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

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

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

  reply	other threads:[~2004-04-22 11:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <c63fvv$g2j$1@news.island.liu.se>
     [not found] ` <68n36c.q5.ln@acm.acm>
2004-04-20 22:27   ` Hungry delete for C, C++ and Java? William Payne
2004-04-22 11:54     ` Alan Mackenzie [this message]
2004-04-22 16:18       ` William Payne
2004-04-22 16:36         ` William Payne
2004-04-22 17:55           ` William Payne
2004-04-24 21:03   ` Kai Grossjohann
2004-04-25  6:33     ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ipb86c.q5.ln@acm.acm \
    --to=none@example.invalid \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.