NSIS Scripting, difference between CallInstDLL and Plugin DLL - nsis

The title has pretty much covered my question.
CallInstDLL is straigh forward and documented here.
CallInstDLL $INSTDIR\somedll.dll somefunction
Question is how is it different from a plugin (also called extension DLL). Extension DLLs are invoked as below
MyExtDll::MyFunction arg1 arg2 ...

There is no difference in the generated code, Dll::Export is just a syntax shortcut.
MyExtDll::MyFunction arg1 arg2 is expanded to something like this:
InitPluginsDir
File "/oname=$pluginsdir\MyExtDll.dll" "${NSISDIR}\Plugins\MyExtDll.dll"
Push arg2
Push arg1
CallInstDll "$pluginsdir\MyExtDll.dll" MyFunction

Related

In Vim how to know if function is defined

I am using Vim editor v7.4 .
I have a huge C Code library , and i make constant changes to it.
Is there a way ( before compilation) to know if a function i am adding to some file is defined for this file.
Thanks
I'm not sure to correctly understand your need. In my definition, when I add a function to a file, I add its definition, so it's defined. But when I'm using a function in a file, I only need its declaration. Then there is also the problem of being sure that a function defined in a translation unit is declared somewhere (privately in the same TU as a static function, or in a header file).
For the latter, I have a solution (that checks functions definitions and declarations are balanced in lh-cpp). For the case of being sure a function is declared in the UT it's used, it won't be that simple: we need to do the preprocessor work (and recursively follow includes) and search whether a function is indeed declared. It's not impossible, but it's best to have vim know the paths where header files are in order to look for them.
Look at a tool like exuberant ctags. It parses C-style files to find any identifier and store them in a tag file, so that each of them can be accessed quickly, inside Vim for example.
Once installed, in the shell command line, you have to create a tag file with this kind of command:
$ ctags *.c *.h
This will create an new file called tags, where all the c files and header files in the current directory are parsed. Please note that there are many options for this tool (like recursively include all lib headers, which can lead to a huge file, though), you may look at the doc for more details.
Once done, in Vim, there are several commands to use transparently the infos in this file. First check your current directory is the same as the tag file; then, to check if an identifier (like a function name) is already present in the tag file, you can use:
:ts myFunctionName
I don't think tag is a good enough solution to check whether function is defined. The flexibility of C syntax make it worse, because most tag tool is syntax-based other than semantics-based.
For example, at present, the most powerful code-completion plug-in for vim is
YouCompleteMe, which is semantic-based by virtue of Clang.
So IMHO, the answer to your question is: compile it!
In order to do compiling more convenience, you can add the following configuration in your .vimrc.
map <F6> :make install<CR>
After this, when you press F6, compiler will be launched to check your code.

Function already exists VIM

