all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* read and write data to files
@ 2020-02-26 22:04 Emanuel Berg via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; only message in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2020-02-26 22:04 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: emacs-devel

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-26 22:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-26 22:04 read and write data to files Emanuel Berg via Users list for the GNU Emacs text editor

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.