简体   繁体   中英

how to write to a file in emacs

I want the emacs lisp code to append some data to a log file from emacs. The log file is large so I don't want to read it into memory.

I just need to open the log file, append some data to it, close it. I never need to see or manually edit the content.

You can use the append-to-file lisp function.

Append the contents of the region to the end of file filename. When called from a function, expects three arguments, start, end and filename. start and end are normally buffer positions specifying the part of the buffer to write.

If start is nil, that means to use the entire buffer contents.

If start is a string, then output that string to the file instead of any buffer contents; end is ignored.

More information is available here

(defun add-log-entry (log-message log-file)
  "Add a given message string to the end of a file."
  (append-to-file log-message nil log-file))
(f-write (format "%s" \<your list or what you what> ) 'utf-8\<or other encoding> "\<absolute file path>")

then go to the end of this line on closing braket and press Ce, go to the terminal cat + file, enjoy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM