Emacs Lisp: Read File Content as String or List of Lines

By Xah Lee. Date: . Last updated: .

Read File Content into a String

(defun get-string-from-file (filePath)
  "Return file content as string."
  (with-temp-buffer
    (insert-file-contents filePath)
    (buffer-string)))
;; 2010-09-02 thanks to Pascal J Bourguignon and TheFlyingDutchman [zzbba…@aol.com]

Read File Content as List of Lines

(defun read-lines (filePath)
  "Return a list of lines of a file at filePath."
  (with-temp-buffer
    (insert-file-contents filePath)
    (split-string (buffer-string) "\n" t)))

Emacs Lisp File/Buffer

Emacs Lisp, Process Lines