From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Nordl=F6w?= Newsgroups: gmane.emacs.help Subject: Checking if find-file-hook was called interactively Date: Fri, 27 Aug 2010 01:52:13 -0700 (PDT) Organization: http://groups.google.com Message-ID: <27c8130e-7855-4a34-842e-9cbdd687b9db@j8g2000yqd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1291860347 12654 80.91.229.12 (9 Dec 2010 02:05:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Dec 2010 02:05:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 09 03:05:43 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQVt8-0001Xl-DV for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 03:05:42 +0100 Original-Received: from localhost ([127.0.0.1]:60469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQVt7-0005sh-Ls for geh-help-gnu-emacs@m.gmane.org; Wed, 08 Dec 2010 21:05:41 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!j8g2000yqd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 42 Original-NNTP-Posting-Host: 150.227.15.253 Original-X-Trace: posting.google.com 1282899141 32170 127.0.0.1 (27 Aug 2010 08:52:21 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 27 Aug 2010 08:52:21 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j8g2000yqd.googlegroups.com; posting-host=150.227.15.253; posting-account=ytJKAgoAAAA1tg4ScoRszebXiIldA5vg User-Agent: G2/1.0 X-HTTP-Via: 1.1 ip1-w.foi.se:8080 (IronPort-WSA/6.3.4-017) X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.6 (KHTML, like Gecko) Ubuntu/10.04 Chromium/7.0.506.0 Chrome/7.0.506.0 Safari/534.6, gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:180980 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:76441 Archived-At: 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=F6w 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)