I want to know how can I configure my netbeans ide to format my code in my specific need.
I need all my assignment in same line to easily distinguish it.
for eg:
$a = 1;
$b = 1;
$c = 1;
$a++;
some code
$d = 1;
Based on your sample code, I'm assuming that you want to do this for PHP. If so, then you can do it as follows:
Select Tools > Options > Editor, then click the Formatting tab.
Select PHP from the Language drop list, then Alignment from the Category drop list.
A code sample will be displayed in the Preview window on the right side of the screen which includes some variable assignments near the end of the code:
Under Group Multiline Alignment check the Assignment box. Note that the assignment operators (=) in the code preview are now aligned:
Notes:
The column position used for aligning the assignment operators is dynamic, based on the length of the longest variable name. I don't think it is possible to place the assignment operator in a specific column as suggested by your code example.
This approach is specific to PHP, and can't be used for formatting code in other languages such as Java or JavaScript.
Formatting in NetBeans can be configured under "Tools / Options / Editor / Formatting", but I don't think that you can configure NetBeans to use your desired format.
Related
I need to be able to generate debugging statements for my code. For example, here is some code I have:
$this->R->radius_ft = $this->TC->diameter / 24;
$this->R->TBETA2_rad = $this->D->beta2 / $rad; //Outer angle
$this->R->TBETA1_rad = $this->R->inner_beta1 / $rad; //Inner angle
I need to be able display results of computations so that they can be read by a human.
So far I have been doing this (example showing first line from above only):
$this->R->radius_ft = $this->TC->diameter / 24;
if (self::DEBUG)
print("radius_ft({$this->R->radius_ft}) = diameter({$this->TC->diameter}) / 24");
The above print something like radius_ft(1.4583) = diameter(35) / 24 and a few of those lines looks like equations and are nicely traceable when I want to verify things on paper, or if I want to expose the intermediate work of the computations to someone else.
The problem is that it is a pain to construct those debugging statements. I craft them by hand, and usually it is not a problem, but in my current example, there are hundreds of lines of code where this needs to be done. Much pain.
I was wondering if there are facilities in PHP that will allow me to make print-outs of statements showing what each line of code does. Or methods to semi-automate creating the debug lines for me.
I have so far discovered this method to cut down on some of the work .... use Macro facilities of a text editor.
Paste line of code into TextPad (or similar editor that supports macros). Record macro and use Search, Mark and Copy facilities to carefully navigate between special symbols of the variable, such as $, >, and symbols that are not alphanumeric or $, >, etc. while copying and extracting and pasting parts of variable to craft my particular statement.
Exact steps may differ for one's needs. My macro operates on one variable like $this->R->radius_ft with cursor at the start and ends up with something like radius_ft({$this->R->radius_ft}), with cursor a few chars after the end, sometimes coinciding with the next variable to process.
Perhaps same could be done with regular expressions but I like the way Macro does it - I can process a variable and go to the next one and just repeat the macro with a hot key combination. This takes out the most tedious chunk of work for me.
Alternatively - hand the person the code and let them figure it out. Teach them how to read code.
I'm trying to build a PHP if expression.
In English, here's the conditions for the IF to be true:
Visbility < 5000m
OR
BKN/OVC < 1500ft
Now, the variables I have to play with are:
for Visibility: $visibility and for the BKN/OVC: it's a bit more complex.
This data is given in
$xml->data->METAR[0]->sky_condition
The data itself is pulled from XML file with the relevant information looking like this:
<sky_condition sky_cover="BKN" cloud_base_ft_agl="600"/>
<sky_condition sky_cover="SCT" cloud_base_ft_agl="1100"/>
Any ideas on how I could sort through the sky_condition->sky_cover for the relevant information and feed it through to the IF?
Thanks.
You could access the attributes of the XML with the array syntax instead of the arrow operator.
if((string)$xml->data->METAR[0]->sky_condition[0]['sky_cover']==='???') {
}
Was this your question?
I'm working on a site for some apartments.
I have some data getting assigned to Smarty in a foreach loop.
$i = 0;
foreach ($obj2 as $array) {
$smarty->assign('name'.$i, $obj2[$i]['name']);
$smarty->assign('numbedrooms'.$i, $obj2[$i]['number_of_bedrooms']);
$smarty->assign('numbathrooms'.$i, $obj2[$i]['number_of_bathrooms']);
$smarty->assign('sqfeet'.$i, $obj2[$i]['square_feet']);
$smarty->assign('deposit'.$i, $obj2[$i]['deposit']);
$smarty->assign('rent'.$i, $obj2[$i]['rent']);
$smarty->assign('vacantunits'.$i, $obj2[$i]['vacant_units']);
$i++;
}
When the template is loaded ($smarty->display('template.tpl');) I want all of the data to be available via replace(like replace:'[[lowestrate]]':{$lowestrate} (example from another block of code)).
However, because the number of items in $obj2 could change (it's currently 3), I can't just say replace:'[[name1]]':{$name1}. (Not to mention how long that would take)
Also, the reason replacement is required is that the page content is managed from a CMS system with a WYSIWYG editor, where the editor can type [[lowestrate]] to have it replaced with the lowest cost apartment. They should be able to type [[name1]] to have it replaced with the name of the first apartment, or [[numberbedrooms1]] to be replaced with the number of bedrooms apartment 1 has.
Does anyone have any idea as to how I should go about doing this?
This sounds like a job you should be doing in the PHP level, not the smarty level. I suggest that you do the replacements before the assignment to smarty, and then send the transformed array, it will be much easier (and cleaner imho)
I like to have a space after function names, arrays, that sort of thing, so a function declaration would look like:
function myfunction ($param)
{
$a = array ('a', 'b');
callfunction ($a);
}
And although I have set the style guide in Netbeans to correspond to this whenever it does autocomplete/suggestions it always misses out the space and gives me something like callfunction($a) even though when I go source->format (alt+shift+f) it then formats the code properly.
Any way to get autocomplete to add the space?
UPDATE:
Just to make things clear, I have set up Netbeans to correspond to my coding preferences, as indicated by the ability to use auto format. The problem is auto complete (or whatever the hint thing is called) does not respect these settings, leading to the missing space.
Go in Tools->Options.
In pane Editor -> choose pane Formatting.
In language choose PHP and in Category choose Spaces.
Check all in Before Keywords, Before Parenthesis, Before left braces, and you can choose other properties if you want.
Then when you will use auto-complete or Alt+Shift+F to reformat it will put the spaces correctly.
EDIT :
In the OP case it seems an other configuration prevents the auto-complete to works.
This is my config :
Do this:
Goto Options > Formatting
Scroll down to "Spaces Before Parenthesis"
Check the option called "Function Declaration"
I have added following lines at start of %PRPOGRA~%\Notepad++\plugin\APIs\php.xml
<KeyWord name="$_GET"></KeyWord>
<KeyWord name="$_POST"></KeyWord>
<KeyWord name="$_SERVER"></KeyWord>
CTRL+Space to generate autocomplete syntax list for
$_GET
$_POST
$_SERVER
List should be appeared on pressing $ (shift + 4).
I found a hint for my own question.
Notepad++ generate AutoCompletion list of syntax, only on keypress event of
A-Z or a-z.
You can modify it behavior by modifying files at
NotePad++ > plugin > APIs > *.xml
<keyword name="anything"> keyword tags must be sort by attribute value "name" and this sorting is ASCII code wise,