kovisoft / paredit

Official mirror of Paredit versions released on vim.org
84 stars 23 forks source link

Strange behavior in Janet files #47

Open MaxGyver83 opened 8 months ago

MaxGyver83 commented 8 months ago

I noticed some strange behavior in Janet files.

Example 1:

(defmacro $<
  [& args]
  (def specs (collect-proc-specs args))
  (tuple $<* ;specs)
  # ~(upscope
  #   (pp ,specs)
  #   (tuple ,$<* ,;specs))
  )

When I select the comment lines (linewise visual mode) and delete them with d, I end up with this:

(defmacro $<
  [& args]
  (def specs (collect-proc-specs args))
  (tuple $<* ;specs)
  ((
  )

These two opening parentheses are unexpected.

Example 2a:

(defn- escape [str]
  (->> str
    (string/replace-all " " "\\ ")
    (string/replace-all `"` `\"`)
    ))

When I put the cursor in line 4 of this snippet and delete/cut the line with dd, I end up with:

(defn- escape [str]
  (->> str
    (string/replace-all " " "\\ ")
    ("
    ))

The (" is not expected.

Example 2b:

When I put the cursor again in line 4 in example 2a and try to copy the line with yyp (instead of deleting it), I end up with:

(defn- escape [str]
  (->> str
    (string/replace-all " " "\\ ")
    (string/replace-all `"` `\"`)
     string/replace-all ` ` `\"`)
    ))

The opening parenthesis in the new line 5 is missing.

kovisoft commented 6 months ago

Sorry for the late response. Well, TBH the janet support was not part of the original implementation, it was added as a contribution here: https://github.com/kovisoft/paredit/commit/9f5ba8a96c15c897fcbeec9eb907ee0f21dbc393

I myself do not know anything about the janet language. I looked it up here: https://janet-lang.org/docs/syntax.html and it seems that its syntax differs from the general lisp syntax in many places. One of them is the commenting. In lisp the comment is ; which seems to be used for a shorthand of (splice ) in janet, and the comment is # in janet. This is causing the first issue, because paredit does not recognize that we are inside a comment block.

The other issues are caused by the backquote that again means something different in janet.

MaxGyver83 commented 6 months ago

Thank you for this hint. See #49 which fixes the behavior of example 1.