all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nordlöw <per.nordlow@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Checking if find-file-hook was called interactively
Date: Fri, 27 Aug 2010 01:52:13 -0700 (PDT)	[thread overview]
Message-ID: <27c8130e-7855-4a34-842e-9cbdd687b9db@j8g2000yqd.googlegroups.com> (raw)

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)


             reply	other threads:[~2010-08-27  8:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-27  8:52 Nordlöw [this message]
2010-08-28  0:20 ` Checking if find-file-hook was called interactively Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=27c8130e-7855-4a34-842e-9cbdd687b9db@j8g2000yqd.googlegroups.com \
    --to=per.nordlow@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.