[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Checking if find-file-hook was called interactively
From: |
Nordlöw |
Subject: |
Checking if find-file-hook was called interactively |
Date: |
Wed, 08 Dec 2010 15:26:27 -0000 |
User-agent: |
G2/1.0 |
Hey, there!
I have the following assistant that auto-inserts a C/C++ template code
when opening new or empty C/C++ files. How can I make this auto-
insertion be inhibited when find-file is called non-interactively?
This because I want prevent semantic's scanning functions from trigger
this template-auto-insertion.
I could solve this by either redefining find-file, advising find-file,
or defining a new function find-file-auto-template bound to C-x C-f.
But there are other variants of find-file I use so I would rather not
have to modify all of them so I guess advising find-file is the best
alternative in that case.
Thanks in advance,
Per Nordlöw
Exert of code follows. Note that buffer-empty-p and c-insert-header-
template is not given here.
(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)
- Checking if find-file-hook was called interactively,
Nordlöw <=