Added snippets.

Pascal J. Bourguignon [2021-04-03 16:16]
Added snippets.
Filename
edit.el
inputrc.el
sound.el
diff --git a/edit.el b/edit.el
new file mode 100644
index 0000000..c481501
--- /dev/null
+++ b/edit.el
@@ -0,0 +1,24 @@
+
+(defvar edit-setter)
+
+(defun edit-complete ()
+  (interactive)
+  (goto-char (point-min))
+  (funcall edit-setter (read (current-buffer)))
+  (kill-buffer))
+
+(defun edit (sexp setter)
+  "Edits sexp in a buffer, until C-c C-c is typed. Then the setter function is called."
+  (let ((name (format "*edit* %S" sexp)))
+    (switch-to-buffer (get-buffer-create name))
+    (erase-buffer)
+    (paredit-mode)
+    (local-set-key (kbd "C-c C-c") 'edit-complete)
+    (local-set-key (kbd "C-c c")   'edit-complete)
+    (set (make-local-variable 'edit-setter) setter)
+    (insert (pp sexp))))
+
+;; (defvar *x* nil)
+;; (edit '("a" "b" "c") (lambda (new-value) (setf *x* new-value)))
+;; (+ 2 3)5
+;; *x* ; --> ("aa" "bbb" "cccc")
diff --git a/inputrc.el b/inputrc.el
new file mode 100644
index 0000000..ddfd3eb
--- /dev/null
+++ b/inputrc.el
@@ -0,0 +1,56 @@
+
+(defun read-inputrc-file (file)
+  (let ((expressions '()))
+    (flet ((collect-expression (expression)
+             (push expression expressions))
+           (collect-include (included-expressions)
+             (setf expressions (nreverse (revappend expressions
+                                                    included-expressions)))))
+       (dolist (line (split-string (string-from-file-literally file) "\n"))
+         (let* ((sharp-pos (position (character "#") line))
+                (line      (if sharp-pos
+                               (subseq line 0 sharp-pos)
+                               line))
+                (colon-pos (position (character ":") line)))
+           (if colon-pos
+               (let ((left  (substring line 0 colon-pos))
+                     (right (substring line (1+ colon-pos))))
+                 (collect-expression `(alias
+                                       ,(car (read-from-string left))
+                                       ,(car (read-from-string right)))))
+               (let ((words (split-string line)))
+                 (when words
+                   (cond
+                     ((string= "$include" (first words))
+                      (collect-include (ignore-errors
+                                        (read-inputrc-file (second words)))))
+                     (t
+                      (collect-expression (mapcar (lambda (string)
+                                                    (car (read-from-string string)))
+                                                  words)))))))))
+      (nreverse expressions))))
+
+
+;; (insert (pp (read-inputrc-file "~/.inputrc")))
+
+
+;; ((set editing-mode emacs)
+;;  (set meta-flag on)
+;;  (set convert-meta off)
+;;  (set input-meta on)
+;;  (set output-meta on)
+;;  (set bell-style visible)
+;;  (alias "[1~" beginning-of-line)
+;;  (alias "[3~" delete-char)
+;;  (alias "[4~" end-of-line)
+;;  (alias "" backward-kill-word)
+;;  (alias "[3~" kill-word)
+;;  (alias Meta-p "")
+;;  (alias Meta-n "")
+;;  (alias "p" "")
+;;  (alias "n" ""))
+;;
+;; (local-set-key "p" "")
+;; (kbd 'Meta-p)"[Meta-p]"
+;; "Meta-p"
+
diff --git a/sound.el b/sound.el
new file mode 100644
index 0000000..62269e8
--- /dev/null
+++ b/sound.el
@@ -0,0 +1,18 @@
+(require 'pjb-cl)
+
+(handler-case
+    (play-sound
+     `(sound :volume 0.5
+             :data ,(coerce (loop
+                              with freq = 440.0
+                              with rate = 8000
+                              repeat 16000
+                              for theta from 0
+                              for s = (+ 128 (* 128 (sin (* freq (/ theta rate)))))
+                              collect (round s))
+                            'string)) )
+  (error (err)
+    (message "%s" err)))
+
+
+
ViewGit