all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Colin S. Miller" <no-spam-thank-you@csmiller.demon.co.uk>
To: help-gnu-emacs@gnu.org
Subject: Re: Need to unhook a function in Makefile-mode
Date: Wed, 31 Oct 2007 23:31:05 +0000	[thread overview]
Message-ID: <4729103a$0$90275$14726298@news.sunsite.dk> (raw)
In-Reply-To: <mailman.2734.1193692935.18990.help-gnu-emacs@gnu.org>

jgombos wrote:
> I have a C++ write file hook to automatically untabify the whole buffer
> before saving.  It works great, but then when I open a Makefile in
> Makefile-mode, the hook persists, which ruins Makefiles.  My .emacs file
> contains:
> <pre>
> ;; Define untabify-buffer.
> (defun untabify-buffer()
>   (interactive)
>   "Untabify the current buffer.  Return nil.
> 
>   Must return nil, if added to write-file-hooks."
>   (save-excursion
>     (goto-char (point-min))
>     (while (re-search-forward "[ \t]+$" nil t)
>       (delete-region (match-beginning 0) (match-end 0)))
>     (goto-char (point-min))
>     (if (search-forward "\t" nil t)
>         (untabify (1- (point)) (point-max))))
>   nil)
> 
> ;; LANGUAGE HOOKS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (add-hook 'c++-mode-hook
> 	  '(lambda ()
> 		  (c-set-style "whitesmith")
> 		  (add-hook 'write-file-hooks 'untabify-buffer)
> 		  ))

Jgombos,

try using local-write-file-hooks, which is the buffer-local version of write-file-hooks,
or at least it is in XEmacs.


Failing that, see add-local-hook,

Failing that
try

(add-hook 'ctypes-load-hook
  '(lambda ()
    (c-set-style "whitesmith")
    (add-hook 'write-file-hooks
       '(lambda ()
        (if (eq major-mode 'c++-mode) (untabify-buffer))))))


Ctypes is used by C, C++, and C# modes.

IIRC, -load-hooks are only called once, when the mode is first loaded,
whereas -mode-hooks are called each time a buffer enters that mode.


HTH,
Colin S. Miller

-- 
Replace the obvious in my email address with the first three letters of the hostname to reply.

       reply	other threads:[~2007-10-31 23:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.2734.1193692935.18990.help-gnu-emacs@gnu.org>
2007-10-31 23:31 ` Colin S. Miller [this message]
2007-11-01  8:18 ` Need to unhook a function in Makefile-mode Stefan Kamphausen
2007-10-29 21:22 jgombos

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='4729103a$0$90275$14726298@news.sunsite.dk' \
    --to=no-spam-thank-you@csmiller.demon.co.uk \
    --cc=help-gnu-emacs@gnu.org \
    /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.