Referencing filetype from function - macvim

I'm trying to write a function that acts on any filetype (thus is not a particular ftplugin), that has divergent behavior based upon what the filetype is. e.g.
if (filetype=='objc')
"do something
elseif (filetype='cpp')
"do something else
endif
I read through the filetype docs, but nothing seems to reference this. Advice?

Try accessing the option value:
if (&ft == 'objc')
...

You can use & to access the value:
if ( &ft == 'cpp' )
...
etc.

Related

Apache2 Perl vHosts Error

I just worked through this tutorial and modified the table by adding another column. I want to check the value before adding the template script. It didn't work and the script includes the template-ssl every time. It is important that this script works with MySQL, mass vhosts is not possible.
$My::dir = #row[3];
$My::encrypted = #row[4];
if ($My::encrypted == 'ssl') {
$s->add_config(["Include /etc/apache2/sites-available/template-ssl"]);
}
else {
$s->add_config(["Include /etc/apache2/sites-available/template-def"]);
}
I think the variables doesn't work but if(#row[4] == "ssl") also fire as true every time. Even when the DataRow contains "def".
Ok, it was too simple. The error was that you compare stings with "xx" eq "yy" and numbers with 1 == 2.

How to call a plugin from my .vimrc file?

I am using a VIM plugin called Goyo (for writing markdown files). It is similar to Distraction Free mode in SublimeText. I want to create a write-mode in my .vimrc that I can toggle. This toggle will set various options on in write-mode, such as set spell, set wrap etc.
I have everything working here, except calling the Goyo function. How can I execute the Goyo plugin from within my ToggleWrite() function?
Here is my code:
" Write toggle switch
let b:write = "no"
function! ToggleWrite()
if exists("b:write") && b:write == "yes"
let b:write = "no"
set nowrap
set nolinebreak
set textwidth=100
set wrapmargin=0
set nospell
" ↓↓↓ I want to call this ↓↓↓
":Goyo
else
let b:write = "yes"
set wrap
set linebreak
set textwidth=100
set wrapmargin=0
set spell
" ↓↓↓ I want to call this ↓↓↓
":Goyo 60x100%
endif
endfunction
" Set up the toggle sequence
nmap <expr> ,w ToggleWrite()
I put my comment as an answer:
Your mapping uses <expr>, which is not right in your case. You should try this mapping instead:
nmap ,w :call ToggleWrite()<cr>
or
nmap <silent> ,w :call ToggleWrite()<cr>
<expr> lets you make "custom" mappings, depending on the return of a function. It's rarely used in common cases.

Set a new Variable in Assemble (or combine two comparison helpers)?

