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

add emacs #1297

Merged
merged 68 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
309d971
add emacs
JuanCaicedo Feb 16, 2018
2aee520
rename to elisp
JuanCaicedo Feb 17, 2018
5d3693b
add elisp to components
JuanCaicedo Feb 17, 2018
1c7021c
add comment test
JuanCaicedo Feb 17, 2018
4c96cab
add heading test
JuanCaicedo Feb 17, 2018
68cd7b1
WIP string test
JuanCaicedo Feb 17, 2018
1c45ad7
update string tests
JuanCaicedo Feb 17, 2018
3fdd5a3
test symbols in strings
JuanCaicedo Feb 17, 2018
e785a09
test arguments
JuanCaicedo Feb 17, 2018
52a01d2
test quoted symbol
JuanCaicedo Feb 20, 2018
83ba77a
lisp-property test
JuanCaicedo Feb 20, 2018
399b39e
splice test
JuanCaicedo Feb 20, 2018
0ce2119
add keyword test
JuanCaicedo Feb 20, 2018
f9dd612
test for declare
JuanCaicedo Feb 20, 2018
2a18699
test interactive
JuanCaicedo Feb 20, 2018
e60ef94
boolean test
JuanCaicedo Feb 20, 2018
f1551e8
test numbers
JuanCaicedo Feb 20, 2018
e0ad45e
test defvar
JuanCaicedo Feb 20, 2018
46a21f7
fix greedy defun regex
JuanCaicedo Feb 20, 2018
994708e
test defun
JuanCaicedo Feb 26, 2018
5527bfd
test lambda
JuanCaicedo Feb 26, 2018
3c9f493
test car
JuanCaicedo Feb 26, 2018
5fbbbc8
test punctuation
JuanCaicedo Feb 26, 2018
eb6f73c
use var instead of const
JuanCaicedo Feb 26, 2018
0f757d2
remove arrow functions
JuanCaicedo Feb 26, 2018
f099a79
flatten language structure
JuanCaicedo Feb 26, 2018
5837a20
remove unnecessary escaping
JuanCaicedo Feb 26, 2018
989b3ed
add lisp and emacs
JuanCaicedo Feb 26, 2018
0310bb8
add lisp
JuanCaicedo Feb 26, 2018
8ed6f9a
fix template strings
JuanCaicedo Feb 26, 2018
9b573bf
minify lisp
JuanCaicedo Feb 26, 2018
106b79b
add example elisp file
JuanCaicedo Feb 27, 2018
87142dc
simplify number
JuanCaicedo Feb 27, 2018
8f34c13
don't mark other def as keywords
JuanCaicedo Feb 27, 2018
28007d4
dont mark other def as keyword in defun
JuanCaicedo Feb 27, 2018
c218e42
make lambda a keyword only at the beginning
JuanCaicedo Feb 27, 2018
4c9111a
restore single quotes in components
JuanCaicedo Feb 27, 2018
97b7a26
double quote in elisp
JuanCaicedo Feb 27, 2018
9c16465
minify elisp
JuanCaicedo Feb 27, 2018
3f5e137
quote keys in components
JuanCaicedo Feb 27, 2018
84369ed
rename punctuation test
JuanCaicedo Feb 27, 2018
5892437
add semicolons elisp
JuanCaicedo Apr 5, 2018
655dc85
undo prettier changes to components.js
JuanCaicedo Apr 5, 2018
20e6942
Merge remote-tracking branch 'upstream/master' into add-emacs
JuanCaicedo Apr 5, 2018
aa8eecb
add lisp to components.json
JuanCaicedo Apr 5, 2018
f3bf019
rename elisp to lisp
JuanCaicedo Apr 5, 2018
b7125bc
fix components.json
JuanCaicedo Apr 5, 2018
cc22fbc
add minified lisp file
JuanCaicedo Apr 5, 2018
a0099d4
rename example lisp file
JuanCaicedo Apr 5, 2018
95bc23d
move lisp to first position
JuanCaicedo Apr 5, 2018
fafc95b
explain null initialized properties in lisp file
JuanCaicedo Apr 5, 2018
a2d7b6e
remove trailing commas
JuanCaicedo Apr 5, 2018
76c2cab
put lisp first in example file
JuanCaicedo Apr 5, 2018
6b0f2c6
add ifee for lisp file
JuanCaicedo Apr 5, 2018
5bd1817
update lisp min file
JuanCaicedo Apr 5, 2018
c394ad7
update show language assets
JuanCaicedo Apr 5, 2018
0434ded
add components index min file
JuanCaicedo Apr 5, 2018
ce3d0fa
add emacs-lisp alias
JuanCaicedo Apr 5, 2018
02ec9af
change title of lisp example file
JuanCaicedo Apr 5, 2018
1201857
undo theme change
JuanCaicedo Apr 5, 2018
feb38b6
Merge remote-tracking branch 'upstream/gh-pages' into add-emacs
JuanCaicedo Apr 5, 2018
857fb1f
combine regex for parens
JuanCaicedo Apr 5, 2018
1aebecd
remove min index
JuanCaicedo Apr 5, 2018
58419f0
remove unneeded example html
JuanCaicedo Apr 5, 2018
0b40f6f
remove doubled string test
JuanCaicedo Apr 5, 2018
7999c2b
capitalize lisp in components
JuanCaicedo Apr 5, 2018
9f29d39
change string theme to match master
JuanCaicedo Apr 5, 2018
ab77c09
build assets after adding lisp
JuanCaicedo Apr 5, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ var components = {
"title": "Eiffel",
"owner": "Conaclos"
},
"elisp": {
"title": "Elisp",
"owner": "JuanCaicedo"
Copy link
Contributor Author

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 😀

Copy link

@akirak akirak Feb 17, 2018

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.

Copy link
Contributor

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.

},
"elixir": {
"title": "Elixir",
"owner": "Golmote"
Expand Down
187 changes: 187 additions & 0 deletions components/prism-elisp.js
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'],
},
Copy link
Contributor

Choose a reason for hiding this comment

The 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
})()
1 change: 1 addition & 0 deletions components/prism-elisp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/languages/elisp/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;; h1

----------------------------------------------------

[
["comment", ";; h1"]
]

----------------------------------------------------

Checks for comments.
11 changes: 11 additions & 0 deletions tests/languages/elisp/heading_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;;; h1

----------------------------------------------------

[
["heading", ";;; h1"]
]

----------------------------------------------------

Checks for headings.
14 changes: 14 additions & 0 deletions tests/languages/elisp/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
""
"foo\
bar"

----------------------------------------------------

[
["string", ["\"\""]],
["string", "\"foo\\\r\nbar\""]
Copy link
Contributor Author

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\""]]
-----------------------------------------

Copy link
Contributor Author

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

Copy link
Contributor Author

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"
)

Copy link
Contributor

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)

]

----------------------------------------------------

Checks for all keywords.