Solved

emacs lisp

Posted on 2002-05-01
5
203 Views
Last Modified: 2010-04-22
I have a hook on.
find-file-not-found-hooks

I call find file interactively with \C-\F or \M-x find-file it works ok. but if I call it in a script (find-file "FileName") it is as if the hook is not there.

Any one know why, and how to get around it.
0
Comment
Question by:bearware
  • 2
5 Comments
 
LVL 5

Expert Comment

by:bryanh
ID: 6990660
I just tried it an it works for me.  

Maybe it is as if the hook is not there because your hook doesn't do anything when in that environment, even though it does something in the interactive environment.  You didn't mention what you expected it to do.

I used a hook that just inserts a string into the new buffer: (insert "new string") .  Does that work for you?

Also, the next step up from running find-file from the M-x buffer, but before running a program that calls find-file, is to put a buffer into lisp interaction mode and run find-file there:  To get into that mode, use the lisp-interaction-mode command.  Now put (find-file "doesntexist") into that buffer and with the cursor to the right of the closing parenthesis, hit ctl-J.  That evaluates the expression (runs the find-file function) in an environment much closer to what it will run in in your program that when you invoke it interactively.

What sort of results do you get when you do that?
0
 
LVL 1

Author Comment

by:bearware
ID: 6993533
to bryanh

Thanks for the help I tryed it but it did not work.
I tryed ctrl-J on:
(find-file "doesntexist.h")
The .h is so the template library does something

I have included some info below, If you need more just ask.

The code  on the hook is from a template library, I dont fully understand it, we need to call find-file from a lisp program as we have a popup window file dialoge that calls find-file.

The code is added to the hook with
(add-hook 'find-file-not-found-hooks 'template-not-found-function t))
The code on the hook is:
(defun template-not-found-function ()
  "Use a template when visiting a non-existent file.
See `template-auto-insert' and `template-find-file-commands'.  Function
in `find-file-not-found-hooks'."
  (and template-auto-insert (not buffer-read-only) (bobp) (eobp)
       (or (memq this-command template-find-file-commands)
        (and (memq this-command template-file-select-commands)
          ;; thanks to Dave Love <d.love@dl.ac.uk>:
          (memq (car-safe (car command-history))
                template-find-file-commands)))
       (let ((template (cdr (template-derivation buffer-file-name t))))
      (and (file-readable-p template)
           (or (eq template-auto-insert t)
            (y-or-n-p
             (format "Use template %s? "
                  (if (string-match "XEmacs\\|Lucid" emacs-version)
                      (abbreviate-file-name template t)
                    (abbreviate-file-name template)))))
           (progn (template-new-file buffer-file-name template t)
               t)))))


 
0
 
LVL 5

Accepted Solution

by:
bryanh earned 50 total points
ID: 6994103
What do you mean "did not work"?  The point of the ctl-J was to find out if you get the same symptom as when you invoke the function in your own program.  Were you unable to find out?  If so, how?  If you mean you were able to duplicate the symptom (i.e. the hook appeared not to run), then the ctl-J worked.

This hook function is too complex for me to see if there's something wrong -- you need to isolate the problem by making a simpler test case.  How about writing a one-line hook that simply inserts the string "I'm running" in all cases.  If that doesn't work, then the problem has nothing to do with this code and we don't have to waste time reading it.

I note in the documentation of file-not-found-hooks that it says this is not a normal hook, but rather a simple list of functions.  So I did not use add-hook in my test.  I simply created a list that consisted of my one test hook function.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9914913
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bryanh {http:#6994103}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question