- 函数名称:
insert-file-contents
- 函数功能一句话描述:插入文件内容到当前buffer。
- 函数原型:
(insert-file-contents FILENAME &optional VISIT BEG END REPLACE)
- 函数用法demo:
假设当前有一个文件,路径为:d:/test.txt
,文件内容为:
hello,
world!
are you ok?
下面写一个elisp函数,去读这个文件,把文件每一行字符串都存在一个列表里并返回:
(defun read-file-as-lines (file-path)
(with-temp-buffer
(insert-file-contents file-path)
(split-string (buffer-string) "\n" t)))
(read-file-as-lines "d:/test.txt")
执行上述代码,输出结果如下:
("hello," "world!" "are you ok?")
网友评论