[Top][All Lists]

[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 (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
;; Define untabify-buffer.
(defun untabify-buffer()
  "Untabify the current buffer.  Return nil.

  Must return nil, if added to write-file-hooks."
    (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))))

;; LANGUAGE HOOKS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'c++-mode-hook
          '(lambda ()
                  (c-set-style "whitesmith")
                  (add-hook 'write-file-hooks 'untabify-buffer)


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

Failing that, see add-local-hook,

Failing that

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

Colin S. Miller

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]