#+title: Random Notes on Emacs #+author: Various #+filetags: NOTE #+options: toc:t This is a small collection of Emacs related posts and documentation by other authors that I find useful. * Fractals in Emacs :PROPERTIES: :CREATED: [2018-08-04 Sat 13:01] :END: From https://nullprogram.com/blog/2012/09/14/ #+begin_src emacs-lisp (defun sierpinski (s) (pop-to-buffer (get-buffer-create "*sierpinski*")) (fundamental-mode) (erase-buffer) (labels ((fill-p (x y) (cond ((or (zerop x) (zerop y)) "0") ((and (= 1 (mod x 3)) (= 1 (mod y 3))) "1") (t (fill-p (/ x 3) (/ y 3)))))) (insert (format "P1\n%d %d\n" s s)) (dotimes (y s) (dotimes (x s) (insert (fill-p x y) " ")))) (image-mode)) (defun mandelbrot () (pop-to-buffer (get-buffer-create "*mandelbrot*")) (let ((w 400) (h 300) (d 32)) (fundamental-mode) (erase-buffer) (set-buffer-multibyte nil) (insert (format "P6\n%d %d\n255\n" w h)) (dotimes (y h) (dotimes (x w) (let* ((cx (* 1.5 (/ (- x (/ w 1.45)) w 0.45))) (cy (* 1.5 (/ (- y (/ h 2.0)) h 0.5))) (zr 0) (zi 0) (v (dotimes (i d d) (if (> (+ (* zr zr) (* zi zi)) 4) (return i) (psetq zr (+ (* zr zr) (- (* zi zi)) cx) zi (+ (* (* zr zi) 2) cy)))))) (insert-char (floor (* 256 (/ v 1.0 d))) 3)))) (image-mode))) #+end_src * Emacs reencode buffers with other encoding - Use the function =revert-buffer-with-coding-system= to re-open a buffer in another encoding. - Customize the variable =file-coding-system-alist= to control whether certain files should always be opened with a specific encoding.