Atom-Editor: Failed to load init.coffee - ERROR: reserved word 'function' - coffeescript

UPDATE: I found a solution/workaround for the problem. I renamed init.coffee to init.js because Atom also supports JavaScript. I would still like to know the cause of the problem. Is the script below not valid CoffeeScript or am I missing some dependence? I Installed Atom from the official Arch repositories.
For some reason my init.coffee cannot be loaded. The following code is from Atom's "Composed" Commands documentation:
atom.commands.add('atom-text-editor', 'custom:cut-line', function () {
const editor = this.getModel();
editor.selectLinesContainingCursors();
editor.cutSelectedText();
});
Atom throws an error when it starts:
Failed to load /home/myname/.atom/init.coffee
reserved word 'function'
I'm not sure if this is a bug, my fault, or a result of out-of-date documentation. The error message isn't super helpful, since I already that "function" is a reserved word, even though I don't know a lot of Coffee/JavaScript.
I replaced function using () -> {...}, which resulted in the same error except this time for the reserved word const.
Finally, I tried defining a named function which I passed as an argument to atom.commands.add() and got the same error.
I'm on Linux. atom --version returns:
Atom : 1.46.0
Electron: 4.2.12
Chrome : 69.0.3497.128
Node : 10.11.0

Your solution is the right direction - that code is JavaScript, not CoffeeScript.
It looks like the '"Composed" Commands' documentation you referenced is using both JavaScript and CoffeeScript in their examples.
To convert from JavaScript:
atom.commands.add('atom-text-editor', 'custom:cut-line', function () {
const editor = this.getModel();
editor.selectLinesContainingCursors();
editor.cutSelectedText();
});
to CoffeeScript:
atom.commands.add 'atom-text-editor', 'custom:cut-line', () ->
editor = #getModel()
editor.selectLinesContainingCursors()
editor.cutSelectedText()
When calling a function with arguments, you can leave out the parenthesis ().
function is removed in CoffeeScript, just use parenthesis and either a single -> or double arrow =>, where a double arrow is the same as .bind(this), so that would be incorrect here.
No const/let/var keywords. Just defined the variable without them.
this. can be replaced with #.
Braces ({}) wrapping function definitions are optional.
No semicolons.
If you want to learn CoffeeScript and help the community, you could fix the documentation yourself by forking, editing and making a pull request of the repository.
Alternatively, you should report this error in the documentations in their repository as an issue.

Related

How to replace deprecated SOBE Code in TYPO3 10.4

