getting an error with ack trying to associate a file to javascript - ack

in my ~/.ackrc I have this line:
--type-add=javascript=.pkg
Now when I try to run ack foo I get an error:
$ ack foo
ack: --type-add: Type "javascript" does not exist, creating with ".pkg" ...
What does this mean? and how do I fix it.

--type-add means "Add .pkg to the list of known javascript extensions". The "add" here refers to the extension, not the type. You have the warning because there is no type called "javascript".
If you want to create a new file type called "javascript" then use --type-set=javascript=.pkg.
If you want to add .pkg to the list of extensions recognized by the existing js type, use --type-add=js=.pkg.

It needs to be 'js' not 'javascript' no wonder i couldn't find it anywhere in their docs:
--type-add=js=.pkg

Your problem is that --type-add is for extending existing types; in order to create a new type, you have to use --type-set, like so:
--type-set=javascript=.pkg

Related

Programmatically add key mappings in Atom

I'm creating several commands programmatically and want to avoid having to add key mappings for them explicitly in keymap.cson.
The Flight Manual page for Keymap Manager shows an add method. It doesn't give an example of how to actually use this method, so my guess is that this should work:
atom.keymaps.add('atom-text-editor',{'alt-1':'custom:my-command'});
However, this does not appear to work. When I run this in the developer console, I get this message:
Encountered an invalid key binding when adding key bindings from 'atom-text-editor' 'custom:my-command'.
I got this message even if I changed alt to ctrl.
What does the correct method call on atom.keymaps look like.
I agree, the docs are not detailed enough. However, through trial and error, I managed to figure it out:
atom.keymaps.add('foo', {
'atom-text-editor' : {
'alt-1': 'custom:my-command',
'#': 'application:about'
// etc
}
});
Explanation:
atom.keymaps.add(source, bindings, priority);
The source argument is not the same as what is referred to as the selector in Atom speak. Instead, it's an identifier that can be used to remove the keybindings, should you wish to (except it seems they haven't actually implemented a remove method!).
Instead, the selector should go inside the bindings argument, as shown above.

Custom Environment Variables Documentation

Why is this documentation :
https://symfony.com/doc/current/configuration/external_parameters.html#custom-environment-variable-processors
suggesting to use a tag (container.env_var_processor) that does not exist in :
https://symfony.com/doc/current/reference/dic_tags.html
When documenting the env var processors in https://github.com/symfony/symfony-docs/pull/10553, it was simply forgotten to add the tag to the reference. Would you like to send a pull request to add it there?

Set default language for new files

