Vim go to std library method/function definition - c++

I love some of the plugins affiliated with vim and I have installed most of them as git submodules (clang_complete, cvim, fugitive, NerdTree, pathogen, snipMate, supertab, taglist) However there are two basic featured that I cannot get working. i.e.
1) Example -> if I compile the following example
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
I can not figure out how to jump for example to the function open i.e. “myfile.open” from the std. library. If I go and paste the code to visual studio and click go to definition it is taking me directly to that place. I have read that this could be done with ctags, however I am asking myself if the autocompletion is already working i.e. when I type “myfile.” I see a whole bunch of methods that clang is giving me , so I guess that it should be some other better way to jump to the definition from vim something similar to (ctrl + ]) which should work out of the box.
2) In visual studio/.net whenever I type the dot . I see methods and when I scroll down the method it is supplying short description what is this method doing. Is there a way to enable something similar in vim. As far as I can tell this should be a property of the std library however I can not see any such thing in std.

You are confusing Vim with an IDE, I think.
You can't expect any IDE feature to be available, at least without some effort, in a (very powerful) text editor.
Vim's equivalent of "Go to declaration", <C-]> or :tag foo<cr> relies on the availabilty of one or more tags generated by exuberant-ctags or some compatible program against your code base and any standard libs. Because Vim doesn't come with such a tags file for (AFAIK) any language, you'll have to generate one by yourself and tell Vim where to find it. There's even a program, hdrtag, specifically written for that, I've never used it, though.
I think I've seen some autocompletion plugins show the signature of the method in the popup menu, some others (PHP, Python) open a small "preview" window. That's as far as you can get. There's also <C-w>} if you have an up to date tags file.
Again: Vim is not an IDE.

Make sure that ctags can find the source code that is in the std lib when you generate the index and you should be fine.
By default those index tools only adds code in the current dir (and its subfolders),
so you need to manually tell him where that code is installed on your system.

Related

Automatically format Curly Braces on Same Line in C++ VSCode

I have a problem with the way intellisense autocompletes snippets in VSCode, currently, when I write an if statement, it autocompletes to:
if (condition)
{
// some code
}
However, I would like it to autocomplete to:
if (condition) {
// some code
}
If I use my formatter in VSCode, it formats it to the convention above, however I would like to avoid having to press a separate command for this to occur. Optimally the intellisense snippet would just format it like this by default.
Any help with this would be appreciated.
This is a bigger subject than you might think
So typically with C++, the preferred formatter is the CLang Formatter. CLang's tool is so good, ECMAScript's ESLint has been taking notes, and has implemented many of the same rules found in the CLang formatter, specifically the rules that have to do with brackets.
VSCode has a default formatter that can be used for C++. And this really comes down to what your using.
Problem:
What your asking for, essentially, is for your brackets to be inserted using a certain style, rather than to be auto formatted to a specific style.
Solution
The snippets you are using are obviously predefined, and VSCode supports writing your own snippets.
Like this:
// FILE: #(".../.config/code/user/snippets/cpp.json")
{
"Print to console": {
"prefix": "if(",
"body": ["if($1){\n$2\n}", "$2"],
"description": "If Condition"
}
}
The problem with snippets is: You would need to defined every snippet you use, styling each one.
VSCode Snippets Documentation (official)
Snippet files are extensible, meaning they can be turned into VSCode extensions. Because a snippet library is quick & easy to write in comparison to most other extensions, there are a lot of them available in the Visual Studio Marketplace, and are all 100% Free to download.
You could download a pack that contains the snippets you wont, and then just ad the '\n' line character where needed, throughout the document.
Preferred Solution
It may not be what you want. But the best way to do this, is to do what 90% of C/Cpp developers do who write c/cpp in VSCode; use CLang formatter, and configure VSCode to format your code when you save. I am always hitting CTRL + S because I don't like throwing work down the drain because I forgot to save. And my if statements are all auto formatted exactly as you displayed the example in your question.

I don't know how to open and run sml files with PolyML

