[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Checking if find-file-hook was called interactively
From: |
Stefan Monnier |
Subject: |
Re: Checking if find-file-hook was called interactively |
Date: |
Wed, 08 Dec 2010 15:26:30 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> (defun c-auto-insert-empty-file-template ()
> "Interactive insertion of file creation template."
> (interactive)
> (unless buffer-read-only
> (let ((filepath (buffer-file-name)))
> (if (buffer-empty-p)
> ;; empty buffer
> (progn
> (if (fmd-file-match filepath 'C-Header 'name-recog)
> (if (y-or-n-p (format "Insert C Header Template? "))
> (c-insert-header-template filepath "y")))
> (if (fmd-file-match filepath 'C++-Header 'name-recog)
> (if (y-or-n-p (format "Insert C++ Header Template? "))
> (c-insert-header-template filepath "y")))
> (if (fmd-file-match filepath 'C-Source 'name-recog)
> (if (y-or-n-p (format "Insert C Source Template? "))
> (c-insert-source-template filepath)))
> (if (fmd-file-match filepath 'C++-Source 'name-recog)
> (if (y-or-n-p (format "Insert C++ Source Template? "))
> (c-insert-source-template filepath)))
> )))))
> (add-hook 'find-file-hook 'c-auto-insert-empty-file-template t)
I'd recommend you use auto-insert-mode rather than your own code.
But you may find that auto-insert suffers from the same problem, in
which case you may want to M-x report-emacs-bug.
Now I'm not sure whether the bug is in Semantic which should not visit
those files with find-file-noselect but with something of lower level,
or in auto-insert which should be more careful to only perform the
auto-insertion (and/or prompt the user) when the command is really
a "find-file"-like command.
Stefan