Emacs

Table of Contents

http://akrl.sdf.org/gccemacs.html

1 themes

2 org-mode

2.1 adding link types

3 persistence

;; creating a hashtable
(setq myhash (make-hash-table :test 'equal))
;; putting things in it
(puthash "joe" 20 myhash)
(puthash "john" 200 myhash)
;; printing it
(print myhash)
;; #s(hash-table size 65
;;               test equal
;;               rehash-size 1.5
;;               rehash-threshold 0.8125
;;               data ("joe" 20 "john" 200))
;; #<hash-table equal 2/65 0x156e97c17f11>

;; writing it as a string
(prin1-to-string myhash)
"#s(hash-table size 65
               test equal
               rehash-size 1.5
               rehash-threshold 0.8125
               data (\"joe\" 20 \"john\" 200))"

;; reading back from string and querying it
(gethash "joe" (read-from-string
"#s(hash-table size 65
               test equal
               rehash-size 1.5
               rehash-threshold 0.8125
               data (\"joe\" 20 \"john\" 200))"))
;; → 20 (#o24, #x14, ?\C-t)

;; writing to a file
(with-temp-file "~/shalala.el" (insert (prin1-to-string myhash)))

;; reading back from it, a helper function:

;; https://stackoverflow.com/a/20747279/1091982
(defun slurp-file (f)
  "Give me a file, and for thee I shall regurgitate its content as a string."
  (with-temp-buffer
    (insert-file-contents f)
    (buffer-substring-no-properties
       (point-min)
       (point-max))))

;; get it back:
setq myhash (car (read-from-string (slurp-file "/medha/lalala.el"))))

· copyright © Edgard Bikelis (eſb) · 2020-04-05 ·
created using Emacs 28.0.50 (Org mode 9.3)