Skip to content

Commit

Permalink
Protect against symbols with unsafe chars
Browse files Browse the repository at this point in the history
Fixes abo-abo#648.

* lispy.el lispy--symbol-safe-chars-regexp: define safe chars.
(lispy--read): protect against unsafe chars in a symbol.
  • Loading branch information
RuijieYu committed Apr 4, 2023
1 parent fe44efd commit 46ffa2e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lispy.el
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,12 @@ See https://clojure.org/guides/weird_characters#_character_literal.")
(match-string subexp)))
t t nil subexp)))))

(defconst lispy--symbol-safe-chars-regexp
(rx (any alnum ?+ ?- ?* ?/ ?: ?=))
"Regexp for \"safe\" characters.
Safe characters are those which are suitable for a symbol and
have no special reader syntax.")

;; TODO: Make the read test pass on string with semi-colon
(defun lispy--read (str)
"Read STR including comments and newlines."
Expand Down Expand Up @@ -7524,11 +7530,13 @@ See https://clojure.org/guides/weird_characters#_character_literal.")
(unless (lispy--in-string-or-comment-p)
(replace-match (format "(ly-raw racket-option %s)"
(match-string 1)))))
;; Clojure # in a symbol
;; Protect symbols containing unsafe characters
(goto-char (point-min))
(while (re-search-forward "\\_<\\(?:\\sw\\|\\s_\\)+\\_>" nil t)
(unless (lispy--in-string-p)
(when (cl-position ?# (match-string 0))
(when (not (string-match
lispy--symbol-safe-chars-regexp
(match-string 0)))
(let* ((bnd (lispy--bounds-dwim))
(str (lispy--string-dwim bnd)))
(delete-region (car bnd) (cdr bnd))
Expand Down

0 comments on commit 46ffa2e

Please sign in to comment.