summaryrefslogtreecommitdiff
path: root/guides/applications/emacs/elisp-demos.org
diff options
context:
space:
mode:
Diffstat (limited to 'guides/applications/emacs/elisp-demos.org')
-rw-r--r--guides/applications/emacs/elisp-demos.org28
1 files changed, 28 insertions, 0 deletions
diff --git a/guides/applications/emacs/elisp-demos.org b/guides/applications/emacs/elisp-demos.org
new file mode 100644
index 0000000..029f5be
--- /dev/null
+++ b/guides/applications/emacs/elisp-demos.org
@@ -0,0 +1,28 @@
+Some terse "context-free" Emacs Lisp snippets that hopefully speak for
+themselves.
+
+* The prefix argument
+#+begin_src elisp
+(defun my/prefix-arg-demo (arg)
+ (interactive (list current-prefix-arg))
+ (insert
+ (let ((num (prefix-numeric-value arg)))
+ (format "%s %d %s\n"
+ arg
+ num
+ (cond ((null arg) "N/A")
+ ((numberp arg) (format "M-%d or C-u %d" arg arg))
+ ((equal arg '-) (format "M-- or C-u -"))
+ ((listp arg)
+ (if (< num 0)
+ (format "(M-- or C-u -) C-u × %d" (log (- num) 4))
+ (format "C-u × %d" (log num 4)))))))))
+#+end_src
+#+begin_example
+nil 1 N/A
+2 2 M-2 or C-u 2
+- -1 M-- or C-u -
+(-16) -16 (M-- or C-u -) C-u × 2
+(64) 64 C-u × 3
+#+end_example
+