summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob L. Kreuze2020-07-18 14:21:22 -0400
committerJakob L. Kreuze2020-07-18 14:21:22 -0400
commit3c43f715618968c18c6264b159bc03cec8387baa (patch)
treed9d0ea0b02cdf49094a1bb0de770ff303abebb70
parent127739b797de9393641dc46ce038f056d4443d32 (diff)
Implement interactive editing commands.
- expand-region - flatten-region - stringify-region
-rw-r--r--lisp/jakob.el47
1 files changed, 47 insertions, 0 deletions
diff --git a/lisp/jakob.el b/lisp/jakob.el
index f720d7e..c226f8a 100644
--- a/lisp/jakob.el
+++ b/lisp/jakob.el
@@ -79,3 +79,50 @@ very important questions."
"My sources say no." "Outlook not so good."
"Very doubtful.")))
(message (elt responses (mod (random) (length responses))))))
+
+
+;;;
+;;; Editing Commands
+;;;
+
+(defun expand-region ()
+ "Turn space-delimited line of sexps into several lines."
+ (interactive)
+ (save-excursion
+ (let* ((begin (region-beginning))
+ (end (region-end))
+ (region (buffer-substring begin end)))
+ (goto-char begin)
+ (while (<= (point) end)
+ (forward-sexp)
+ (newline)
+ (indent-for-tab-command)))))
+
+(defun flatten-region ()
+ "Turn newline-delimited region of sexps into single line."
+ (interactive)
+ (save-excursion
+ (let* ((begin (region-beginning))
+ (end (region-end))
+ (region (buffer-substring begin end)))
+ (goto-char end)
+ (while (> (point) begin)
+ (forward-sexp -1)
+ (delete-char -1)
+ (insert ? )))))
+
+(defun stringify-region ()
+ "Wrap all sexps in region with double quotes."
+ (interactive)
+ (save-excursion
+ (let* ((begin (region-beginning))
+ (end (region-end))
+ (region (buffer-substring begin end)))
+ (goto-char begin)
+ (while (< (point) end)
+ (forward-sexp)
+ (forward-sexp -1)
+ (insert ?\")
+ (forward-sexp)
+ (insert ?\")
+ (setf end (+ 2 end))))))

© 2015 - 2026 Jakob L. Kreuze