mastodon warning! may contain trace amounts of Lisp

Emacs

Table of Contents

1. documentation

2. native compiler

3. themes

4. org-mode

4.1. adding link types

5. 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"))))

6. insert colored text

(insert (let ((tmp "lalala"))
          (put-text-property 0 (length tmp)
                             'font-lock-face
                             '(:foreground "orange" :weight bold :slant italic)
                             tmp)
          tmp))

To find in which character the cursor currently is: (what-cursor-position)

To find the text properties of a character: (text-properties-at 1)

To apply a face to a string:

(insert (let ((tmp "lalala"))
          (put-text-property 0 (length tmp) 'font-lock-face 'diff-error tmp)
          tmp))

Or, with my function: (insert (add-properties-to-string "lalala" 'dired-broken-symlink))

7. variables

Files may define local variables, since ancient times, on the first line using this form: -*- mode:lisp; base:8 -*. There are functions for manipulating this:

  • add-file-local-variable-prop-line

Another way is putting them at the end of the file. Check the link above.

8. command list

9. zmacs

9.1. commands

10. making packages


· © Edgard Bikelis (eſb) created using Emacs 29.0.50 (Org mode 9.5.3) ·
· created: 2019-12-29 last modified: 2022-07-25 ·