Skip to content

Recognize comments in Janet files #49

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

Merged
merged 2 commits into from
Feb 25, 2024
Merged

Conversation

MaxGyver83
Copy link
Contributor

Fix issue #47 partly.

Janet uses # for comments (Lisp uses ;).

@MaxGyver83
Copy link
Contributor Author

I guess that it's inefficient to define comment_char in multiple places. But when I add a script-local variable on top of the file, it does not work:

if &ft == 'janet' | let s:comment_char = '#' | else | let s:comment_char = ';' | end

I think at this point, &ft isn't set to janet yet.

@kovisoft
Copy link
Owner

Thanks for the fix, but I think it does not really conform to the other parts of the filetype and comment handling of paredit. See for example s:fts_balancing_all_brackets, s:fts_multiline_comment or s:fts_datum_comment. The general logic is that we define what languages need support for a specific functionality. It is not 100% sure that the only language using # for comments is going to be janet.

You say that adding a script-local variable on top of the file does not work, because the filetype is defined after the script is loaded. How about doing the same as for the other variables mentioned above? Instead of defining the comment character in a script-local variable, just define the filetype for the # comment character. Then wherever there was a reference to ; we define the comment character based on the filetype (similar to how you are doing it in your pull request, but the filetype defined separately).

For example if we define s:fts_hash_comment as '.*\(janet\).*' then we can use it in s:InsideComment this way:

        let comment_char = ';'
        if &ft =~ s:fts_hash_comment
            let comment_char = '#'
        endif
        return match( line, comment_char ) >= 0

@MaxGyver83
Copy link
Contributor Author

Thanks for the fix, but I think it does not really conform to the other parts of the filetype and comment handling of paredit. See for example s:fts_balancing_all_brackets, s:fts_multiline_comment or s:fts_datum_comment. The general logic is that we define what languages need support for a specific functionality. It is not 100% sure that the only language using # for comments is going to be janet.

You say that adding a script-local variable on top of the file does not work, because the filetype is defined after the script is loaded. How about doing the same as for the other variables mentioned above? Instead of defining the comment character in a script-local variable, just define the filetype for the # comment character. Then wherever there was a reference to ; we define the comment character based on the filetype (similar to how you are doing it in your pull request, but the filetype defined separately).

For example if we define s:fts_hash_comment as '.*\(janet\).*' then we can use it in s:InsideComment this way:

        let comment_char = ';'
        if &ft =~ s:fts_hash_comment
            let comment_char = '#'
        endif
        return match( line, comment_char ) >= 0

Sure, this makes totally sense!

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.

2 participants