I'm completely new to SML and I don't understand what am I supposed to do in order to create, edit, compile and run an sml file with PolyML. I'm using Windows and I don't know if I need to download another IDE, or some developement kit like for Java.
I'd like to create files where some functions are defined and then use them by the terminal.
You can edit your SML code in any programming editor you like. Some have better support for syntax highlighting than others. Finding a good editor is a matter of exploration and personal taste and is not suitable for answering here.
Save your SML code to a file that ends in .sml and do one of the following two:
Either, in the terminal enter the following command:
poly --use yourfile.sml
Or, by first typing poly and inside the REPL type the following:
use "yourfile.sml";

Taking an Input from a C++ Gui into another C++ program

I am currently developing a C++ program that does all the mathematical calculations, prints items to the screen that is scanned in by an RFID Reader, and allows the user to select a payment method. (Basically using RFID tags to replace barcodes)
I have started writing my C++ code for a keyboard entry and have no idea how to take an input from my RFID reader into my program. My RFID Reader is a DLP-RFID1 from it comes with some demo software and drivers. I got it working with windows 7 last week on the demo software(a GUI using Microsoft Visual Studio).
My question is can I take the input from my Demo GUI and some how use that as my input for my C++ program? If I can can some one push me in the right direction by links, pointers, reading material?
Also I have basic C++ experience. I am teaching myself how to program in C++ and right now only know print statements, while loops, switch/case, math functions, and etc.
That is a very specific question about hardware and software of that vendor an not really general knowledge. However, those types of devices, in my past experience with bar code readers and such, usually have a driver that comes with them which allows you to set them up as an actual keyboard (for example, you could even go into a text editor and capture the codes). If you can set them up like that, then reading them is nothing more than reading stdin. For example, cin >> stringVariable;
Assuming that you have demo software in C++:
The demo software should link against one or more libraries that comes with the demo, and include a header that declares the functions in the library. You have to (at minimum) include this header and link against that same library, and use those libraries. The demo will help you understand which functions you need to call and how.
As already said it is very dependent on how they want you to use it but some general guide lines.
Look for header file that came with their demo ( ends in ".h" or ".hpp")
you will need to #include that in your project at the very minimum
Look for a .lib file. you will need to link that to your file. With gcc you would type something like G++ -l[libname].
With MSVS there are two ways i know of. You will need to right click the project in the sidebar. Click something like options or preferences. Expand linker options. Add the library.
or you can type #pragma comment(lib, "filename.lib") in your file near your includes
If there is a .dll (windows) or .so(Linux) file you can dynamically link it. There are many ways to do this. Google search for C++ Dynamic link libraries should be some help. As a newbie try to stick with Static Linking first. that would be another good keyword to search for. The best tutorial on dynamic linking for windows i have found is actually in assembly. but its all Win32 function calls anyways so its not hard to understand. Icz DLL tutorial

C++ vim IDE. Things you'd need from it

