[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Need to unhook a function in Makefile-mode
From: |
Colin S. Miller |
Subject: |
Re: Need to unhook a function in Makefile-mode |
Date: |
Wed, 31 Oct 2007 23:31:05 +0000 |
User-agent: |
Icedove 1.5.0.14pre (X11/20071018) |
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.