I am using emacs (js2-mode) for coding javaScript. Here is a simple code snippet where emacs always shows me a syntax error:
<script>
var x = function (a, b)
{
return a * b;
};
</script>
The "{" and "return a" are always colored in red, can somebody tell me why? Has anyone worked with js2-mode so far?
I think the problem arises from the script tags you have in the code, as there shouldn't be any HTML in a JavaScript file, hence the syntax errors.
Related
I really would like to knit my R codes in a Word file, and I have knitted codes a few hours ago; however, it suddenly don't work. :(
I looked up some answers in this site, and tried some solutions, but it didn't work.
First, I restored Rcpp, but it didn't change anything.
Second, I used rs.restartR, but it also didn't work.
Third, I tried to find a solution at https://yihui.name/knitr/options, but I still don't have an idea. ;-(
My error messages on R Markdown are shown as below.
processing file: my_data.rmd
(*) NOTE: I saw chunk options "1st paragraph, eval=FALSE"
please go to https://yihui.name/knitr/options
(it is likely that you forgot to quote "character" options)
Error in parse(text = cpde. keep.source = FALSE) :
<text>:1:14: unpredictable symbol
1. alist('
Calls: <Anonymous> ... parse_params -> withCallingHandlers -> eval -> parse_only -> parse
What happens to my R studio? (T_T)
Dose anyone who can solve my problem? Thank you so much.
First of all, you should give a reproducible example, i.e. the source code of your my_data.rmd file.
I guess you should use "1st paragraph" rather than "1st paragraph".
That is to say,
```{r some.option=1st paragraph, eval=FALSE}
#some r code here
```
should be
```{r some.option="1st-paragraph", eval=FALSE}
#some r code here
```
I need to include HTML code in LaTeX and I'm using the listings package for that.
The problem is that if there is a $ character in my HTML code the color of the word after $ is broken in Emacs. To get the correct color I need to use another $.
For example:
\begin{lstlisting}
var mapElement = $("#map")[0];
var mapOptions = {
center: new google.maps.LatLng(43.720741,10.408413),
zoom: 10
};
\end{lstlisting}
After the $ character the text in the rest of the document isn't highlighted correctly.
I'm not using AUCTeX but the default latex-mode of Emacs.
Any ideas?
I had the same problem and found a nice work around at http://www.latex-community.org/forum/viewtopic.php?f=31&t=25036
Use the following to output a $ each time you type 4> in the Latex code:
\lstset{
literate={4>}{\$}1
}
then put your listing code in as normal
\begin{lstlisting}
ruby -e "4>(curl -fsSL\ https://raw.github.com/Homebrew/homebrew/go/install)"
\end{lstlisting}
which will work around highlighting issues and AucTeX will still look nice and pretty! (:
As I was playing around for the first time with CoffeeScript, I ran in to a problem. In order to debug my problem, I tried replacing my whole file with one of the example bits of code from the coffee script site:
kids =
brother:
name: "Max"
age: 11
sister:
name: "Ida"
age: 9
However, when I try to compile that code, I get:
Error: In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'
at Object.parseError (/usr/lib/coffeescript/parser.js:501:11)
at Object.parse (/usr/lib/coffeescript/parser.js:573:32)
at Object.compile (/usr/lib/coffeescript/coffee-script.js:23:22)
at /usr/lib/coffeescript/command.js:99:27
at /usr/lib/coffeescript/command.js:72:28
at fs:84:13
at node.js:773:9
In coffee/main.coffee, Parse error on line 3: Unexpected 'INDENT'
Since this is code from the CoffeeScript site, I assume the code itself isn't the problem. However, the compiler also seems to be working properly; if I compile:
a = 2
it generates a file with:
(function(){
var a;
a = 2;
})();
as expected. So in other words, the code is good, the compiler is good, and yet somehow I'm getting this Unexpected 'IDENT' error ... can anyone help me understand what is going on?
I am pretty sure this is a tabs-vs-spaces issue. Tell your editor not to convert spaces to tabs if it does that. Also, go through your code with the cursor and make sure it doesn't jump over blank areas.
The issue is that while normal editors see a tab as equivalent to two or four spaces, coffeescript sees it as one space, so the indentation gets messed up.
If this all doesn't help, make sure you have a recent coffeescript version, e.g. 1.1.0 or newer.
If you are using a JetBrains IDE (IntelliJ, PHPStorm, etc) the change of setting that worked for me is:
File > Settings > Project Settings > Code Style > CoffeeScript > Tabs
and Indents
Tick "Use tab character" & "Smart tabs"
Code is fine. Make sure you haven't messed up the whitespace (strange control chars showing as blanks, tabs or similar).
If you have the same problem, but your indentation is okay,
then you must be suffering from bug 2868.
Basically, the error is misleading. Check for indentation
errors in the required files.
When in Atom you can automatically convert tabs to spaces:
Packages > Whitespace > Convert Tabs to Spaces
You can resolve this two ways
1. IF using webstorm File->Default Settings as said above
2. Other workaround, is to use a different editor like Sublime, there u can press enter on earlier line and it will auto tab it for you with spaces
I like the idea behind JSLINT but sometimes it is a little too strict, in my opinion needlessly so.
Recently I found JSHINT. It's a little more flexible, allows more options to be turned on or off.
But JSHINT is throwing an error on code that I think looks right. For example, JSHINT barfs on its own code. If I run JSHINT on JSHINT.js, it gives me this:
I don't understand that. See the error message near the bottom of that image? JSHINT seems to want the indentation to be different than it is. It's not complaining about the lack of the curly. I have curly:false which says to not require curlies around one-liner if statements.
The odd thing is, JSHINT.js source code uses a 4-space indent everywhere, but it throws errors about the indent only for these few lines. Why?
Am I doing this wrong? Is there something else I should be configuring?
EDITED - originally I had been playing around with JSHINT, and I put the combine() call on the same line as the if statement. I've reverted the JSHINT code back to what it was originally, to show that the errors remain.
This is done with JSHINT using these options:
options = {
curly : false, // no curly fascism
wsh : true, // WScript is allowed
white : true, // true: 'sloppy' whitespace is ok
plusplus : false, // false == ok to use ++
passfail : false // do not stop after first error
//radix : true // do not puke on parseInt() with no radix
};
EDIT2
Here's a gif that shows what JSHINT, in its original form, really wants. When the red highlights disappear, it means JSHINT is happy for that particular line. (This is using flymake-for-jslint in emacs).
As you can see, if I indent the line in an odd way, JSHINT relaxes.
Answer
I think the answer is in this github issue. I modified JSHINT, line 2264, like this:
***************
*** 2256,2262 ****
--- 2261,2270 ----
nexttoken, '{', nexttoken.value);
noreach = true;
+ // cheeso - fix for https://github.com/jshint/jshint/issues/87
+ indent += option.indent;
a = [statement()];
+ indent = old_indent;
noreach = false;
}
...and it stopped complaining about its own formatting.
JSHint maintainer here. Based on your screenshot, it errors because the combine is on the same line as your if clause which is against white option's rules.
Are you sure that your copy of JSHint was not modified by anybody? We have unit tests for JSHint and one of the tests checks JSHint's own source code with itself. And, as you can see from the attached example, everything passes just fine.
I think the answer is in [this github issue][4]. I modified JSHINT, line 2264, like this:
***************
*** 2256,2262 ****
--- 2261,2270 ----
nexttoken, '{', nexttoken.value);
noreach = true;
+ // cheeso - fix for https://github.com/jshint/jshint/issues/87
+ indent += option.indent;
a = [statement()];
+ indent = old_indent;
noreach = false;
}
...and it stopped complaining about its own formatting.
Emacs doesn't properly indent C++ class definitions for allocators that have initializers with colons in them. I think that this is because lines with colons are left-indented in many cases.
I would like to fix this.
Here is an example of what I am talking about.
EMACS indents the code like this:
class demo {
int x;
demo(){
}
demo(int y):x(y){
};
};
But it should really indent it like this:
class demo {
int x;
demo(){
}
demo(int y):x(y){
};
};
Is there a way to fix this behavior? Presumably we need some elisp...
Thanks!
Emacs (at least version 23) doesn't do this in C mode, but it does in C++ mode since in C the part before the colon can only be a label. Make sure you're in C++ mode (M-x c++-mode).