Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elisp - Loading an expression as data from a file

Tags:

emacs

lisp

elisp

I am attempting to write a function which, given a file path, will load the contents of that file and append it to a list. The end goal is to have one file for each org-capture template, and to load them from a list of files or an org-table.

My problem is that the load and load-file functions only return t if the load is successful.

What function can I use to return the contents of a file as an expression?

for example, given the file test.el:

'("foo" "bar" "baz" "fnord")

How can I achieve the following:

(mysterious-function "~/test.el")

=> '("foo" "bar" "baz" "fnord")

Thanks in advance

like image 811
Chazu Avatar asked Sep 11 '26 08:09

Chazu


1 Answers

(defun mysterious-function (filename)
  (setq filename (expand-file-name filename))
  (with-temp-buffer
    (insert-file-contents filename)
    (read (current-buffer))))
like image 190
Barmar Avatar answered Sep 15 '26 01:09

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!