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

Non standard source formatting often reduces readability #43

Closed
Drainful opened this issue Mar 20, 2020 · 9 comments
Closed

Non standard source formatting often reduces readability #43

Drainful opened this issue Mar 20, 2020 · 9 comments

Comments

@Drainful
Copy link

Compare the following 2 screenshots:

Current formatting. Without counting parentheses (or using delimiter coloration) it's unclear how many arguments are being passed to sucle-mp:submit.
screen

Formatted with slime. Indentation makes it clear that it has been called with 1 standard argument and 2 keyword arguments
screen01

There seem to be many cases resembling the above. If this is how you prefer to indent your code then feel free to ignore/close, but otherwise I'd be happy to tweak the formatting as I read through.

@gregcman
Copy link
Owner

Thank you for taking the time to screenshot both scenarios! The first image definitely looks like the code is improperly formatted. However, the following is what appears in my editor:

Screenshot from 2020-03-20 14-04-04

My guess for the difference is that my emacs uses 8-character width tabs, and looking at this area, there are a lot of tabs. It might be a good idea for me to update the entire codebase to use spaces instead of tabs, as well as add a style-guide.

It would be incredibly helpful and greatly appreciated if you tweaked the formatting to make it correct, but it is in a lot of places so I wouldn't want you to make it hard on yourself. If you really want to help update the formatting, we should probably write it down in a style-guide.

Unrelated, how did you get the 'lambda' to look like a single-character symbol? That seems like a nice plugin.

@Drainful
Copy link
Author

Drainful commented Mar 20, 2020

I didn't notice, but you are 100% right; I'm using 4 character tabs. I ran a quick emacs script to convert each tab in the project to 8 spaces and everything looks perfectly fine, so there shouldn't be any need to tweak anything manually.

As far as the lambda goes, emacs has built in support for that feature with prettify symbols mode. I also have M-l bound to insert "lambda".

(setq prettify-symbols-alist
      '(("lambda" . 955) ; Replace instances of the word lambda with λ
        ))
(global-prettify-symbols-mode 1)

I believe emacs is getting more robust ligature support in version 27 which might improve this.

@Drainful
Copy link
Author

I can submit a PR for the tab->space conversion if you want, or I could share the script I used.

@Drainful
Copy link
Author

I’ll close this issue; a new one could be made for tabs vs spaces.

@mohe2015
Copy link

regarding tab vs spaces the correct way is tabs for indentation and spaces for alignment so everybody can set their tab width how they want. I also think that emacs can autoformat code like that.

@Drainful
Copy link
Author

I'm not sure that works for lisp where according to common style each line is offset a on a space by space basis, with no concept of levels of indentation at all. Every form is either a top level form or an argument, and arguments are offset at (offset of the form they were called on) + (character length of the function being called) with few exceptions.

@mohe2015
Copy link

Yeah you are right - according to this website most projects use two spaces. But I think autoformatting should still be possible. Unfortunately I don't have the time to look into that.

@Drainful
Copy link
Author

Autoformatting is trivially done with or without tabs using emacs or any other lisp ide. The original issue only came up because in a codebase that does contain tab characters, an emacs configured with a tab-width of 8 and one configured with a width of 4 disagree on the output, since formatting is done to visually allign forms with the same depth in the abstract syntax tree.

@gregcman
Copy link
Owner

@mohe2015 https://ukupat.github.io/tabs-or-spaces/ that pie chart is pretty stark, its a wonder how I didn't notice that before...

Also, here is the issue for formatting/editors #45

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

No branches or pull requests

3 participants