Search code examples
emacselisp

operate file in background?


I am writing an elisp function for having a short help description for a symbol:

(defun set-up-tooltip()
    ;; search for the text to be highlighted
    ...
    (add-text-properties (match-beginning 0)
                         (match-end 0)
                         '(mouse-face highlight
                                      help-echo (get-help-text (match-beginning 0)))

the (get-help-text ) function needs to open another file to search for the text. The question is: How do I open this file in the background so that user does not notice? I tried:

(defun get-help-text(
    (save-excursion
      (with-temp-buffer
         (find-file "lookup-file")
         ;;search for the text
         ...
             )))))

Here the file which is opened in the temp buffer opens in the window where I call the function and not in the background. Is there a idiomatic way for such tasks?


Solution

  • You're looking for the function insert-file-contents:

    insert-file-contents is a built-in function in `C source code'.
    
    (insert-file-contents FILENAME &optional VISIT BEG END REPLACE)
    
    Insert contents of file FILENAME after point.
    

    Use that instead of find-file inside your with-temp-buffer, and you should achieve what you want.