I just wrote my first SublimeText Snipped and wonder if I can all API commands. In the concrete case I have the following snippet:
<snippet>
<content><![CDATA[ public function set${1:fieldName}(\$${2:fieldName})
{
\$this->_${2:fieldName} = \$${2:fieldName};
}]]></content>
<tabTrigger>set</tabTrigger>
<scope>source.php</scope>
<description>public function set...(...){}</description>
</snippet>
and at the second occurrence of ${2:fieldName} I'd like convert the first char to lower case.
There is no API access, but you can do regex substitutions. See the following for additional information.
https://docs.sublimetext.io/guide/extensibility/snippets.html
Related
I want to take the text for a document and save it as a variable. I looked in the documentation and found "getText" something I think shall work. https://developers.google.com/apps-script/reference/document/footnote-section#gettext
I just get a problem when I try using it, because it's not a pre built function it gives the error massage "TypeError: Cannot read property 'getText' of null". So I looked at some more into it and noticed I needed Authorization:
"Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents"
So how do I get the required authorization, do I need to do something different or is there another way i could do it?
It's just going to run on some of my docs for fun to se what funny things I am able to do with the program.
(New to programing, now the basics but just trying to see if programing is something for me)
Thanks in advance
Given with this sample document
You can start with this sample code below.
Code:
function myFunction() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
Logger.log(text.getText()); // returns all text in document ("Hey, search for me!!! I am <here>!!")
// 1. Regular expression (exec)
var regExp = new RegExp("<\(.*\)>", "gi"); // "i" is for case insensitive
var search = regExp.exec(text.getText())[1];
Logger.log(search); // returns "here"
// 2. (search)
Logger.log(text.getText().search(/here/)); // returns the index where the string was found, or -1 if not found
}
Output:
Note:
getText will return the text of the Class Text.
If you want to get a specific pattern from the document, you need to use Regular expression. I prefer the exec method. See usage for more details
For the authorization, you only need to click allow. I assume you are using apps script due to the tag.
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 searched via Google but couldn't find an answer to this. PhpStorm has many built in annotations for code completion but many are missing as well. I am pretty sure there is a way to create new annotations but couldn't find it anywhere within the settings. Or maybe it is an XML file somewhere. NetBeans has support for this feature.
In other words, how can I create new phpDoc annotations for completion in phpStorm 8 like #usesDefaultClass for phpUnit.
I have found this answer here: http://blog.jetbrains.com/webide/2013/02/phpdoc_and_code_templates/
Hope this will help you
PhpDoc Templates
PhpDoc templates are located under Settings | File Templates | Includes. Currently there are three templates named PHP Class Doc Comment, PHP Function Doc Comment and PHP Field Doc Comment. Any of these can be included into other templates via the #parse directive. For example, we can modify the original class template (Templates | PHP Class) to also include the class PHP Doc when a class is generated:
<?php
#parse("PHP File Header.php")
...
#parse("PHP Class Doc Comment")
class ${NAME} {
}
The same templates are used when:
A new PHP Doc comment is generated after we type /** and press Enter before a class, function (method) or class field.
We invoke Code | Generate | PHPDoc blocks or use the Add PHP Doc quick-fix for the inspection Missing PHP Doc.
Below is a list of variables that can be used in PHP Doc templates:
${NAME}
The element (class, function, field) name.
${NAMESPACE}
The name of the namespace the element belongs to without any leading or trailing backslashes, for example Core\Widgets. The variable value is empty if the element doesn’t belong to any namespace. A check like `#if (${NAMESPACE})` ... is possible.
${CLASS_NAME}
Contains a class name for class methods and fields. Will be empty for functions that do not belong to any class.
${TYPE_HINT}
For functions (methods), contains the return type of the function (method). For fields, evaluates to the field’s type if it can be found, for example, from a default value. Will be empty if the type cannot be retrieved from the code.
${STATIC}
Takes the value of “static” if the function or field is static, otherwise, an empty string. We can use this variable with the condition `#if (${STATIC})` ... to generate something specific for static class members.
${CARET}
Marks the position where the editor caret should be placed after the comment is added. Note: Works only if the comment is added after we type “/**” and hit Enter. Should be placed inside the comment, not on the first line /** or on the last line */. In all other cases the caret marker will be ignored.
${PARAM_DOC}
A generated PHP Doc fragment containing function (method) parameters in the form: “* #param type $name“. For example, if the function signature is foo ($x, $y), it will evaluate to:
#param $x
#param $y
${THROWS_DOC}
A generated PHP Doc fragment containing exceptions thrown from function (method) body in the form * #throws ExceptionName. One exception per line/#throws tag. For example:
#throws DOMException
#throws HttpException
Code Templates for Overridden/Implemented Methods
The following templates can be found under Settings | File Templates | Code: PHP Implemented Method Body and PHP Overridden Method Body. There are few parameters, considering that in most cases we will need either a simple call to a parent method or just our own comment (some version of TODO perhaps):
${NAME}
Method name.
${PARAM_LIST}
A comma-separated list of parameters. For example, if the original method signature is foo(Bar $bar, $y), the variable will take the value “$bar, $x” which can be used in a call to the parent method as `${NAME}(${PARAM_LIST})`”
${RETURN}
Either “return” or an empty string.
A Dollar Sign Variable: ${DS}
Solves the problem of putting a dollar sign $ anywhere within the template. Actually, the dollar sign is used both in PHP and in Velocity template engine taking care of code generation behind the scenes. So whenever we need a dollar sign, just use ${DS} as its equivalent. For example, if we want $this->foo() to be generated, we need to put ${DS}this->foo(). This may not look perfect but guarantees that there will be no conflicts.
Is there a way to have procedures (or C-like functions) in Gnuplot? I need something really simple, just something like:
function func1()
{
var1 = "string1";
var2 = var1."string2";
return var2;
}
to make my gnuplot scripts a little bit more compact.
Gnuplot supports (simple) functions with arguments:
func1(x)=x."string2"
More complicated "inline" functions can be created if you're using gnuplot 4.4:
func1(x)=(var1=x, var2=var1."string2", var1.var2) #returns x.x."string2"
In this form, the last portion of the function is what is returned (var1.var2) and the statements are evaluated left to right.
If you want to have functions which accept no parameters, you can (often) use macros:
set macro
funcmacro='"string1"."string2"'
print #funcmacro
Yes. You can concatenate strings in gnuplot with something like
strcat(str1,str2) = sprintf("%s%s",str1,str2)
str3 = strcat("string1","string2"); print str3
The first line is the function definition, the second line is just an example of usage. You can read more in the "User-defined variables and functions" section of the gnuplot documentation (it is under the "Expressions" section; you may have trouble searching for the string 'user-defined' in the pdf because of the 'fi' character generated by LaTeX).
You might want to consider looking at the Pyxplot plotting package http://pyxplot.org.uk, which has very similar syntax to gnuplot (albeit cleaned up), but which also has a lot of the features of a scripting language. It has subroutines, which should do exactly what you're asking for.
How can you send an argument to the help function?
I wish to have something like this:
function intro(funcname)
disp('This is an introduction to the function you chose. See the help below:')
help funcname
end
where I can show the help text for a function, which name comes as an argument in the function. The above does not work though, when MatLab just searches for funcname as a function name and not the variable value.
In short: Yes, you can do it, by using the function form of help:
x = 'mean';
help(x);
In your example:
function intro(funcname)
disp('This is an introduction to the function you chose. See the help below:')
help(funcname);
end
Explanation:
The form that you are using
help xxx
is merely a shortcut to:
help('xxx');
If you have multiple arguments separated by space (Thanks to #Amro on this one), it is the same like sending multiple arguments:
For example:
mcc -m fileNames
is equal to
mcc('-m','fileNames');
As a side note that represents my opinion, I would like to add that in general, the second form is preferred, except when you write a quick-and-dirty code.