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

Adding R syntax highlight to *.R files #1073

Closed
alireza202 opened this issue Feb 9, 2016 · 2 comments · Fixed by #1076
Closed

Adding R syntax highlight to *.R files #1073

alireza202 opened this issue Feb 9, 2016 · 2 comments · Fixed by #1076

Comments

@alireza202
Copy link

R notebook files have a proper syntax highlight, however, text files with extension ".R" do not have any syntax highlights. Python ".py" files, on the other hands, do have proper syntax highlight. When I'm editing ".R" files, I end up renaming them to ".py", and then back to ".R" to have some sort of syntax highlight, but obviously this is not the right solution. It would be great if this feature is added.

@takluyver
Copy link
Member

At least on my system, they are correctly highlighted with a lowercase .r extension, but not with a capital .R extension.

We try two things to set the highlighting mode:

  1. The server calls the Python function mimetypes.guess_type(path). If we get a mimetype, we use CodeMirror's findModeByMIME() function to get the mode. On my system, neither .r nor .R appears to have a registered mime type.
  2. If that hasn't got us a mode, we use the file extension and call CodeMirror's findModeByExtension() function. Looking at CodeMirror's modes data, it recognises .r but not .R.

Maybe we should make all file extensions lowercase before looking them up. You could in theory differentiate an extension by case, but I can't think of any examples. My system recognises capitalised extensions as equivalent to the lowercase form, e.g. .PY. And I can't see any capitalised extensions in the CodeMirror data.

takluyver added a commit to takluyver/notebook that referenced this issue Feb 10, 2016
It looks like CodeMirror stores no capitalised extensions:
https://github.com/codemirror/CodeMirror/blob/master/mode/meta.js

If there ever are any, this would break looking them up. But that seems
fairly unlikely.

Closes jupytergh-1073
@alireza202
Copy link
Author

Thanks! It works with ".r".

@minrk minrk added this to the 4.2 milestone Apr 8, 2016
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants