From a6578b54872824a00bf465a7af63aab14a92d101 Mon Sep 17 00:00:00 2001 From: Siddhartha Date: Fri, 14 Jun 2024 00:25:39 -0700 Subject: [PATCH] Commit some minor fixes in emit and capture There are still issues but they will likely require more thought and a deeper refactoring. --- symex-primitives-lisp.el | 9 ++++++--- symex-transformations-lisp.el | 14 ++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/symex-primitives-lisp.el b/symex-primitives-lisp.el index b71d8714..e28ddaf4 100644 --- a/symex-primitives-lisp.el +++ b/symex-primitives-lisp.el @@ -170,6 +170,9 @@ (defvar symex--re-whitespace "[[:space:]|\n]+" "Whitespace that may extend over many lines.") +(defvar symex--re-optional-whitespace "[[:space:]|\n]*" + "Optional whitespace that may extend over many lines.") + (defvar symex--re-symex-line "^[[:space:]]*[^;[:space:]\n]" "A line that isn't blank and isn't a comment line.") @@ -247,7 +250,7 @@ "Check if we're looking at an empty list." (looking-at-p (concat symex--re-left - symex--re-whitespace + symex--re-optional-whitespace symex--re-right))) (defun symex-empty-string-p () @@ -260,10 +263,10 @@ (defun symex-inside-empty-form-p () "Check if point is inside an empty form." (and (looking-back (concat symex--re-left - symex--re-whitespace) + symex--re-optional-whitespace) (line-beginning-position)) (looking-at-p - (concat symex--re-whitespace + (concat symex--re-optional-whitespace symex--re-right)))) (defun symex--racket-syntax-object-p () diff --git a/symex-transformations-lisp.el b/symex-transformations-lisp.el index 6e90a1d3..199def15 100644 --- a/symex-transformations-lisp.el +++ b/symex-transformations-lisp.el @@ -179,12 +179,18 @@ text, on the respective side." ((and before (string-match-p (concat symex--re-whitespace "$") (symex--current-kill))) + ;; if the text to be pasted before includes whitespace already, + ;; then don't add more "") (t " "))))) (defun symex-lisp--paste-before () "Paste before symex." (interactive) + (when (symex-inside-empty-form-p) + (symex--kill-ring-push + (string-trim-right + (symex--kill-ring-pop)))) (symex-lisp--paste "" (symex-lisp--padding t))) @@ -217,10 +223,10 @@ If a symex is currently selected, then paste after the end of the selected expression. Otherwise, paste in place." (interactive) (let ((padding (symex-lisp--padding nil))) - (if (symex-lisp--point-at-last-symex-p) - (symex--kill-ring-push - (string-trim-right - (symex--kill-ring-pop)))) + (when (symex-lisp--point-at-last-symex-p) + (symex--kill-ring-push + (string-trim-right + (symex--kill-ring-pop)))) (save-excursion (condition-case nil (forward-sexp)