[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
read and write data to files
From: |
Emanuel Berg |
Subject: |
read and write data to files |
Date: |
Wed, 26 Feb 2020 23:04:20 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
Is this any good?
For the intended purpose, for once, performance
might be an issue and there will be many, many
reading and writings back and forth (sensors,
actions based on sensor readings, and so on in
a loop).
So optimizations are perhaps finally called
for, if anyone has any :)
;;; -*- lexical-binding: t -*-
;; this file: http://user.it.uu.se/~embe8573/emacs-init/file-write-to.el
;; https://dataswamp.org/~incal/emacs-init/file-write-to.el
;; write
(defun write-to-file (file string)
(write-region string nil file) )
;; read
(require 'subr-x)
(defun file-to-string (file)
"A string with the contents of FILE."
(interactive "Ffile: ")
(with-temp-buffer
(insert-file-contents file)
(string-trim
(buffer-substring-no-properties (point-min) (point-max)) )))
(defmacro file-to-string-variable (file var)
`(setq ,var ,(file-to-string file)) )
(defmacro file-to-integer-variable (file var)
`(setq ,var ,(string-to-number (file-to-string file))) )
;; (write-to-file "~/5ifth.txt" "Leeloo Dallas Multipass")
;; (write-to-file "~/element.txt" (number-to-string 5))
;;
;; (file-to-string "~/5ifth.txt") ; "Leeloo ..."
;; (file-to-string-variable "~/5ifth.txt" string-value) ; "Leeloo ..."
;; (file-to-integer-variable "~/element.txt" integer-value) ; 5
;;
;; string-value ; "Leeloo ..."
;; integer-value ; 5
(provide 'file-write-to)
--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- read and write data to files,
Emanuel Berg <=