How to correctly combine "dot notation" and "braces notation" in cocoascript (sketch)? - cocoascript

In sketch documentation it's stated that dot and braces notations can be mixed with each other. It's even an example available:
[[context.document currentPage] deselectAllLayers];
Unfortunately, this code doesn't work in sketch and produce error if executed by "run custom script" command:
SyntaxError: Unexpected identifier 'currentPage'. Expected either a closing ']' or a ',' following an array element..
Plugin “untitled script”, line 2.
» [context.document currentPage]; «Error in command untitled script Script at path (null) does not contain a handler function named: onRun
Script executed in 0.023666s
This can be avoided by adding additional ( and ):
[[(context.document) currentPage] deselectAllLayers];
Why this happens? Is it any documentation available how exactly braces and dot notation can be mixed? Is it some error or expected behaviour?

It seems to me it's an error, but in Sketch documentation. Besides this case you showed, I couldn't find any other example where dot and braces notations are used together in the same statement, without parentheses.
The documentation page about Selections, for instance, tells that you'd use the following code to unselect everything:
var doc = context.document
[[doc currentPage] deselectAllLayers]
Follow this link and look under Clearing the selection header: http://bohemiancoding.com/sketch/support/developer/02-common-tasks/01.html
Even their example plugins don't mix both notations, as you can see here: https://github.com/BohemianCoding/ExampleSketchPlugins/blob/master/Hello%20World/Hello%20World.sketchplugin/Contents/Sketch/script.cocoascript.
In that example, context.document is also assigned to a new variable before being used within braces.

Related

What is the right parameter syntax for PyRAF biassec?

If I use epar ccdproc in imred >> ccdred >> ccdproc, I can put [261:280,1:1032] in biassec, which is in a old iraf code by my teacher:
ccdproc #list.all o//#list.all ccdtype='' overscan+ biassec=[261:280,1:1032]
But if I use the terminal, it will say:
SyntaxError: Too many positional parameters for task ccdproc
And if I put (261:280,1:1032), (261:280;1:1032) or (261:280 1:1032), it will also pop out SyntaxError. It seems that pyraf syntax is slightly different from iraf. What is the right parameter syntax?
Solved, "[261:280,1:1032]".
Add quotation marks
ccdproc #list.all o//#list.all ccdtype='' overscan+ biassec="[261:280,1:1032]"

ZSH avoid adding empty commands to history?

In zsh (with oh-my-zsh, is that matters) when I enter empty commands (e.g. just press enter) I see empty lines added to my ~/.zsh_history:
: 1508496422:0;ls
: 1508496422:0;vim
: 1508496482:0;
: 1508496482:0;
: 1508496482:0;
: 1508496482:0;
: 1508496490:0;
: 1508496490:0;
: 1508496490:0;
: 1508496490:0;
: 1508496494:0;ls
I'm wondering if it's possible to avoid adding these lines. I checked http://zsh.sourceforge.net/Doc/Release/Options.html but no luck. The reason why I'm trying to avoid adding empty lines is I'm using fzf and fzf lists these empty commands when I search in last commands in a directory.
If this is not possible in zsh side I'll try to search for a solution in fzf side.
There are a few Zsh settings to control what goes into your history
(though I'm surprised emtpies end up there; I can't reproduce that
despite also using fzf and hitting blank RETs a lot).
The man page for zshoptions(1) describes:
HIST_IGNORE_[ALL_]DUPS — This should at least reduce your
consecutive multiple empties down to one.
HIST_IGNORE_SPACE — Your empties might be treated as whitespace
and thus be eliminated. I like this feature anyway for intentionall
discarding commands by starting them with a space.
There is also the HISTORY_IGNORE option (not to be confused with
Bash's HISTIGNORE) — described in zshparam(1) with an example —
which lets you remove a set of patterns. An empty pattern may fix
your case. It also has a zshaddhistory hook that you could use to
more finely control exactly what goes into history.

ZSH - Oh My Zsh: modify PROMPT

I am trying to modify the PROMPT variable to include some additional information. My current PROMPT also includes git status on the right hand side. It looks like this:
ex2 ➤ git:master*
Screen shot of the same:
I would like to some text in front of the current folder-- like [Drone] for example. I am currently doing it as follows,
export PROMPT=%{"$fg[green] [Donre]"$fg[$NCOLOR]%}%c ➤ %{$reset_color%}
But this creates two issues.
1. The arrow character is not parsed correctly anymore and I get an error like
" not valid in this context: ➤"
2. The git status is pushed to the next line.
The new prompt appears as,
/home/arul/.zshrc:export:100: not valid in this context: ➤
[Drone]ex2 git:maste
r*
Screen shot of the same:
Could someone help me in modifying the PROMPT correctly?
%{...} does not escape any spaces contained therein; you should quote the entire value to ensure any enclosed whitespace is properly escaped for the assignment.
export PROMPT="%{$fg[green] [Donre]$fg[$NCOLOR]%}%c ➤ %{$reset_color%}"
As is, the arrow character is being treated as a separate argument (and an invalid parameter name at that) to the export command. export, by the way, is probably unnecessary. Each shell that needs the value of PROMPT is likely executing whatever configuration file contains this assignment.
Consider using zsh's own support for colors, so that you don't need %{...} at all.
PROMPT="%F{green} [Donre]%F{...}%c ➤ %f"
(where ... is whatever color $NCOLOR represents).

How to automatically enter brackets on autocomplete?

Whenever I use the autocomplete for atom it doesn't include the brackets. For example if i start typing "print" I hit enter and it enters print but doesn't include the brackets.
The default Python snippets only supports the print keyword, not the print() function. Since I haven't found another package that does, you're problably best off adding a snippet (Atom > Open Your Snippets) such as:
'.source.python':
'print()':
'prefix': 'print-function'
'body': 'print($1)'
The prefix will trigger the snippet defined in the body, in case prefer to call it differently.

Completing options of the form --<option>:<file> and --<option>:<possible values>

I'm trying to write a completion method for fsharpi (F# interactive), which has options like the following:
--use:<file> Use the given file on startup as initial input
--debug:{full|pdbonly} Specify debugging type: full, pdbonly. ('full' is the default and enables attaching a debugger to a running program).
--warn:<n> Set a warning level (0-5)
I'm guessing this has to be handled with $state similarly to sub-commands, but the documentation is monolithic and the language isn't very descriptive, so I've gotten nowhere with experimentation and by stitching together different examples.
A solution to this would also work for aspell, which uses an equals-sign instead of the colon e.g.
--conf=<str> main configuration file
This is one of the most common forms of completion, and it can be easily handled by _arguments. Note that literal colons in options can be quoted with a backslash. Here's the code example:
#compdef command
arguments=(
'--use\:-:initial input file:_files'
'--debug\:-:debugging type:(full pbonly)'
'--warn\:-:warning level:(0 1 2 3 4 5)'
)
_arguments -S $arguments[#]
Reference: _arguments in official documentation.

Resources