Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor sly-cl-indent.el so it doesn't clobber cl-indent.el #312

Closed
wants to merge 35 commits into from

Conversation

SwiftLawnGnome
Copy link
Contributor

No description provided.

This is the only usage of `rx` in all of sly so it seems silly to
`require` it for that one simple regexp.
Old version hogged memory by repeatedly calling `reverse` on a fresh
list. This version reuses the cons, and uses the primitive `assoc`
instead of `cl-assoc`. It's faster and way more memory efficient.
And use `buffer-substring` instead of `buffer-substring-no-properties`,
since `string-to-number` doesn't care about string properties, and
`buffer-substring` has an opcode.

This is considered a hot spot, so it seems appropriate to try to
optimize it.
Removed `sly-length>`, as its only usage was checking if a list had a
cdr. Made `sly-length=` only accept a list (the only argument type it's
used with), and only use sparingly.
It's a hot spot, and the only call in sly.el was wrapped in `inline`,
which is not supposed to be used in source code.
@joaotavora
Copy link
Owner

Thanks very much @SwiftLawnGnome for all these enhacements. I know I'm very late in reviewing, but they aren't forgotten!

@@ -1674,10 +1678,6 @@ EVAL'd by Lisp."
(and (>= (buffer-size) 6)
(>= (- (buffer-size) 6) (sly-net-decode-length))))