Newly created files in Atom are always "Plain Text". How can I change this so that new files will automatically be in another language, for example "Shell Script (Bash)"? I want to do this because auto indentation does not work with Plain Text files.
Had this problem as well, there is a plugin called default-language that will do this for you.
Search atom for default-language, install and open its settings. Type the name of the language you want Atom to default to, e.g. Shell Script (if in doubt, copy from the language selection menu) in the Default Language field. Next time you open a script with no extension (or shebang) it'll default to the language you set.
The following code, added to your init.coffee, will do what you're asking:
atom.workspace.observeTextEditors (editor) ->
default_scope = 'source.shell'
original = editor.getGrammar()
# If the editor has "null" grammar (aka unset)
if original? and original is atom.grammars.grammarForScopeName('text.plain.null-grammar')
default_grammar = atom.grammars.grammarForScopeName(default_scope)
if default_grammar? # check if desired grammar is already loaded
editor.setGrammar(default_grammar)
else
# grammar was not loaded yet, so add a callback as grammars load
callback = atom.grammars.onDidAddGrammar (grammar) ->
if grammar.id is default_scope
# once we've loaded the grammar, set it and dispose of the callback
editor.setGrammar(grammar)
callback.dispose()
Things to note:
The init.coffee file is where you can customize Atom without having to write a package
The observeTextEditors method sets a callback that is called upon each TextEditor creation for currently open and future editors
The code above:
Checks the grammar that the editor was created with
If and only if it is the default ("null") grammar, it sets the editor's grammar to the Shell grammar once it's loaded
Disposes of the callback to check for grammar loading once it's done with it
This should solve the TypeError: Cannot call method 'getScore' of undefined that happens for the first file opened in a new window.
To default to a different grammar, just change the default_scope = 'source.shell' line to use the scope of whatever grammar you'd like.
Firstly, CTRL+SHIFT+L is your friend. It's unfortunately not a permanent solution, but nice to know about.
Of course, we'd prefer a more permanent solution. A couple of the other answers are now obsolete due to API changes in Atom. Below is a more up-to-date version. Inspiration initially came from this discussion, but the other answers here seem to follow the same concept as well.
Place this in your init.coffee file (File -> Open Your Init Script):
extname = require("path").extname
fileTypes =
".wxs": "text.xml"
".wxi": "text.xml"
".wixobj": "text.xml"
nullGrammar = atom.grammars.selectGrammar("text.plain.null-grammar")
atom.workspace.observeTextEditors (editor) ->
grammar = atom.grammars.selectGrammar(fileTypes[extname(editor.getPath())])
editor.setGrammar grammar if editor.getGrammar() is nullGrammar and grammar isnt nullGrammar
Basically, you define have an array of file types, and the grammars (AKA syntax highlighting) that you want to associate them with. Find each editor, find out if it has a selected grammar already, and if not, attempt to give it one if we find one.
The one issue I've had with this is that the syntax highlighting only works if you open files after you've already launched Atom; if you open a file that results in Atom launching (say by double clicking on it's icon in your favourite OS), syntax highlighting won't for that file until you re-open it.
You need to create a mapping in your config.cson file.
"*":
core:
customFileTypes:
"source.shell": [
"sh"
"shell"
]
For mapping .sh and .shell files to shell script syntax.
Have a look at this bit of code: (you can can then change 'text.html.basic' to whichever syntax you require)
editor = atom.workspace.getActiveTextEditor()
cursor = editor.getLastCursor()
valueAtCursor = atom.config.get(cursor.getScopeDescriptor(), 'my-package.my-setting')
valueForLanguage = atom.config.get(editor.getRootScopeDescriptor('text.html.basic'), 'my-package.my-setting')
For reference please see: Scope Descriptors # https://atom.io/docs/latest/advanced/scopes-and-scope-descriptors

How can I ask the state for a content object?

At the end of this tutorial several object attributes are listed. But I need access to the state (published, private,...). I also search that attribute using dir() but I don't see an attribute named as state or something similar. i.e, I need something like this:
>>> app.Plone.foo.bar.state
"published"
Or to keep your code more readable and not having to remember strange method names, you can use plone.api to do this:
from plone import api
api.content.get_state(obj=your_object)
Of course, you need to add plone.api to your eggs first, and re-run buildout.
You can always use the plone_workflow to determine current status:
workflowTool = getToolByName(self.portal, "portal_workflow")
status = workflowTool.getStatusOf("plone_workflow", object)
# where "object" is your content object
print (status)
Unfortunately there is no "state" attribute. Instead, check review_state using the workflow tool e.g.:
>>> app.Plone.portal_workflow.getInfoFor(app.Plone.foo.bar, "review_state")

Custom grunt.helper values possible?

I am working on my own boilerplate using grunt's CLI possibilities like so grunt init:webdesign-project - for this I created a folder named webdesign-project within node_modules/grunt/init and a corresponding webdesign-project.js file. So far everything works great.
Now I wanted to insert my own "questions" with the grunt.helper function like this
grunt.helper('prompt_for', 'img_path', 'img')
however this gives me
TypeError: Cannot set property 'name' of undefined
at Object.module.exports.grunt.registerHelper.grunt.utils.spawn.cmd (/usr/lib/node_modules/grunt/tasks/init.js:573:17)
at Task.helper (/usr/lib/node_modules/grunt/lib/util/task.js:117:19)
at Object.exports.template (/usr/lib/node_modules/grunt/tasks/init/webdesign-project.js:30:11)
at Object.module.exports.grunt.registerHelper.done (/usr/lib/node_modules/grunt/tasks/init.js:240:27)
at Object.task.registerTask.thisTask.fn (/usr/lib/node_modules/grunt/lib/grunt/task.js:58:16)
at Task.<anonymous> (/usr/lib/node_modules/grunt/lib/util/task.js:341:36)
at Task.start (/usr/lib/node_modules/grunt/lib/util/task.js:357:5)
at Object.grunt.tasks (/usr/lib/node_modules/grunt/lib/grunt.js:143:8)
at Object.module.exports [as cli] (/usr/lib/node_modules/grunt/lib/grunt/cli.js:36:9)
at Object.<anonymous> (/usr/lib/node_modules/grunt/bin/grunt:19:14)
Isn't it possible to define your own variables using this function?
EDIT: Does anybody know if a documentation for this function exists? (Couldn't find one yet)
You shouldn't modify or add files within the node_modules/ folder as they will be overwritten upon updating with npm. Take a look at the init docs for creating custom init templates: https://github.com/gruntjs/grunt/blob/master/docs/task_init.md#creating-custom-templates
I recommend copying one of the existing init templates to: ~/.grunt/tasks/init/webdesign-project.js and modify from there.
I figured out how to achieve the "custom prompt" - in case anybody is interested:
Grunt's grunt.helper('prompt_for', '...') function apparently only takes a predefined set of values in lieu of '...'. Actually this should not be surprising, as there are some pretty unique features for some of those values (e.g. when you've entered testproject as your project's name, "(git://github.com/peter/testproject.git)" will automatically be proposed.
Solution: Take a look at the .js file of the gruntfile template (node_modules/grunt/tasks/init/gruntfile.js) - creating a custom prompt goes like this:
{
name: 'img_path',
message: 'Name the folder where all image files are located',
default: 'img',
// warning: '' couldn't find any use for this optional property
}
instead of
grunt.helper('prompt_for', 'img_path', 'img')

Resources