-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
add emacs #1297
add emacs #1297
Conversation
I'll try to post an example soon of this working |
You can see some of the highlighting at https://prism-emacs-ogfsnjvwlg.now.sh/post |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thanks for contributing.
Apart from my inline comments, there are other things that need to be adressed before inclusion in Prism:
- You need to add the language in the
components.js
file. - You should add an example file, following the format of the existing ones.
- You should ideally add tests. You can find more information on the Test suite and look at the many existing examples.
components/prism-emacs.js
Outdated
@@ -0,0 +1,179 @@ | |||
Prism.languages.emacs = (function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emacs
is an editor before being a language. I think it would be less confusing to name the componentemacs-lisp
.- Since this is a dialect of Lisp, it would have been interesting to have generic support for Lisp first, and then maybe add specific dialects support if the generic component can't handle them.
components/prism-emacs.js
Outdated
|
||
// Symbol name. See https://www.gnu.org/software/emacs/manual/html_node/elisp/Symbol-Type.html | ||
// & and : are excluded as they are usually used for special purposes | ||
const symbol = '[-+*/_~!@$%^=<>{}\\w]+'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Prism is written is ES5. ES6 is not compatible with IE11 so this component would need to be transpiled or rewrittent in ES5. Here, this just means the
const
should be replaced withvar
. - The
_
should not be needed here as it's already included in\w
.
components/prism-emacs.js
Outdated
// Functions to construct regular expressions | ||
// simple form | ||
// e.g. (interactive ... or (interactive) | ||
const simple_form = name => new RegExp(`(\\()${name}(?=[\\s\\)])`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Same thing for fat arrows and template strings. Please use ES5.
- There is no need to espace the closing parenthesis in the character class at the end.
components/prism-emacs.js
Outdated
// e.g. (interactive ... or (interactive) | ||
const simple_form = name => new RegExp(`(\\()${name}(?=[\\s\\)])`); | ||
// booleans and numbers | ||
const primitive = pattern => new RegExp(`([\\s\\(\\[])${pattern}(?=[\\s\\)])`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to espace the opening and closing parentheses in the character classes here.
components/prism-emacs.js
Outdated
}, | ||
'comment': /;.*/, | ||
'string': { | ||
pattern: /"(?:[^"\\]*|\\.)*"/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about line feeds? Are multiline strings supported in Emacs Lisp? If not, the character class should probably also exclude \r
and \n
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think multiline feeds are supported, I say that because this is a valid function definition
(defun multiply-by-seven (number)
"Multiply NUMBER by seven,
second line"
(* 7 number))
components/prism-emacs.js
Outdated
pattern: primitive("[-+]?\\d+(?:\\.\\d*)?"), | ||
lookbehind: true | ||
} | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the array contains only one pattern, it could be be removed.
components/prism-emacs.js
Outdated
pattern: new RegExp(par + 'def(?:var|const|custom|group)\\s+' + symbol), | ||
lookbehind: true, | ||
inside: { | ||
'keyword': /def[a-z]+/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what the highlighting would be here with a code piece like (defvar defabc
? Maybe a ^
anchor should be added at the beginning of this regexp.
components/prism-emacs.js
Outdated
pattern: new RegExp(par + `(?:cl-)?(?:defun\\*?|defmacro)\\s+${symbol}\\s+\\([\\s\\S]*\\)`), | ||
lookbehind: true, | ||
inside: { | ||
'keyword': /(?:cl-)?def\S+/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ^
anchor might be needed here too.
components/prism-emacs.js
Outdated
pattern: new RegExp(par + `lambda\\s+\\((?:&?${symbol}\\s*)*\\)`), | ||
lookbehind: true, | ||
inside: { | ||
'keyword': /lambda/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A ^ anchor might be needed here too.
@Golmote Thanks for the feedback! I'm having some trouble understanding the tests. I'll upload here with some comments on what I'm having trouble with. I think the renamings I made will cause the previous comments to appear outdated. I'm adding this here as a reminder that they still need to be addressed |
components.js
Outdated
@@ -197,6 +197,10 @@ var components = { | |||
"title": "Eiffel", | |||
"owner": "Conaclos" | |||
}, | |||
"elisp": { | |||
"title": "Elisp", | |||
"owner": "JuanCaicedo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I should be the owner, since I didn't develop this. Totally willing to defer to @akirak if they would like to take it over 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for creating this pull request.
I don't mind your being owner of the module, but this plugin is experimental, and there are some corner cases where it doesn't render well, like in this example. It's doing complex things, and I don't know how to fix this bug.
If you still don't mind using the plugin, you or whoever can be its owner. As you've put an effort in adapting the plugin, I think you deserve the credit. I will mention this merge in the README of my repo, but I won't be responsible for maintaining the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akirak has a point, here. In Prism, we do expect the component's "owner" to do some kind of maintenance if issues regarding this component arise.
So you should probably keep it with your ownership, @JuanCaicedo.
|
||
[ | ||
["string", ["\"\""]], | ||
["string", "\"foo\\\r\nbar\""] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leads to a failure which I don't understand
Token Stream:
[["string",["\"\""]],"\r\n\"foo\\\r\nbar\""]
-----------------------------------------
Expected Token Stream:
[["string",["\"\""]],["string","\"foo\\\r\nbar\""]]
-----------------------------------------
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression is that the second case is not recognized as a string. I'm not sure if it's a problem I'm how I'm writing the test cases or in the implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to assume the implementation is right and my testing is wrong. If so, maybe the problem is that listing strings like this isn't valid lisp. Maybe the test tokens could me changed to
(
""
"foo
bar"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, your string pattern in the component allows only unescaped line feeds. #1297 (comment)
Also note, you may have to add some classes to your theme (CSS) to fully take advantage of it. I have tried it with Dracula theme included in the repo, which is a dedicated effort for the language, but I haven't tested it with any other themes for Prism. |
@Golmote I'm the original author of the plugin, and I'm sorry for this tedious work. That code was not meant to be merged into the code base of PrismJS. It should be transpiled using babel, but apparently its resulting code will not be suitable for maintenance by human. Therefore I didn't send a merge request to you. I am currently working on another project, and I'm not sure if I will adapt this stuff to the proper plugin format. Thank you for your comments. |
The name |
@akirak No worries. I noticed that some patterns are not handled by the official themes. It's not the first component doing so though, and it's ok if some parts are tagged but not styled. I'll just check the appearance once the PR is ready to be merged and maybe we'll make some adjustments. We might also want to add a comment with a link to your original repo, to credit your original work and in case some users are interested in using the Dracula theme you made. The transpilation to ES5 should not be that tedious in this case: you're really just using tiny bits of syntactic sugar. Transforming I understand the naming limitation you had. Maybe we can still add Thanks for showing up on the PR anyway! I hope @JuanCaicedo can take it to a mergeable state. :) |
@Golmote sorry for the delay, I'm working through these changes now 😀 |
components/index.min.js
Outdated
@@ -0,0 +1 @@ | |||
function loadLanguages(e){e||(e=Object.keys(components.languages).filter(function(e){return"meta"!==e})),Array.isArray(e)||(e=[e]),e.forEach(function(e){components.languages[e]&&components.languages[e].require&&loadLanguages(components.languages[e].require),require("./prism-"+e)})}var components=require("../components.js");module.exports=loadLanguages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was generated when I ran gulp
. Not sure if it should be included. If not, I can revert the commit that added it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I never realized a minified version was generated for it.
I don't think it's needed, though. I'll have to update the gulpfile to exclude it. In the meantime, you can remove it from this PR, indeed.
Sorry about this, and thanks for pointing it out!
Prism.languages.lisp = language; | ||
Prism.languages.elisp = language; | ||
Prism.languages.emacs = language; | ||
Prism.languages['emacs-lisp'] = language; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this alias is allowed. I added it to allow more flexibility, but I can remove it you'd rather not have it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok, we can keep it.
@Golmote I fixed the merge conflicts and addressed the majority of the code comments (sorry for the accidental style changes 😬) I'm working on trying to combine the regexes you mentioned. I'm finding it difficult though, so if it's okay to merge this without doing that, let me know 😀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuanCaicedo Don't worry it's ok if you don't manage to merge the regexps. Maybe I'll try later, once the PR is merged.
Thanks for updating the PR, we're almost there! Please take a look at my comments.
components/index.min.js
Outdated
@@ -0,0 +1 @@ | |||
function loadLanguages(e){e||(e=Object.keys(components.languages).filter(function(e){return"meta"!==e})),Array.isArray(e)||(e=[e]),e.forEach(function(e){components.languages[e]&&components.languages[e].require&&loadLanguages(components.languages[e].require),require("./prism-"+e)})}var components=require("../components.js");module.exports=loadLanguages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I never realized a minified version was generated for it.
I don't think it's needed, though. I'll have to update the gulpfile to exclude it. In the meantime, you can remove it from this PR, indeed.
Sorry about this, and thanks for pointing it out!
Prism.languages.lisp = language; | ||
Prism.languages.elisp = language; | ||
Prism.languages.emacs = language; | ||
Prism.languages['emacs-lisp'] = language; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok, we can keep it.
examples/prism-lisp.html
Outdated
<li>"language-emacs"</li> | ||
<li>"language-emacs-lisp"</li> | ||
</ul> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to a recent update, you can remove everything above this comment, in this file. The example header will be generated automatically.
components.json
Outdated
@@ -373,6 +373,11 @@ | |||
"title": "Liquid", | |||
"owner": "cinhtau" | |||
}, | |||
"lisp": { | |||
"title": "lisp", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you capitalize the name here? "Lisp"
Note that you'll need to run gulp
after this change, to update the Show Language plugin files.
bar" | ||
"\"foo\"" | ||
"foo\tbar" | ||
"foo\tbar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's a duplicate here. I don't think there's a need to test it twice.
themes/prism.css
Outdated
@@ -104,7 +104,7 @@ pre[class*="language-"] { | |||
.token.url, | |||
.language-css .token.string, | |||
.style .token.string { | |||
color: #9a6e3a; | |||
color: #a67f59; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should not be here. This file was changed 10 days ago in 8aea939. #9a6e3a
is the correct value.
@Golmote I've updated based on your last comments 😀 |
@JuanCaicedo Yay! 🎉 |
This adds the plugin developed by akirak/prism-emacs-lisp for the emacs lisp language. The extension is
emacs
.I would like to support also
lisp
andelisp
since both of those names are used, but I'm not sure what would be the best way to do that.Let me know if there's anything missing to be able to add this 😀