diff --git a/lispy.el b/lispy.el index 0c5c9720..73229d1e 100644 --- a/lispy.el +++ b/lispy.el @@ -182,10 +182,10 @@ :group 'bindings :prefix "lispy-") -(defvar lispy-left "[([{]" +(defvar lispy-left (rx (or (any "([{") symbol-start)) "Opening delimiter.") -(defvar lispy-right "[])}]" +(defvar lispy-right (rx (or (any "])}") symbol-end)) "Closing delimiter.") (defvar lispy-outline "^;;\\(?:;[^#]\\|\\*+\\)" @@ -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." @@ -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))