Skip to content

Commit 4203638

Browse files
committed
Protect against symbols with unsafe chars
Fixes #648. * lispy.el lispy--symbol-safe-chars-regexp: define safe chars. (lispy--read): protect against unsafe chars in a symbol. lispy-left lispy-right: also match for beginning and end of symbol.
1 parent fe44efd commit 4203638

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lispy.el

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@
182182
:group 'bindings
183183
:prefix "lispy-")
184184

185-
(defvar lispy-left "[([{]"
185+
(defvar lispy-left (rx (or (any "([{") symbol-start))
186186
"Opening delimiter.")
187187

188-
(defvar lispy-right "[])}]"
188+
(defvar lispy-right (rx (or (any "])}") symbol-end))
189189
"Closing delimiter.")
190190

191191
(defvar lispy-outline "^;;\\(?:;[^#]\\|\\*+\\)"
@@ -7286,6 +7286,12 @@ See https://clojure.org/guides/weird_characters#_character_literal.")
72867286
(match-string subexp)))
72877287
t t nil subexp)))))
72887288

7289+
(defconst lispy--symbol-safe-chars-regexp
7290+
(rx (any alnum ?+ ?- ?* ?/ ?: ?=))
7291+
"Regexp for \"safe\" characters.
7292+
Safe characters are those which are suitable for a symbol and
7293+
have no special reader syntax.")
7294+
72897295
;; TODO: Make the read test pass on string with semi-colon
72907296
(defun lispy--read (str)
72917297
"Read STR including comments and newlines."
@@ -7524,11 +7530,13 @@ See https://clojure.org/guides/weird_characters#_character_literal.")
75247530
(unless (lispy--in-string-or-comment-p)
75257531
(replace-match (format "(ly-raw racket-option %s)"
75267532
(match-string 1)))))
7527-
;; Clojure # in a symbol
7533+
;; Protect symbols containing unsafe characters
75287534
(goto-char (point-min))
75297535
(while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t)
75307536
(unless (lispy--in-string-p)
7531-
(when (cl-position ?# (match-string 0))
7537+
(unless (string-match
7538+
lispy--symbol-safe-chars-regexp
7539+
(match-string 0))
75327540
(let* ((bnd (lispy--bounds-dwim))
75337541
(str (lispy--string-dwim bnd)))
75347542
(delete-region (car bnd) (cdr bnd))

0 commit comments

Comments
 (0)