Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 194 forks source link

Clojure tagged elements should be treated as a single sexp #711

Open xiongtx opened 7 years ago

xiongtx commented 7 years ago

Expected behavior

Tagged elements in Clojure/EDN, such as #uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6", should be treated as a single sexp.

This is what clojure-forward-logical-sexp does in clojure-mode. clojure-forward-logical-sexp also takes into account hints (e.g. ^:private foo is treated as a single sexp).

Actual behavior

#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6" is treated as two sexps:

Steps to reproduce the problem

  1. In clojure-mode, call sp-forward-sexp with point at: |#uuid "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"

Backtraces if necessary (M-x toggle-debug-on-error)

N/A

Environment & version information

xiongtx commented 7 years ago

@Fuco1 I'll try to implement this if you'll give me some pointers.

My current idea is to simply use set sp-{forward, backward}-sexp to use clojure-{forward, backward}-logical-sexp in smartparens-clojure.el, though I'm not sure how best to do that (advising seems hackish).

Fuco1 commented 7 years ago

I think it should be possible to do this with the prefix functionality in SP. If this #uuid tag can only be applied to strings, you can add a :prefix property to the " pair.

From the docs:

PREFIX is a regular expression matching an optional prefix for
this pair in the specified major modes.  If not specified, the
characters of expression prefix syntax class are automatically
considered instead.  This can be used to attach custom prefixes
to pairs, such as prefix \"\\function\" in \\function{arg} in
`LaTeX-mode'.

So the regexp would be something like #uuid (with space at the end). Or if there are more variants you can construct the regexp to match them all.

Fuco1 commented 7 years ago

If any expression can have these tags, you can use the variable sp-sexp-prefix to configure it (that is a setting for everything in given major mode). Check its docstring.