I was going to create the C++ IDE Vim extendable plugin. It is not a problem to make one which will satisfy my own needs.
This plugin was going to work with workspaces, projects and its dependencies.
This is for unix like system with gcc as c++ compiler.
So my question is what is the most important things you'd need from an IDE? Please take in account that this is Vim, where almost all, almost, is possible.
Several questions:
How often do you manage different workspaces with projects inside them and their relationships between them? What is the most annoying things in this process.
Is is necessary to recreate "project" from the Makefile?
Thanks.
Reason to create this plugin:
With a bunch of plugins and self written ones we can simulate most of things. It is ok when we work on a one big "infinitive" project.
Good when we already have a makefile or jam file. Bad when we have to create our owns, mostly by copy and paste existing.
All ctags and cscope related things have to know about list of a real project files. And we create such ones. This <project#get_list_of_files()> and many similar could be a good project api function to cooperate with an existing and the future plugins.
Cooperation with an existing makefiles can help to find out the list of the real project files and the executable name.
With plugin system inside the plugin there can be different project templates.
Above are some reasons why I will start the job. I'd like to hear your one.
There are multiple problems. Most of them are already solved by independent and generic plugins.
Regarding the definition of what is a project.
Given a set of files in a same directory, each file can be the unique file of a project -- I always have a tests/ directory where I host pet projects, or where I test the behaviour of the compiler. On the opposite, the files from a set of directories can be part of a same and very big project.
In the end, what really defines a project is a (leaf) "makefile" -- And why restrict ourselves to makefiles, what about scons, autotools, ant, (b)jam, aap? And BTW, Sun-Makefiles or GNU-Makefiles ?
Moreover, I don't see any point in having vim know the exact files in the current project. And even so, the well known project.vim plugin already does the job. Personally I use a local_vimrc plugin (I'm maintaining one, and I've seen two others on SF). With this plugin, I just have to drop a _vimrc_local.vim file in a directory, and what is defined in it (:mappings, :functions, variables, :commands, :settings, ...) will apply to each file under the directory -- I work on a big project having a dozen of subcomponents, each component live in its own directory, has its own makefile (not even named Makefile, nor with a name of the directory)
Regarding C++ code understanding
Every time we want to do something complex (refactorings like rename-function, rename-variable, generate-switch-from-current-variable-which-is-an-enum, ...), we need vim to have an understanding of C++. Most of the existing plugins rely on ctags. Unfortunately, ctags comprehension of C++ is quite limited -- I have already written a few advanced things, but I'm often stopped by the poor information provided by ctags. cscope is no better. Eventually, I think we will have to integrate an advanced tool like elsa/pork/ionk/deshydrata/....
NB: That's where, now, I concentrate most of my efforts.
Regarding Doxygen
I don't known how difficult it is to jump to the doxygen definition associated to a current token. The first difficulty is to understand what the cursor is on (I guess omnicppcomplete has already done a lot of work in this direction). The second difficulty will be to understand how doxygen generate the page name for each symbol from the code.
Opening vim at the right line of code from a doxygen page should be simple with a greasemonkey plugin.
Regarding the debugger
There is the pyclewn project for those that run vim under linux, and with gdb as debugger. Unfortunately, it does not support other debuggers like dbx.
Responses to other requirements:
When I run or debug my compiled program, I'd like the option of having a dialog pop up which asks me for the command line parameters. It should remember the last 20 or so parameters I used for the project. I do not want to have to edit the project properties for this.
My BuildToolsWrapper plugin has a g:BTW_run_parameters option (easily overridden with project/local_vimrc solutions). Adding a mapping to ask the arguments to use is really simple. (see :h inputdialog())
work with source control system
There already exist several plugins addressing this issue. This has nothing to do with C++, and it must not be addressed by a C++ suite.
debugger
source code navigation tools (now I am using http://www.vim.org/scripts/script.php?script_id=1638 plugin and ctags)
compile lib/project/one source file from ide
navigation by files in project
work with source control system
easy acces to file changes history
rename file/variable/method functions
easy access to c++ help
easy change project settings (Makefiles, jam, etc)
fast autocomplette for paths/variables/methods/parameters
smart identation for new scopes (also it will be good thing if developer will have posibility to setup identation rules)
highlighting incorrect by code convenstion identation (tabs instead spaces, spaces after ";", spaces near "(" or ")", etc)
reformating selected block by convenstion
Things I'd like in an IDE that the ones I use don't provide:
When I run or debug my compiled program, I'd like the option of having a dialog pop up which asks me for the command line parameters. It should remember the last 20 or so parameters I used for the project. I do not want to have to edit the project properties for this.
A "Tools" menu that is configurable on a per-project basis
Ability to rejig the keyboard mappings for every possible command.
Ability to produce lists of project configurations in text form
Intelligent floating (not docked) windows for debugger etc. that pop up only when I need them, stay on top and then disappear when no longer needed.
Built-in code metrics analysis so I get a list of the most complex functions in the project and can click on them to jump to the code
Built-in support for Doxygen or similar so I can click in a Doxygen document and go directly to code. Sjould also reverse navigate from code to Doxygen.
No doubt someone will now say Eclipse can do this or that, but it's too slow and bloated for me.
Adding to Neil's answer:
integration with gdb as in emacs. I know of clewn, but I don't like that I have to restart vim to restart the debugger. With clewn, vim is integrated into the debugger, but not the other way around.
Not sure if you are developing on Windows, but if you are I suggest you check out Viemu. It is a pretty good VIM extension for Visual Studio. I really like Visual Studio as an IDE (although I still think VC6 is hard to beat), so a Vim extension for VS was perfect for me. Features that I would prefer worked better in a Vim IDE are:
The Macro Recording is a bit error prone, especially with indentation. I find I can easily and often record macros in Vim while I am editing code (eg. taking an enum defn from a header and cranking out a corresponding switch statement), but found that Viemu is a bit flakey in that deptartment.
The VIM code completion picks up words in the current buffer where Viemu hooks into the VS code completion stuff. This means if I have just created a method name and I want to ctrl ] to auto complete, Vim will pick it up, but Viemu won't.
For me, it's just down to the necessities
nice integration with ctags, so you can do jump to definition
intelligent completion, that also give you the function prototype
easy way to switch between code and headers
interactive debugging with breaakpoints, but maybe
maybe folding
extra bonus points for refactoring tools like rename or extract method
I'd say stay away from defining projects - just treat the entire file branch as part of the "project" and let users have a settings file to override that default
99% of the difference in speed I see between IDE and vim users is code lookup and navigation. You need to be able to grep your source tree for a phrase (or intelligently look for the right symbol using ctags), show all the hits, and switch to that file in like two or three keystrokes.
All the other crap like repository navigation or interactive debugging is nice, but there are other ways to solve those problems. I'd say drop the interactive debugging even. Just focus on what makes IDEs good editors - have a "big picture" view of your project, instead of single file.
In fact, are there any plugins for vim that already achieve this?

