abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.2k stars 130 forks source link

Don't insert space between `#p` and double quotes in Common Lisp #597

Open Ambrevar opened 3 years ago

Ambrevar commented 3 years ago

In Common Lisp, pathnames can be written using the #p"..." reader macro. But Lispy inserts a space before the double quotes on ".

While we are at it, we could take provision for any reader macro.

Possible fix:

(defun lispy-quotes (arg)
  "Insert a pair of quotes around the point.

When the region is active, wrap it in quotes instead.
When inside string, if ARG is nil quotes are quoted,
otherwise the whole string is unquoted."
  (interactive "P")
  (let (bnd)
    (cond ((region-active-p)
           (if arg
               (lispy-unstringify)
             (lispy-stringify)))
          ((and (setq bnd (lispy--bounds-string))
                (not (= (point) (car bnd))))
           (if arg
               (lispy-unstringify)
             (if (and lispy-close-quotes-at-end-p (looking-at "\""))
                 (forward-char 1)
                 (progn (insert "\\\"\\\""))
               (backward-char 2))))

          (arg
           (lispy-stringify))

          ((lispy-after-string-p "?\\")
           (self-insert-command 1))

          (t
-           (lispy--space-unless "^\\|\\s-\\|\\s(\\|[#]")
+           (lispy--space-unless "^\\|\\s-\\|\\s(\\|[#][^[:space:]():]*")
           (insert "\"\"")
           (unless (looking-at "\n\\|)\\|}\\|\\]\\|$")
             (just-one-space)
             (backward-char 1))
           (backward-char)))))
Ambrevar commented 3 years ago

Note that I'm excluding : in particular so that a space is inserted after Scheme and CL keywords like #:foo.

NightMachinery commented 3 years ago

There is a similar problem where lispy-tab inserts a bogus space in (list '(#\Newline)) to make it (list '(#\N ewline)).

Ambrevar commented 3 years ago

I can reproduce.