(defun sly-run-when-idle (function &rest args)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this: these one-off half-decent abstractions (in the words of the former SLIME maintainer) aren't really useful and complicate reading. I welcome this.

@tarsius
Copy link
Contributor

tarsius commented May 22, 2020

What's the status of this?

@joaotavora
Copy link
Owner

joaotavora commented May 22, 2020 via email

* (sly--lisp-indent-function-1, sly--lisp-indent-259): Use `char-before`.
@SwiftLawnGnome
Copy link
Contributor Author

From what I've seen, it looks fantastic.

Awesome!

I just have to review it, and I don't have a lot of time now.

I think it's definitely worth a review, I'm sure there are issues with it as it stands.

Or I give Zach commit permissions (though I'd have to bother him with a couple of boring details, such as GNU-style commit messages).

Please do bother me! I've been self conscious about my commits, I'd like to keep the style in line with Sly's. I'll start formatting them like * file.el (function-name): Change., and if there's other style preferences let me know.

Regarding sly-cl-indent, I was thinking there may need to be more backward compatibility since this refactor will inevitably break some people's private configs. The sly-lisp-indent-compatibility-mode could add additional aliases, for functions and macros like define-common-lisp-style and custom vars like lisp-indent-maximum-backtracking. Some of those vars are shadowed from cl-indent.el so it could be a bit sketchy. What do you think?

* contrib/sly-autodoc.el (sly-autodoc--parsing-safe-p): Remove.
(sly-autodoc--parse-context): Don't use `sly-autodoc--parsing-safe-p`.

(sly-autodoc--cache-get, sly-autodoc--cache-put): Remove.
(sly-autodoc): Don't use `sly-autodoc--cache-get`.
(sly-autodoc--async%): Don't use `sly-autodoc--cache-put`.

(sly-autodoc--fontify): Fix indentation.
With `readtable-case` :invert, `tokenize-symbol-thoroughly` was blindly
inverting every character in a string, but :invert only inverts the case
when the entire token is the same case. So `SYMBOL` is read as `symbol`,
and vice versa, but `Symbol` is read as-is. This is now handled
correctly.

* slynk/slynk.lisp (casify-char): Remove.
(char-casifier): New function.
Takes a string and returns a function which will apply the appropriate
case to the characters in the string, according to `readtable-case`.
(tokenize-symbol-thoroughly): Use `char-casifier`.
@joaotavora
Copy link
Owner

The most important cl-indent.el bits are already in master. The rest I have restructured and put them in a branch called many-zach-tweaks. I will work on that branch for a few days, then push to master. There are a few commits that I didn't think were worth it, like killing some one-off functions which could yet be useful. Though I liked the vast majority: I found it surprising that the gist of the changes were similar in spirit to what I tried in SLIME around 2013/14. So I let most of it through so we don't get another fork soon :-D

@joaotavora
Copy link
Owner

Regarding sly-cl-indent, I was thinking there may need to be more backward compatibility since this refactor will inevitably break some people's private configs. The sly-lisp-indent-compatibility-mode could add additional aliases, for functions and macros like define-common-lisp-style and custom vars like lisp-indent-maximum-backtracking. Some of those vars are shadowed from cl-indent.el so it could be a bit sketchy. What do you think?

Regarding this. I think we can cautiously assume that SLY users won't have so many of these configs. But surely here and there, a complaint might pop up. We'll hope they report it.

@joaotavora joaotavora closed this Jun 29, 2020
@joaotavora joaotavora reopened this Jun 29, 2020
* lib/sly-cl-indent.el (common-lisp-style): Remove alias to
`sly-common-lisp-style`. All uses of `sly-common-lisp-style` now fall
back on `common-lisp-style` if it's `bound-and-true-p`.
Lots of changes here. The biggest is with respect to the LOOP keyword
regexps. The main reason I felt compelled to do this was that those
regexps weren't terminated with "\\_>" (symbol end), so `thereis` was
being indented like `the`. Then I just started fixing up a bunch of
other regexp related stuff while I was at it.

* lib/sly-cl-indent.el
(sly--lisp-loop-keyword-regexp): New function. Creates a regexp matching
a keyword or (maybe interned) symbol whose name is exactly one of its
arguments. It's now used to generate the values of the following variables.
(sly--common-lisp-body-introducing-loop-macro-keyword): Renamed to
`sly--lisp-indent-body-loop-macro-keyword`.
(sly--common-lisp-accumlation-loop-macro-keyword): Renamed to
`sly--lisp-indent-accumulation-loop-macro-keyword`.
(sly--common-lisp-prefix-loop-macro-keyword): Renamed to
`sly--lisp-indent-prefix-loop-macro-keyword`.
(sly--common-lisp-indent-clause-joining-loop-macro-keyword): renamed to
`sly--lisp-indent-joining-loop-macro-keyword`.
(sly--common-lisp-indent-indented-loop-macro-keyword): Renamed to
`sly--lisp-indent-indented-loop-macro-keyword`, and added some missing
keywords (probably still missing a few).
(sly--common-lisp-indenting-loop-macro-keyword): Renamed to
`sly--lisp-indent-conditional-loop-macro-keyword`.
(sly--lisp-indent-loop-macro-else-keyword): Renamed to
`sly--lisp-indent-else-loop-macro-keyword`.
(sly--lisp-indent-lambda-list-keywords-regexp): Use `regexp-opt`, cuz
why not.
(sly--lisp-indent-feature-expr-regexp): Fixed the regexp (#!+ is not a
valid feature expression as far as I know).
(sly--lisp-indent-loop-advance-past-keyword-on-line): Use
`skip-syntax-forward`, instead of `looking-at` every character in a
loop.
(sly--lisp-indent-function-lambda-hack): Fixed the regexp. Before it
would treat `(function-foo (lambda ()))` the same as
`(function (lambda ()))`.
(sly--lisp-indent-beginning-of-defmethod-qualifiers): Trivial change to
the regexp, and use `match-beginning` instead of `match-string` to test
which group matched.
Before it would think "FOO-BAR" aught not to be downcased since the '-'
isn't UPPER-CASE-P.
I broke the whole point of the function in the last commit for no
reason, oops.

* lib/sly-cl-indent.el
(sly--lisp-indent-beginning-of-defmethod-qualifiers): Group "def" and
":" in the regexp for finding the start of a method definition, so the
two forms can be differentiated.
@SwiftLawnGnome
Copy link
Contributor Author

I've cherry-picked this one to the master branch. @SwiftLawnGnome can you make pull requests of your other commits, so that I can have an idea of what they're fixing/improving?

Yes, sorry about that. I keep forgetting to branch. Are there any commits here you'd still like to see or did you cherry all the ones that matter?

@joaotavora
Copy link
Owner

Yes, sorry about that. I keep forgetting to branch. Are there any commits here you'd still like to see or did you cherry all the ones that matter?

I don't know. I'm kinda lost now to be honest. I just think that the code you contribute to SLY is pretty good and would like to review it separately. Can you try rebase your "most current" branch on top of SLY's origin/master and showing me that in a new pull request?

@SwiftLawnGnome
Copy link
Contributor Author

I don't know. I'm kinda lost now to be honest.

Ha, yeah I made a real mess.

I just think that the code you contribute to SLY is pretty good and would like to review it separately. Can you try rebase your "most current" branch on top of SLY's origin/master and showing me that in a new pull request?

I just attempted to do that here but it looks like I may have done something wrong. I'm not exactly a git expert. If this isn't right I can try to just branch from master and add the one or two significant commits to that, it looks like a large majority of the meaningful ones were already merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants