I want to get the url of a blob, and I'm doing the following:
(.. js/window -URL createObjectURL blob)
to mimic the JS
window.URL.createObjectURL(blob)
But I get the following error:
TypeError: Not enough arguments (at createObjectURL)
What am I doing wrong?
Your use is incorrect. Needs an extra pair of parens so blob becomes an actual argument and not the "next" step.
(.. js/window -URL (createObjectURL blob))
Related
In ELISP, the documentation for interactive codes mentions:
P -- Prefix arg in raw form. Does not do I/O.
...
s -- Arbitrary text, read in the minibuffer and returned as a string ... Prompt.
I presumed that I could write a function with an optional prefix argument, as in:
(defun some-function (&optional prefix)
(interactive "P")
...
)
or a function with user input, as in:
(defun some-function (user-argument)
(interactive "sProvide an argument: ")
...
)
but not both. Then I found the Org-mode function org-match-sparse-tree, which I can call with C-u C-c \, where the prefix argument restricts the match to open org-mode headings and I am still prompted for a match. The source code is below and I cannot find how the variable match is assigned:
(defun org-match-sparse-tree (&optional todo-only match)
"..."
(interactive "P")
(org-agenda-prepare-buffers (list (current-buffer)))
(let ((org--matcher-tags-todo-only todo-only))
(org-scan-tags 'sparse-tree (cdr (org-make-tags-matcher match))
org--matcher-tags-todo-only)))
How does this function take both prefix argument and user input?
How does this function [interactively] take both prefix argument and user input?
It doesn't -- the match argument is not obtained, and is therefore nil. What you're seeing is the effect of the subsequent call to (org-make-tags-matcher match) with that nil value as the argument:
(defun org-make-tags-matcher (match)
"..."
(unless match
;; Get a new match request, with completion against the global
;; tags table and the local tags in current buffer.
(let ((org-last-tags-completion-table
(org-tag-add-to-alist
(org-get-buffer-tags)
(org-global-tags-completion-table))))
(setq match
(completing-read
"Match: "
'org-tags-completion-function nil nil nil 'org-tags-history))))
...)
Functions can take multiple interactive arguments, though.
See C-hf interactive
To pass several arguments to the command, concatenate the individual strings, separating them by newline characters.
The very first example in that help demonstrates this:
(defun foo (arg buf) "Doc string" (interactive "P\nbbuffer: ") .... )
This is elaborated upon at (elisp)Using Interactive -- up one level in the documentation you'd linked to:
It may be a string; its contents are a sequence of elements
separated by newlines, one for each argument(1). Each element
consists of a code character (*note Interactive Codes::) optionally
followed by a prompt (which some code characters use and some
ignore). Here is an example:
(interactive "P\nbFrobnicate buffer: ")
The code letter ‘P’ sets the command’s first argument to the raw
command prefix (*note Prefix Command Arguments::). ‘bFrobnicate
buffer: ’ prompts the user with ‘Frobnicate buffer: ’ to enter the
name of an existing buffer, which becomes the second and final
argument.
You should read that documentation fully, though -- there are more sophisticated things you can do, including writing arbitrary elisp to produce the interactive arguments (which may or may not involve prompting the user).
I am trying to get entire text of current buffer. I believe it is represented by '%' (see answer by SnoringFrog at https://vi.stackexchange.com/questions/2319/is-there-a-text-object-for-the-entire-buffer). However, following function gives an error:
function Check ()
echo %
endfunction
I call it with following command:
:call Check()
The error is:
Error detected while processing function Check:
line 1:
E15: Invalid expression: %
E15: Invalid expression: %
Where is the problem and how can it be solved?
Depending on the context, % can be a shortcut for the 1,$ range or a placeholder for the filename associated with the current buffer.
In the first case (the one in your link), it's not meant to be echoed at all which would be completely pointless.
In the second case, it needs to be expanded with expand('%') if you want to use it in a function.
Anyway, none of that matters because % is not what you want at all. What you want is :help getline():
function Check ()
echo getline(1,'$')
endfunction
I am simulating Wireless Sensor Network using NS2.35 and I get an error saying
ns: 217: invalid command name "217"
while executing
"217"
I have no where used such command throughput my tcl file. Can any one help why I get this error?
You've probably used a variable containing a numeric value as a command name, perhaps by putting it at the start of a line or by placing [brackets] around it (because brackets do command substitution). The brackets can be even embedded in a string:
This example demonstrates what I mean:
set xyz 217
puts "This is [$xyz] in brackets"
If you want to print some literal brackets out around a variable, you have to add some backslashes:
set xyz 217
puts "This is \[$xyz\] in brackets"
The problem could also be if you've got a command that returns 217 and you've put brackets around it at the start of a line (or in other places where a command is expected):
proc xyz {} {
return 217
}
[xyz]
You've not shown us your code so which exact possibility it is… we can't tell. But I bet it'll be one of these problems. Tcl cares about its syntax characters, and is very exacting about making sure they do what they say they do.
invalid command name "217" :
"217" is an internal command in your 'ns' executable.
Please tell which changes you made to ns-2.35/, if any. (WSN ?)
And please upload your "wsn.tcl" file to e.g. 'Google Docs'.
ns2
In the following code, we can assign the result of a GET-WORD to p through a SET-WORD, and then use it under the new name:
p: :print
p [{Hello} {World}]
But what if you are using COMPOSE, and you find a situation such as this?
do compose [p: (:print)]
p [{Hello} {World}]
That gives an error:
*** ERROR
** Script error: -unnamed- is missing its value argument
** Where: do
** Near: do compose [p: (:print)] p ["Hello" "World"]
So it's like function values in a block are "live" when seen in the interpreter...whether they were fetched as an evaluative result or not. (It would seem they should be inert unless fetched or applied somehow, otherwise such assignments are not possible from within a COMPOSE or similar.)
It seems you have to quote a get-word, such as:
do compose [p: (quote :print)]
p [{Hello} {World}]
That could do the trick to make p the print function. But can you do it without going through a GET-WORD or similar as a proxy?
Yes, you can "disarm" the active function! value with a feature of the DO-dialect:
>> do probe compose [p: quote (:print)]
[p: quote make native! [[
"Outputs a value followed by a line break."
value [any-type!] "The value to print"
]]]
>> p [{Hello} {World}]
Hello World
They key here is the special argument passing mode used for the single argument of QUOTE:
>> source quote
quote: make function! [[
"Returns the value passed to it without evaluation."
:value [any-type!]
][
:value
]]
This argument passing mode, unimaginatively called "get arguments", inhibits evaluation of the argument value. So in our particular case, it prevents the "active" nature of the function! value to come to bear.
For more details about argument passing modes, you might want to have a look at this recent treatise about literal and get arguments, which compares the differences between Rebol 2 and Rebol 3 to give a historical perspective.
Use the following way to create the get-word, it buys you an additional level of indirection:
>> do compose [p: (to-get-word 'print)]
>> p [{Hello} {World}]
Hello World
If you want the assignment to be done using a DO [...] form, then you need a word assigned to the anonymous function in order to manipulate it in a passive way.
An alternative option is to do the assignment outside of the composed block:
p: first compose [(:print)]
The first question is what do you need this for?
Because it works without compose.
Do [p: :print]
P 1
And without a get-word
Do [p: get first [print]]
Edit:
I don't understand the implications for the C++ binding, but 'compose is used to evaluate parts of a block selectively. In your example you want to evaluate a part, but still want it not being evaluated, so you need to stop it from being evaluated too early, for example:
do compose [p1: (to get-word! 'x)]
If you want to use compose, and no get-/lit-word!, you could try quote:
do compose [p4: get quote ( quote print)]
The inner 'quote guards 'print from being evaluated during compose, the outer one guards durng the 'do, so that 'get can get the value.
I'm attempting to look up the word "flower" in Google's dictionary semi-api. Source:
https://gist.github.com/DelvarWorld/0a83a42abbc1297a6687
Long story short, I'm calling JSONP with a callback paramater then regexing it out.
But it hits this snag:
undefined:1
ple","terms":[{"type":"text","text":"I stopped to buy Bridget some \x3cem\x3ef
^
SyntaxError: Unexpected token x
at Object.parse (native)
Google is serving me escaped HTML characters, which is fine, but JSON.parse cannot handle them?? What's weirding me out is this works just fine:
$ node
> JSON.parse( '{"a":"\x3cem"}' )
{ a: '<em' }
I don't get why my thingle is crashing
Edit These are all nice informational repsonses, but none of them help me get rid of the stacktrace.
\xHH is not part of JSON, but is part of JavaScript. It is equivalent to \u00HH. Since the built-in JSON doesn't seem to support it and I doubt you'd want to go through the trouble of modifying a non-built-in JSON implementation, you might just want to run the code in a sandbox and collect the resulting object.
According to http://json.org, a string character in a JSON representation of string may be:
any-Unicode-character-
except-"-or--or-
control-character
\"
\
\/
\b
\f
\n
\r
\t
\u four-hex-digits
So according to that list, the "json" you are getting is malformed at \x3
The reason why it works is because these two are equivalent.
JSON.parse( '{"a":"\x3cem"}' )
and
JSON.parse( '{"a":"<em"}' )
you string is passed to JSON.parse already decoded since its a literal \x3cem is actually <em
Now, \xxx is valid in JavaScript but not in JSON, according to http://json.org/ the only characters you can have after a \ are "\/bfnrtu.
answer is correct, but needs couple of modifications. you might wanna try this one: https://gist.github.com/Selmanh/6973863