is there a way to set a new variable in a partial in assemble (assemble.io)? Or is it possible to combine two comparison-helpers, for example:
{#is somevar "yes" || anothervar "no"}
There's HTML in my partial which should only be shown if one of two different variables is true. If there's only one variable, i only write {{#is somevar "yes"}}, but i need that #is-helper for both variables.
I haven't found a way in the assemble-docs so i tried another way. I tried to do two #is-Helper like:
{{#is somevar "yes"}}
// HTML
{{/is}}
{{#is anothervar "no"}}
// HTML (the same as above)
{{/is}}
But this is really redundant... so i tried to set a variable inside both #is, for example:
{{checkvar = 0}}
{{#is somevar "yes"}}
{{checkvar = 1}}
{{/is}}
{{#is anothervar "no"}}
{{checkvar = 1}}
{{/is}}
So i only have to check for one variable (checkvar).
BUT all this wont work... So is there a way to do this in assemble?
Greetings
This would be something common to any Handlebars templates and not specifically Assemble.
Assemble uses handlebars-helpers and we've recently upgraded to Handlebars 3.0 so you can use a combination of subexpressions with the or and is helpers:
{{#or (is somevar "yes") (is anothervar "no")}}
<div>somevar = yes or anothervar = no</div>
{{/or}}
Edit: This might not work since the is helper is a block helper. You might have to write your own helper to just return the value. Either that or change somevar and anothervar to be truthy values instead of yes and no. Then you can just use the or helper directly:
{{#or somevar anothervar}}
{{/or}}

Assign a function to a variable recursively

I've read a lot about that argument here in stackoverflow. Anyway I can't really understand what really happens to a variable when I assign a recursive function to it ! I've tried so hard using printNow() command just to undestand what happening .. but nothing , just a bunch of None !
variable = function() #variable is going to be the the return value of function() ?
#if function() is a recursive function each time of the recursive, variable
#is gonna be different ?
edit :
Added a piece of code that i can't understand ..
def permute(seq):
if len(seq)<=1:
perm=[seq]
else:
perm=[]
for i in range(len(seq)):
sub=permute(seq[:i]+seq[i+1:]) # What sub is gonna be = ?
for p in sub:
perm.append(seq[i:i+1]+p)
return perm

How do I substitute unseen name-value pairs (from radio buttons) in my CGI script?

Cross from PerlMonks, see bottom.
UPDATE: Perhaps the best way to do this is through HTML or JavaScript(I know nothing of these)?
Objective
After the whole code is run and an output is given, I'd like to provide a hyperlink to re-run the code, with the same search word, but different radio buttons pressed.
Here is a portion of my CGI script, related to the user input:
my $search_key = param('query');
my $c_verb = param('verb_only');
my $c_enabling = param('enabling');
my $c_subject = param('subject');
my $c_object = param('object');
my $c_prep = param('prep');
my $c_adj = param('adjective');
my $c_modnoun = param('modnoun');
my $category_id;
if ($c_verb eq 'on')
{
if ($c_enabling eq 'on')
{$category_id = 'xcomp';}
elsif ($c_subject eq 'on')
{$category_id = 'subj';}
elsif ($c_object eq 'on')
{$category_id = 'obj';}
elsif ($c_prep eq 'on')
{$category_id = 'prep';}
I don't have access to the HTML, but from viewing the source code, all the $c_... have the form:
<input type="checkbox" name="verb_only" onClick="ch...
The "unseen" in the title is referring to no appended name/tag value pairs, so I don't know what to change, Where can I find this information?
I was thinking of changing $c_enabling to $c_subject and another link to a case where it was as if $c_prep was chosen from the user. Is there a way to substitute the name-value pairs of that single param? (So user inputs options, runs, instead of going back to input different ones, just click hyperlink, because some options stay the same)
The URL of the form is like: http://concept.whatever.com/test.html and the output is at the URL: http://concept.whatever.com/cgi-bin/search2011.cgi
My attempt
See posted answer
UPDATE: I've tried `url(-query) but nothing was appended to the end...
Thanks for any advice. Let me know if this is not clear.
Original: http://www.perlmonks.org/?node_id=910616.... Particularly applying this advice: http://www.perlmonks.org/?node_id=910630
If the method of the HTML is changed to GET instead of POST:
<form name="search_option" action="http://localhost/cgi-bin/mytestsearch2011.cgi" method="get">
Then the tags can be viewed (I had to copy the source code and do this on my localhost to check them)
I was able to find out what tags and values to put, b/c get method. So here is the working code:
if ($category_id eq "xcomp") {
my $subjurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&subject=on&exclude0=&exclude1=&exclude2=&exclude3=";
print qq(Subject\n)." ";
my $objurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&object=on&exclude0=&exclude1=&exclude2=&exclude3=";
print qq(Object\n)." ";
my $prepurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&prep=on&exclude0=&exclude1=&exclude2=&exclude3=";
print qq(Preposition\n)."<br><br>";
}
elsif ($category_id eq "subj") { ##List urls other than what is currently output:
my $enablingurl = "http://localhost/cgi-bin/mytestsearch2011.cgi?query=$search_key&verb_only=on&enabling=on&exclude0=&exclude1=&exclude2=&exclude3=";
print qq(Enabling Function\n)." ";
...
I don't understand all the exclude tags, but that's okay...
UPDATE: This works with POST as well, I just needed to know all the tags that came after the URL. Thanks!