【问题标题】:operate file in background?在后台操作文件?
【发布时间】:2019-01-18 12:25:56
【问题描述】:

我正在编写一个 elisp 函数来为符号提供简短的帮助描述:

(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)))

(get-help-text ) 函数需要打开另一个文件来搜索文本。问题是:如何在后台打开这个文件,让用户不会注意到?我试过了:

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

在这里,在临时缓冲区中打开的文件在我调用函数的窗口中打开,而不是在后台打开。此类任务有惯用的方法吗?

【问题讨论】:

    标签: emacs elisp


    【解决方案1】:

    您正在寻找函数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.
    

    在你的with-temp-buffer 中使用它而不是find-file,你应该会实现你想要的。

    【讨论】:

      【解决方案2】:

      你可以考虑find-file-noselect这个函数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-22
        • 2013-12-31
        • 2016-02-21
        • 2021-06-13
        • 2014-12-29
        相关资源
        最近更新 更多