help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Persistence of variables


From: Emanuel Berg
Subject: Re: Persistence of variables
Date: Wed, 21 Mar 2018 22:43:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

(defun write-string-to-file (string file)
  "Write STRING to FILE.
Create nonexistent FILE otherwise overwrite."
  (interactive "sstring: \nFfile: ")
  (with-temp-file file
    (insert string "\n") ))
;; (write-string-to-file "Leeloo Dallas Multipass" "~/5ifth.txt")

(require 'subr-x)
(defun file-to-string (file)
  "Put the contents of FILE into a string and return it."
  (interactive "Ffile: ")
  (with-temp-buffer
    (insert-file-contents file)
    (string-trim
     (buffer-substring-no-properties (point-min) (point-max)))
    ))
;; (file-to-string "~/5ifth.txt")

(defmacro read-from-file (var file)
  `(setq ,var ,(file-to-string file)) )

(defvar string-value)
(setq string-value "")

;; (read-from-file string-value "~/5ifth.txt")
;; string-value

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]