Solved

emacs lisp

Posted on 2002-05-01
5
202 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now