Solved

emacs lisp

Posted on 2002-05-01
5
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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