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

11. buffers

11.1. create a new buffer into next window

(switch-to-buffer-other-window (generate-new-buffer "some-new-buffer"))

12. highlighting

;; (setq dna-keyword '(("^\+\\([GCT\-]*\\(A\\)\\)*" (2 font-lock-function-name-face))))

(define-derived-mode bioseq-mode fundamental-mode
  (setq font-lock-defaults '(dna-keyword))
  (setq mode-name "bioseq mode"))


;; MATCH-ANCHORED should be of the form:
;;
;; (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)

;;      /- main matcher
;;     /
;;    /          /- PRE-MATCH-FORM
;;   /          /
'(("^\\+" ("A" nil nil (0 'bioseq-mode-a)))
  ("^\\+" ("G" nil nil (0 'bioseq-mode-g))))


(font-lock-add-keywords nil
                        '(("⁑"
                           ("i:[[:word:]]+" nil nil 'italic)
                           ("[[:word:]]+:" nil nil 'raideda-simple-command-marks))))


                           (2 'raideda-simple-command-face)
                           (3 'raideda-simple-command-marks)
                           (4 'raideda-simple-argument))))


· © Edgard Bikelis (eſb) created using Emacs 31.0.50 (Org mode 9.7.11) ·
· created: 2019-12-29 last (re)generated: 2025-03-12 ·