I know that it is possible to call a vimrc function from menu.vim
but is it also possible the other way around?
p.e. Writing this in vimrc does't work:
nmap <F4> :call <SID>MyFunction_in_menuvim()<CR>
What did I wrong?
<SID> is used for local functions. If your function is not local, you do not need to add this. <SID> will be replace by a string like: <SNR>23_
See vim documentation on map for more information
Related
Hi I'm trying to add a copyIndex into a script so I can pass an array of vm's into it.
The full script is at:
https://pastebin.com/embed_iframe/vQyyKrYn
The error I get is:
is not valid: The template function 'copyIndex' is not expected at this location. The function
can only be used in a resource with copy specified.
I do have the copy specified in the resource on line 44.. I think!
Any idea where I'm going wrong or how I could get this into a loop to iterate over one vm at a time.
Thanks in advance :)
Do you need to concat the copyIndex?
Instead of:
[parameters('vmName')[copyindex()]]
Use:
[concat(parameters('vmName'), copyIndex())]
I would like to define function in file functions.ps1 and then call it from another script. Something like this:
Functions.ps1:
Function Hi()
{
"hi"
}
Call it from another script (Call.ps1).
Call.ps1:
invoke-expression -Command .\functions.ps1
Hi
But function is defined in local scope of script functions.ps1 and I get err:
The term 'hi' is not recognized as the name of a cmdlet, function,
script file , or operable program. Check the spelling of the name, or
if a path was included, v erify that the path is correct and try
again.
Is there a simple way to fix this ?
You have to dotsource your script to load it into your current runspace:
. .\functions.ps1
Hi
I think the way to do this would be to dot soruce the file in the script that should use the function(s).
So in the script that will use the function put something like this.
. .\functions.ps1
Then you can start calling funcitons in that file.
A bit by memory , but think it would work.
Edit: removed a brainfart.. :)
Yup, dotsource is what you're looking for.
If your script contains spaces, you would dot source it like this
."C:\Dotsourced script.ps1"
Without space, is as the other people say
.C:\function1.ps1
All the functions and logic contained in the dotsourced script will be loaded upon sourcing it. So try to keep the scripts your'e dotsourcing in functions, otherwise it will run when sourced.
Read more about it on SS64 for example:
https://ss64.com/ps/source.html
I have been searching an entire afternoon and have found no solution to call in matlab a function by specifying its path and not adding its directory to the path.
This question is quite similar to Is it possible to call a function that is not in the path in MATLAB?, but in my case, I do not want to call a built-in function, but just a normal function as defined in an m-file.
I think handles might be a solution (because apparently they can refer to functions not on the path), but I again found no way to create a handle without cd-ing to the directory, creating it there and the cd-ing back. Trying to 'explore' what a function handle object is and how to make one with a reference to a specific function not on the path has led me nowhere.
So the solution might come from two angles:
1) You know how to create a handle for an m-file in a specific directory.
2) You know a way to call a function not on the matlab path.
EDIT: I have just discovered the function functions(myhandle) which actually lets you see the filepath to which the handle is referring. But still no way to modify it though...
This is doable, but requires a bit of parsing, and a call to evalin.
I added (many years ago!) a function to the MATLAB Central File Exchange called externalFcn
http://www.mathworks.com/matlabcentral/fileexchange/4361-externalfcn
that manages calls to off-path functions. For instance, I have a function called offpathFcn that simply returns a structure with a success message, and the value of an input. Storing that function off my MATLAB path, I can call it using:
externalfcn('out = C:\MFILES_OffPath\offpathFcn(''this is a test'')');
This returns:
out =
success: 1
input: 'this is a test'
(Note that my implementation is limited, and improvable; you have to include an output with an equal sign for this to work. But it should show you how to achieve what you want.)
(MathWorks application engineer)
The solution as noted in the comment 1 to create a function handle before calling the function is nicely implemented by #Rody Oldenhuis' FEX Contribution:
http://www.mathworks.com/matlabcentral/fileexchange/45941-constructor-for-functionhandles
function [varargout]=funeval(fun,varargin)
% INPUT:
% fun: (char) full path to function file
curdir=cd;
[fundir,funname]=fileparts(fun);
cd(fundir);
[varargout{1:nargout}] =feval(funname,varargin{:})
cd(curdir);
I've modified Thierry Dalon's code to avoid the use of feval, which I always feel uncomfortable with. Note this still doesn't get around cd-ing to the directory in question, but well, it happens behind the scenes, so pretend it doesn't happen :-)
Also note what Ben Voigt pointed out above: calls to helper functions off the path will fail.
function [varargout]=funeval(FunctionHandle, FunctionPath, varargin)
% INPUT:
% FunctionHandle: handle to the function to be called; eg #MyFunction
% FunctionPath: the path to that function
% varargin: the arguments to be passed to Myfunction
curdir=cd;
cd(FunctionPath)
[varargout{1:nargout}] = FunctionHandle(varargin{:});
cd(curdir);
end
and calling it would look like
Output = funeval(#MyFunction, 'c:\SomeDirOffMatlabsPath\', InputArgToMyFunc)
The run command can run a script file from any directory, but it can't call a function (with input and output arguments).
Neither feval nor str2func permit directory information in the function string.
I suggest writing your own wrapper for str2func that:
saves the working directory
changes directory to the script directory
creates a function handle
restores the original working directory
Beware, however, that a handle to a function not in the path is likely to break, because the function will be unable to invoke any helper code stored in other files in its directory.
I am trying to call a perl script from my HTML page. The way am trying to do is to call the url of the perl script located on the server.
Here is the piece of code:
HTML:
var fname = "Bob";
var url='http://xxx.com:30000/cgi-bin/abc.pl?title=fname';
window.open(url,"_self");
The way am trying to retrieve it in perl as:
Perl:
print "$ARGV[0]\n";
Now, I have 3 questions:
I think this is the correct way to pass the variables but am not able to print the argument in perl.
If i want to pass another variable lname, how do i append it to the url?
My window.open should open the output in the same window, since it uses the parameter _self. Still it doesn't.
Could anybody point out the problems?
Thanks,
Buzz
No #ARGV contains command line arguments and will be empty.
You need the CGI module
use warnings;
use strict;
use CGI;
my $query = CGI->new;
print $query->param( 'title' );
Edit:
Take a look at dan1111's answer on how to generate HTML and display it in the browser.
In addition to what Matteo said, a simple print statement is not enough to send some output to the browser.
Please see a recent answer I wrote giving a sample CGI script with output.
In regard to your other issues:
Variables are appended to a url separated with &:
var url='http://xxx.com:30000/cgi-bin/abc.pl?title=fname&description=blah';
Based on this question, perhaps you should try window.location.href = url; instead (though that doesn't explain why your code isn't working).
There are two different environments that each pass variables two different ways. The command line can pass variables through the #ARGV and the browser can pass variables through #ENV. It doesn't matter what language you use, those are the arrays that you will have to employ.
I am trying to implement a boolean function in Vim and having some trouble and I am sure there is something I'm missing.
Just to be clear, I'm looking to implement a function that when called with ! it will do the opposite.
Vim has plenty of boolean functions, like list and paste. In my case, if I have a function that say, opens a buffer, like:
:call MyFunction()
Then I would like this to close the buffer when is called with a !:
:call MyFunction()!
Not sure if this is even possible, and I am not looking to find out how to open or close a buffer, but the actual boolean implementation.
Edit:
It seems that this is way more feasible if we talk about a user-defined command, like:
:MyCommand action
That can also be called as:
:MyCommand action!
When creating your command, give it the -bang option and then use the <bang>, which will expand to a bang or nothing. Then, to redirect this to your function create a special argument and analyze it to see whether it contains a bang or not. Something like this: (including what ZyX suggested)
function! Bang(bang)
echo "With".((a:bang)?"":"out")." bang."
endfunction
command! -bang Bg call Bang(<bang>0)
Of course, I'm not doing the correct tests here to check if a:bang is really a bang, but you got the idea.
:Bg
Without bang.
:Bg!
With bang.