diff --git a/symex-primitives-lisp.el b/symex-primitives-lisp.el index fadf57de..127fcb30 100644 --- a/symex-primitives-lisp.el +++ b/symex-primitives-lisp.el @@ -168,6 +168,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.") @@ -245,7 +248,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 () @@ -258,10 +261,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)