Is it possible to customize the indent style of XCode?

For example, I'd like to not indent namespaces in C++ code, but the prefpane doesn't seem to have any place to make a decision of this granularity. Is there some hidden config file or something? Or am I just out of luck?
Apple's XCode documentation contains a full list of user preferences, many of them that don't have a corresponding UI. I'm not seeing anything that is namespace-specific however, so I think you might be out of luck.
However, I thought I'd pass along the preferences list in case it's useful.
I've also attempted to do this.
The answer is that whoever did the code formatting in XCode appears to be completely unaware that there are languages other than Objective C, or coding styles other than Apple's.
Here's a list of things that one would want to do that can't be done in XCode.
Indent public: or private: just one space.
Indent namespaces zero spaces.
Alternate indentation for arguments NOT relative to the opening parenthesis.
The last one needs a little discussion. Sometimes, a function or method name can be quite long, as well as its first argument, so you want also to be able to indent like this:
someExcitingClass->AVeryLongMethodNameTraLaLaLaLa(
someLongExpressionOrVariableNameGoesHere,
anotherNameHere);
Of course, you might want to be extracting subexpressions to make the line shorter, but in real-world code this comes up all the time, and creating subexpressions just to fit everything into a reasonable line length is annoying.
It's a terrible shame and I really have no idea what to do. I personally write in emacs and only dip into XCode as a build system but :-D that's not for everyone.
As the Xcode indenter uses just the lexer, and not the AST, you can 'fool' the formatting by defining away the curly braces.
I have:
#define NAMESPACE_OPEN(_name) namespace _name {
#define NAMESPACE_CLOSE(_name) }
#define dsmsg_namespace_open NAMESPACE_OPEN(dsmsg)
#define dsmsg_namespace_close NAMESPACE_CLOSE(dsmsg)
i.e., a generic 'NAMESPACE_OPEN/CLOSE' define, and a define specific to my most-used namespace 'dsmsg'. Then, whenever I want to open the namespace, I use
dsmsg_namespace_open
... code ...
dsmsg_namespace_close
Ugly hack, but I quite like having a specific, named 'close'
I bypass Xcode's indenting altogether, and have a user script that calls uncrustify on the currently displayed document.
#!/bin/sh
#echo -n "%%%{PBXSelection}%%%"
uncrustify -q -c ~/.uncrustify/sample.cfg -l oc+
#echo -n "%%%{PBXSelection}%%%"
Notes:
uncrustify must be in your PATH
you may need to adjust the location of your config file
if you want to have the new code selected in Xcode, uncomment the two echo statements (this can also be used to make a "Format Selection" script, rather than "Format All"
Script Settings:
Input:Entire Document
Directory: Home directory
Output: Replace Document Contents
Errors: display in alert
As of Xcode 4.3.1 no custom namespace indent options are available, however I overcame this irritation by navigating to Preferences->Text Editing->Indentation and disabling "Syntax-aware indenting".
Another possibility is to use Articstic Style (astyle). A tutorial how to integrate astyle into XCode using automator and services can be found here: http://eatmyrandom.blogspot.com/2011/03/xcode-astyle-part-2-for-xcode-4x.html and http://youtu.be/d8bbE6_OHGc