;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/file-write-to.el (require 'subr-x) (defun write-to-file (file data) (write-region (format "%s" data) nil file) ) (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))))) ;; (insert (file-to-string "/home/incal/.emacs.d/emacs-init/bad/data/eye.txt")) (defun file-to-integer (file) (string-to-number (file-to-string file)) ) (defmacro file-to-variable (file var) `(setq ,var ,(file-to-string file)) ) (defmacro file-to-variable-integer (file var) `(setq ,var ,(string-to-number (file-to-string file))) ) ;; (write-to-file "~/5ifth.txt" "Leeloo Dallas Multipass") ;; ;; (file-to-string "~/5ifth.txt") ; Leeloo ... ;; (file-to-variable "~/5ifth.txt" string-value) ; Leeloo ... ;; string-value ; Leeloo ... ;; (file-to-variable-integer "~/element.txt" integer-value) ; 5 ;; integer-value ; 5 (provide 'file-write-to)