abo-abo / lispy

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

Package specifier is interpreted as start of new symbol in Common lisp. #656

Open simendsjo opened 1 year ago

simendsjo commented 1 year ago

Colon is package specifier, so a:b means the symbol b exported from package a. This works for function calls, e.g. (a:b), but other places, pressing : will insert a space (a:b c :d) instead of (a:b c:d)

RuijieYu commented 1 year ago

I see what's going on. In which scenarios do you expect to have spaces? I have come up with the following cases, do you have more?

  1. after a "numeric" value
  2. after a CL character syntax
simendsjo commented 1 year ago

I see what's going on. In which scenarios do you expect to have spaces? I have come up with the following cases, do you have more?

I don't really see the usecase for automatically inserting spaces. I press space iff I need to add another value/symbol/whatever. You're talking about 1f would automatically insert a space, giving 1 f? And #\sp doing #\s p? It's a bit too magic for me and not something I really want. It would just get in the way causing extra spaces like in this case or double spaces because I already add a space myself.

RuijieYu commented 1 year ago

Let me address this first: you can disable space auto-insertion by customizing lispy-no-space to non-nil. If that is set, none of the following is relevant to you.


I should have been more specific. I meant: in which cases do you (or anyone who wants smart spaces before colons) : and expect a space be added. In other words, without the space, this does not form a valid lisp syntax. After all, this should be the core reason why lispy implements the auto-spacing feature for certain punctuations in the first place.

The current behavior for the auto-spacing is that unless the colon is at the function position or after characters such as "#", and I want to make lispy recognize more patterns where adding the space before colon is not desirable, like the scenario in your report.

after a "numeric" value

I tested '(1:a), '(2.3:b), etc., in sbcl. All these failed with the error message that the package named "1" or "2.3" does not exist. Therefore, iff we agree that no packages should be named as such, then we can allow colon to insert a space when there is a numeric value before it.

after a CL character syntax

Colons after CL charcter syntaxes re considered part of the character syntax. sbcl considers this '(#\newline:c) as referring to the character named "newline:c", which doesn't exist. Similarly, '(#\x:y) refers to the character "x:y". In this case, adding a space before colon makes each example a valid s-exp: '(#\newline :c), '(#\x :y).

simendsjo commented 1 year ago

Let me address this first: you can disable space auto-insertion by customizing lispy-no-space to non-nil. If that is set, none of the following is relevant to you.

Great, thanks!

I tested '(1:a), '(2.3:b), etc., in sbcl. All these failed with the error message that the package named "1" or "2.3" does not exist. Therefore, iff we agree that no packages should be named as such, then we can allow colon to insert a space when there is a numeric value before it.

You probably did something wrong, because this should work.

(cl:defpackage "1")
(cl:in-package "1")
(cl:defparameter exists cl:t)

;; 1::exists returns T

(cl:defpackage "2.3")
(cl:in-package "2.3")
(cl:defparameter exists cl:t)

;; 2.3::exists returns T
RuijieYu commented 1 year ago

Thanks for the example. So that rules out rule 1.

Can you think of any possibilities that rule 2 is unwanted -- that is, it might be valid code without the space? If not, I will make a PR soonish™️ where the colon smart spacing consists of only rule 2 for common lisp.

simendsjo commented 1 year ago

Can you think of any possibilities that rule 2 is unwanted -- that is, it might be valid code without the space?

I cannot think of any, but I'm not that experienced with Common Lisp.