* Need to unhook a function in Makefile-mode
@ 2007-10-29 21:22 jgombos
0 siblings, 0 replies; 3+ messages in thread
From: jgombos @ 2007-10-29 21:22 UTC (permalink / raw)
To: Help-gnu-emacs
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)
))
</pre>
http://www.emacswiki.org/cgi-bin/emacs-en/UntabifyUponSave This article
suggests a solution, but someone responded to that saying that the
alternative approach screws up formatting (eg. number of spaces equated with
a tab). And I don't want to untabify manually (even though tabs are
highlighted in my view).
I would like a Makefile write hook that will undo the C++ write file hook.
Perhaps I've been spoiled with Mutt's "unhook" feature. [Mutt is an MUA
that has hook (and unhook) features in the configuration scripts].
--
View this message in context: http://www.nabble.com/Need-to-unhook-a-function-in-Makefile-mode-tf4714791.html#a13477295
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Need to unhook a function in Makefile-mode
[not found] <mailman.2734.1193692935.18990.help-gnu-emacs@gnu.org>
@ 2007-10-31 23:31 ` Colin S. Miller
2007-11-01 8:18 ` Stefan Kamphausen
1 sibling, 0 replies; 3+ messages in thread
From: Colin S. Miller @ 2007-10-31 23:31 UTC (permalink / raw)
To: help-gnu-emacs
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Need to unhook a function in Makefile-mode
[not found] <mailman.2734.1193692935.18990.help-gnu-emacs@gnu.org>
2007-10-31 23:31 ` Colin S. Miller
@ 2007-11-01 8:18 ` Stefan Kamphausen
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Kamphausen @ 2007-11-01 8:18 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
jgombos <nabble.forum.jog@spamgourmet.com> writes:
> ;; LANGUAGE HOOKS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (add-hook 'c++-mode-hook
> '(lambda ()
> (c-set-style "whitesmith")
> (add-hook 'write-file-hooks 'untabify-buffer)
> ))
> </pre>
> http://www.emacswiki.org/cgi-bin/emacs-en/UntabifyUponSave This article
> suggests a solution, but someone responded to that saying that the
> alternative approach screws up formatting (eg. number of spaces equated with
> a tab). And I don't want to untabify manually (even though tabs are
> highlighted in my view).
well the approach given over there in the wiki makes write-file-hooks
a /buffer local/ hook by calling
(make-local-hook 'write-contents-hooks)
I have been using that code for something like 5-8 years (can't really
remember) and it always did what I wanted. Note however, it was used
in XEmacs and I never hade much code edititing in larger teams (at
least no teams not using that same code, too ;-)
Kind Regards
Stefan
--
Stefan Kamphausen --- http://www.skamphausen.de
a blessed +42 regexp of confusion (weapon in hand)
You hit. The format string crumbles and turns to dust.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-11-01 8:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-29 21:22 Need to unhook a function in Makefile-mode jgombos
[not found] <mailman.2734.1193692935.18990.help-gnu-emacs@gnu.org>
2007-10-31 23:31 ` Colin S. Miller
2007-11-01 8:18 ` Stefan Kamphausen
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.