-
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
Changes from 6 commits
309d971
2aee520
5d3693b
1c7021c
4c96cab
68cd7b1
1c45ad7
3fdd5a3
e785a09
52a01d2
83ba77a
399b39e
0ce2119
f9dd612
2a18699
e60ef94
f1551e8
e0ad45e
46a21f7
994708e
5527bfd
3c9f493
5fbbbc8
eb6f73c
0f757d2
f099a79
5837a20
989b3ed
0310bb8
8ed6f9a
9b573bf
106b79b
87142dc
8f34c13
28007d4
c218e42
4c9111a
97b7a26
9c16465
3f5e137
84369ed
5892437
655dc85
20e6942
aa8eecb
f3bf019
b7125bc
cc22fbc
a0099d4
95bc23d
fafc95b
a2d7b6e
76c2cab
6b0f2c6
5bd1817
c394ad7
0434ded
ce3d0fa
02ec9af
1201857
feb38b6
857fb1f
1aebecd
58419f0
0b40f6f
7999c2b
9f29d39
ab77c09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
Prism.languages.elisp = (function() { | ||
// Patterns in regular expressions | ||
|
||
// 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]+' | ||
// symbol starting with & used in function arguments | ||
const marker = '&' + symbol | ||
// Open parenthesis for look-behind | ||
const par = '(\\()' | ||
const endpar = '(?=\\))' | ||
// End the pattern with look-ahead space | ||
const space = '(?=\\s)' | ||
|
||
// Functions to construct regular expressions | ||
// simple form | ||
// e.g. (interactive ... or (interactive) | ||
const simple_form = name => new RegExp(`(\\()${name}(?=[\\s\\)])`) | ||
// booleans and numbers | ||
const primitive = pattern => new RegExp(`([\\s\\(\\[])${pattern}(?=[\\s\\)])`) | ||
|
||
var language = { | ||
// Three or four semicolons are considered a heading. | ||
// See https://www.gnu.org/software/emacs/manual/html_node/elisp/Comment-Tips.html | ||
heading: { | ||
pattern: /;;;.*/, | ||
alias: ['comment', 'title'], | ||
}, | ||
comment: /;.*/, | ||
string: { | ||
pattern: /"(?:[^"\\]*|\\.)*"/, | ||
greedy: true, | ||
inside: { | ||
argument: /[-A-Z]+(?=[.,\s])/, | ||
symbol: new RegExp('`' + symbol + "'"), | ||
}, | ||
}, | ||
'quoted-symbol': { | ||
pattern: new RegExp("#?'" + symbol), | ||
alias: ['variable', 'symbol'], | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove all trailing commas in the file. |
||
'lisp-property': { | ||
pattern: new RegExp(':' + symbol), | ||
alias: 'property', | ||
}, | ||
splice: { | ||
pattern: new RegExp(',@?' + symbol), | ||
alias: ['symbol', 'variable'], | ||
}, | ||
keyword: [ | ||
{ | ||
pattern: new RegExp( | ||
par + | ||
'(?:(?:lexical-)?let\\*?|(?:cl-)?letf|if|when|while|unless|cons|cl-loop|and|or|not|cond|setq|error|message|null|require|provide|use-package)' + | ||
space | ||
), | ||
lookbehind: true, | ||
}, | ||
{ | ||
pattern: new RegExp( | ||
par + '(?:for|do|collect|return|finally|append|concat|in|by)' + space | ||
), | ||
lookbehind: true, | ||
}, | ||
], | ||
declare: { | ||
pattern: simple_form('declare'), | ||
lookbehind: true, | ||
alias: 'keyword', | ||
}, | ||
interactive: { | ||
pattern: simple_form('interactive'), | ||
lookbehind: true, | ||
alias: 'keyword', | ||
}, | ||
boolean: { | ||
pattern: primitive('(?:t|nil)'), | ||
lookbehind: true, | ||
}, | ||
number: [ | ||
{ | ||
pattern: primitive('[-+]?\\d+(?:\\.\\d*)?'), | ||
lookbehind: true, | ||
}, | ||
], | ||
defvar: { | ||
pattern: new RegExp(par + 'def(?:var|const|custom|group)\\s+' + symbol), | ||
lookbehind: true, | ||
inside: { | ||
keyword: /def[a-z]+/, | ||
variable: new RegExp(symbol), | ||
}, | ||
}, | ||
defun: { | ||
pattern: new RegExp( | ||
par + `(?:cl-)?(?:defun\\*?|defmacro)\\s+${symbol}\\s+\\([\\s\\S]*\\)` | ||
), | ||
lookbehind: true, | ||
inside: { | ||
keyword: /(?:cl-)?def\S+/, | ||
arguments: null, | ||
function: { | ||
pattern: new RegExp('(^\\s)' + symbol), | ||
lookbehind: true, | ||
}, | ||
punctuation: /[()]/, | ||
}, | ||
}, | ||
lambda: { | ||
pattern: new RegExp(par + `lambda\\s+\\((?:&?${symbol}\\s*)*\\)`), | ||
lookbehind: true, | ||
inside: { | ||
keyword: /lambda/, | ||
arguments: null, | ||
punctuation: /[()]/, | ||
}, | ||
}, | ||
car: { | ||
pattern: new RegExp(par + symbol), | ||
lookbehind: true, | ||
}, | ||
punctuation: [ | ||
// open paren | ||
/['`,]?\(/, | ||
// brackets and close paren | ||
/[)\[\]]/, | ||
// cons | ||
{ | ||
pattern: /(\s)\.(?=\s)/, | ||
lookbehind: true, | ||
}, | ||
], | ||
} | ||
|
||
const arg = { | ||
'lisp-marker': new RegExp(marker), | ||
rest: { | ||
argument: { | ||
pattern: new RegExp(symbol), | ||
alias: 'variable', | ||
}, | ||
varform: { | ||
pattern: new RegExp(par + symbol + '\\s+\\S[\\s\\S]*' + endpar), | ||
lookbehind: true, | ||
inside: { | ||
string: language.string, | ||
boolean: language.boolean, | ||
number: language.number, | ||
symbol: language.symbol, | ||
punctuation: /[()]/, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const forms = '\\S+(?:\\s+\\S+)*' | ||
|
||
const arglist = { | ||
pattern: new RegExp(par + '[\\s\\S]*' + endpar), | ||
lookbehind: true, | ||
inside: { | ||
'rest-vars': { | ||
pattern: new RegExp('&(?:rest|body)\\s+' + forms), | ||
inside: arg, | ||
}, | ||
'other-marker-vars': { | ||
pattern: new RegExp('&(?:optional|aux)\\s+' + forms), | ||
inside: arg, | ||
}, | ||
keys: { | ||
pattern: new RegExp('&key\\s+' + forms + '(?:\\s+&allow-other-keys)?'), | ||
inside: arg, | ||
}, | ||
argument: { | ||
pattern: new RegExp(symbol), | ||
alias: 'variable', | ||
}, | ||
punctuation: /[()]/, | ||
}, | ||
} | ||
|
||
language['lambda'].inside.arguments = arglist | ||
language['defun'].inside.arguments = Prism.util.clone(arglist) | ||
language['defun'].inside.arguments.inside.sublist = arglist | ||
|
||
return language | ||
})() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
;; h1 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", ";; h1"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
;;; h1 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["heading", ";;; h1"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for headings. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"" | ||
"foo\ | ||
bar" | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", ["\"\""]], | ||
["string", "\"foo\\\r\nbar\""] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This leads to a failure which I don't understand
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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) |
||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for all keywords. |
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.