I inherited an old TYPO3 Extension using SOBE. As far as I unterstand it's deprecated, but it seems there is no documentation on how to replace it.
The Extension is using Backend Forms and the following line is throwing an error:
if (is_array($GLOBALS['SOBE']->editconf['tt_content']) && reset($GLOBALS['SOBE']->editconf['tt_content']) === 'new') {
The error is:
Cannot access protected property TYPO3\CMS\Backend\Controller\EditDocumentController::$editconf
The Var $GLOBALS['SOBE'] is still there, and there is also editconf, but it's not working.
How can I replace this code or rewrite it?
The SOBE object is part by part removed since years. As there are multiple ways for using it - see https://docs.typo3.org/c/typo3/cms-core/main/en-us/search.html?q=sobe&check_keywords=yes&area=default - you may need to take a closer look what is the exact part of replacing this code.
I would guess you can see more at https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.2/Deprecation-84195-ProtectedMethodsAndPropertiesInEditDocumentController.html?highlight=editconf.

org_scalajs_dom_raw_HTMLDocument(...).createRange is not a function

I'm upgrading scalatags from 0.6.7 to 0.9.3 as part of upgrading scalaJS from 0.6.x to 1.4.0.
I got the following error in some of my tests:
scala.scalajs.js.JavaScriptException: TypeError: $m_Lorg_scalajs_dom_package$(...).document__Lorg_scalajs_dom_raw_HTMLDocument(...).createRange is not a function
Tracing the code, I believe it occurs while executing line 141 of the following scalatags code in `scalatags.JsDom:
I extracted just the createRange call into a separate test and got the same error. "creating range" was printed; "created range" was not and it produced the same exception as above.
createRange() is a native function.
Googling "createRange is not a function" yields a number of similar issues, all seem to be related to testing (but not with ScalaJS). Many of them indicate the "fix" is to monkey-patch document with your own version of createRange. Really?
I initially thought this was an issue with scalatags. Then I thought it's with the scalajs library. Now I'm thinking it's something with Node.js, although Google is not producing any smoking guns.
Suggestions on how to proceed? Try to monkey patch document?
Summary: jsdom appears to be missing the document.createRange function when using Node.js for testing. Others in other languages have similar problems.
The following monkey patch worked for me. After developing this, I noticed that Facade Types has a section on monkey typing.
Also, the library code that tickled this bug (scalatags) actually calls document.createRange().createContextualFragment(v). So I needed to provide something for that as well.
import scala.scalajs.js
import org.scalajs.dom.document
js.Dynamic.global.document.createRange = () ⇒
js.Dynamic.literal(
setStart = () => js.Dynamic.literal(),
setEnd = () => js.Dynamic.literal(),
commonAncestorContainer = js.Dynamic.literal(
nodeName = "BODY",
ownerDocument = document
),
createContextualFragment = (v: String) ⇒ {
val p = document.createElement("p")
p.appendChild(document.createTextNode(v))
}
)

How to clear method call parameters/arguments filled by SublimeText Jedi-autocomplete?

I am testing out SublimeText auto-complete using JEDI package and one problem I am having is unrequired parameters are auto-filling function/method calls:
For example in Flask:
I can just call the function as such:
app.run(),
but JEDI-Autocomplete is doing something like this:
app.run(host= , port=..., debug=..., load_dotenv=...)
I can't figure out how to clear the parameters as it's not needed in this case.
Same problem with:
app = Flask(__name__)
Instead autocomplete is automatically filling in unrequired parameters and seemingly forcing me to add value to each argument.
Searching the Sublime Text 3's SublimeJEDI repo (issue #290 - open() autocompletes all args when in required mode) seems to suggests that there's an option to control autocomplete aggressiveness:
"auto_complete_function_params": "all",
In your preference settings (either user preferences or syntax preferences).
From their README.md:
Function parameters completion has 3 different behaviors:
Insert all function arguments on autocomplete:
# complete result
func(a, b, c, d=True, e=1, f=None)
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": "all"
}
Insert only required arguments that don't have default value (default behavior):
# complete result
func(a, b, c)
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": "required"
}
Do not insert any arguments:
# complete result
func()
# sublime_jedi.sublime-settings
{
"auto_complete_function_params": ""
}
More info about auto_complete_function_params
You may experiment with those options to see what fits you better.
Turning auto_complete off and using SublimeJedi: ShowDocstring (defaults to Ctrl+Alt+D) when the cursor is after the function name fixes the issue for me.
You can also hover over the function name or use SublimeJedi: Show Signature.

IPython/Jupyter Installing Extensions

I'm having troubles installing extensions in IPython. The problem is that i can't get the extensions load automatically, i have followed the instructions in the github page but it just doesn't work. According the the homepage i need to modify the custom.js file by adding some lines. I want to install the codefolding, hide_input_all and runtools extensions. This is how my custom.js file looks:
// activate extensions only after Notebook is initialized
require(["base/js/events"], function (events) {
$([IPython.events]).on("app_initialized.NotebookApp", function () {
/* load your extension here */
IPython.load_extensions('usability/codefolding/codefolding')
IPython.load_extensions('usability/runtools/runtools')
require(['/static/custom/hide_input_all.js'])
});
});
The extensions work well if i call them manually, for example, if i type
%%javascript
IPython.load_extensions('usability/runtools/runtools/main');
the runtools appear and works perfectly, but i want the extensions to be loaded automatically and not to have to call them manually every time. Could someone tell me where is my mistake?
There's been a little change to the syntax. Nowadays, $ might not be defined by the time your custom.js loads, so instead of something like
$([IPython.events]).on("app_initialized.NotebookApp", function () {
IPython.load_extensions("whatever");
});
you should do something like
require(['base/js/namespace', 'base/js/events'], function(IPython, events) {
events.on('app_initialized.NotebookApp', function(){
IPython.load_extensions("whatever");
})
});
with the appropriate changes to braces and parentheses. For me, the former will work more often than not, but certainly not always; it fails maybe ~1/3 of the time.
If that doesn't do it for you, open up Developer Tools (or whatever is relevant for your browser) and look at the javascript console for errors. That'll help figure out what's going wrong.

Eclipse JavaScript code formatter and JSHint anonymous function format conflict

I am using the Eclipse (version Indigo) JavaScript code formatter and using the jshint-eclipse plugin with white: true option for code convention validation.
Eclipse code formatter and JSHint plugin conflict with the anonymous function declaration format.
The JavaScript code formatter formats anonymous functions like the following:
var f1 = function() {
};
But the jshint-eclipse plugin gives a "Missing spaces after function" warning.
The right format for this plugin is:
var f1 = function () {
};
NOTE THE SPACE AFTER THE function
Is there a way to format anonymus function declaration differently with eclipse than regular function declarations. I would like to add one space after "function" for anonymous functions but not for normal functions.
Thanks.
Update a relevang eclipse bug is here
There is a bug for this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=315507
Similar bug in Aptana was fixed: http://jira.appcelerator.org/browse/APSTUD-3792
I've worked out a patch for this: https://github.com/eclipse/webtools.jsdt.core/pull/1
which hopefully will be merged and released soon.
Check the JavaScript formatting preferences (Preference->JavaScript->Code Style->Formatter) on the White Space tab, for the Declarations of Functions.