I have defined a function in my /.vim/ftplugin/python.vim file. The problem is that every time I open a .py file, I get the E122: Function MyFunction already exists, add ! to replace it.
I know that if I add ! then it will override the function (which is not a problem), but that means that it will replace it everytime, and it is a useless (and not very clean) supplementary action.
I guess that the problem come from the Python configuration file being sourced again and again every time I open a new .py file.
How can I tell VIM to source only once?
I would recommend putting the function in an autoload directory. (Read :help autoload it does a very good job explaining how this works). The quick version is below.
Edit the file ~/.vim/autoload/ftplugin/python.vim and add your function there. Everything after the autoload is part of the function signiture. (Instead of / use # between directories and leave off the .vim for the filename directory(s)#file#FunctionName)
function ftplugin#python#MyFunction()
...
endfunction
This function will automatically be loaded by vim the first time it is used.
Inside the filetype plugin you would just create the necessary mappings and commands.
command -buffer MyFunction call ftplugin#python#MyFunction()
nnoremap <buffer> <leader>m :call ftplugin#python#MyFunction()<CR>
and the function will automatically be loaded when it is called the first time. And other buffer that loads the ftplugin won't run into the redefinition problem.
One way: define a variable at the end of the file, check for its existence at the beginning (similar to a c include guard):
if exists('g:my_python')
finish
endif
fun MyFunction
...
endfun
" ... other stuff
let g:my_python = 1
Another way (if all you have is this function): check directly for the existence of its definition:
if !exists('*MyFunction')
fun MyFunction
...
endfun
endif
If you use ultisnips plugin would be great to have a snippet like:
snippet guard "add guard to functions" b
if !exists('*`!p
try:
func_name = re.search('\S+\s+(\S+)\(', snip.v.text.splitlines()[0]).group(1)
except AttributeError:
func_name = ''
snip.rv = func_name
`')
${VISUAL}
endif
${0:jump here <C-j>}
endsnippet
It allow us to select a function with vip, trigger the guard snippet and fix
any function with no effort. In the post quoted you can see a complete explanation about the code above
It came from a discussion on vim #stackexchange. Actually I already knew about !exists thing, so I was trying to create a snippet to make my snippets smarter.

Haskell indentation doesn't line up function arguments

I'm using Emacs as my main Haskell editor, and as such, I of course use haskell-mode as the main mode for editing Haskell code.
Now for whatever reason, haskell-indentation doesn't offer an indent point for function arguments.
What I mean is that Emacs will consistently do this: (□ is the other indent point(s))
myFunction = maybe arg1
□ arg2
□ arg3
Instead of doing this:
myFunction = maybe arg1
□ □ arg2
□ □ arg3
Sometimes I need to break functions up onto multiple lines due to the lines getting too long, but not having haskell-mode offer the right indent level is bugging me some.
Anything I can do to alleviate this?
Edit
Seeing as I'm not the only one with this issue, I've opened a ticket on the haskell-mode github page [here]
The haskell-indentation haskell-mode issue was closed last year and won't be fixed.
For desired behavior, use haskell-indent.

Getting command line arguements passed to NSIS compiled exe

How to get all the 3 command line arguements passed to my NSIS compiled exe in variables so that I can use those parameters to Exec(ute) another exe.
For example - start abc.exe "test.txt" "-1" is the command passed to my NSIS compiled exe where "abc" is exe name and "test.txt" and "-1" are the two arguements.
How to get both of them as different variables ?
Take a look at the GetOptions macro, which allows you getting the parameters when passed in a certain way. Unless you want to adapt your current commandline parameters, GetParameters might suit you better, but you'll have to parse the parameters yourself.

<SID> with foldexpr

I am reading Learn Vim Script the Hard Way and hit something that confused me whilst doing the exercise to convert the folding functions to script local ones.
I tried to go this:
setlocal foldexpr=<SID>GetPotionFold(v:lnum)
and renamed all the functions to start with s:
To my surprise this didn't work and every line had a fold level of 0? It works if I put GetPotionFold into the global scope. Do you have to use a globally scoped function when assigning it to a option? Why?
The <SID> can be used in a mapping or menu, unfortunately not in an option. (This is a shortcoming in the implementation.)
You'd either have to translate it into the actual <SNR>NNN_ prefix (there's an s:SID() example function at :help <SID>), or use a different scope that is accessible from outside the script that defines the function. It's commendable that you want to avoid clobbering the global function namespace, as this is prone to name clashes.
A nice trick is using the autoload function prefix; it doesn't just work in autoload scripts, but can also be used elsewhere, e.g. in plugin scripts. Just prepend the script's name, and you'll have a function that can be invoked from anywhere, but scoped to the script's name:
:function! MyScriptName#GetPotionFold(lnum)
...
:setlocal foldexpr=MyScriptName#GetPotionFold(v:lnum)
Adding to the previous answer, you could define the function s:SID() to determine the script number as in the help documentation and then use execute to set the fold expression as following:
exe "setlocal foldexpr=<SNR>" . s:SID() . "_GetPotionFold(v:lnum)"

Resources