Custom ABAP Code Folding in ABAP for Eclipse - visual-studio

I'm trying to find out if Code Folding in Eclipse is possible.
(I dont mean the automated Folding for Source Code by the way)
Is there something like the equivalent in Visual Studio?
#region Region1
'Sample Code
#endregion
Would love to hear from you

This region feature used to exist in the ABAP editor of the ABAP Workbench (SAP GUI), but I didn't see this option in Eclipse ADT. I guess it became useless since the SAP recommendation is to write short methods.
If you really need to use regions, you may use the old ABAP editor (transaction codes SE24, SE37, SE38, SE80...) from Eclipse ADT, by first editing the ABAP code as usually, switch to the SAP GUI via the context menu Open with > SAP GUI, then write the regions this way:
"$. Region region-name followed by an optional text and a final dot.
ANY ABAP CODE
"$. Endregion region-name followed by a final dot.
Regions have a number of rules: their names must not contain spaces, are case-insensitive, they must not "cut" an ABAP block (like IF...ENDIF) in the middle, they may be nested, etc.

Related

Is there a way to have Xcode auto-align variable names like in Apple's example code?

Apple's example projects often have the variable names aligned, in addition to their type specification/general code indentation:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
As opposed to:
NSUInteger level;
double fadeSpeed;
CGPoint ballPosition;
int keyOffset;
Is there a shortcut to make this happen? (I don't know what it would be called or else I could search the docs for it.)
It sounds like you're looking for Uncrustify. I've not used it in anger myself, but the feature list seems to include your requirement:
Features
Ident code, aligning on parens, assignments, etc
Align on '=' and variable definitions
Align structure initializers
Align #define stuff
Align backslash-newline stuff
Reformat comments (a little bit)
Fix inter-character spacing
Add or remove parens on return statements
Add or remove braces on single-statement if/do/while/for statements
Supports embedded SQL 'EXEC SQL' stuff
Highly configurable - 412 configurable options as of version 0.59
The popular pretty-printer uncrustify has at least a dozen different variable alignment parameters that you can specify in its config file. Tony Arnold's project shows you how to use uncrustify as an automator service (which means that you can access it from Xcode or any other editor). Robert Payne suggests using it from a shell script that you can incorporate into your build process.
My guess is that Apple runs its examples through uncrustify or some other pretty-printer before publishing so that they're all formatted using a common style. It may take some fiddling if you want to exactly reproduce Apple's style, but at a minimum it should be pretty easy to get your variable declarations to align the way you want. It's been a while since I played with all the options, but I'd start by looking at the align_var_def_span, align_var_def_thresh, and align_var_def_gap settings.
I don't know whether there is already a shortcut, but you can create a program which accepts a big string as input (variables) and the output would be the aligned version of this. Writing this program should not cause too many problems.
There is no built in function in Xcode to do that automatically, however you can easily align variable names with tab . You have to press tab after the type multiple time and align to the same width .

Auto-completion in Textmate for Ruby?

I'm really used to auto-completion coming from Netbeans.
In Netbeans, when I type a 'string' and then hit a 'dot' it will print out a list of methods for the String class.
TextMate doesn't seem to have that function.
Is it something you could add?
Would save A LOT of time instead of using the ri/irb/online doc all the time.
Install the Ruby TextMate bundle, open a Ruby file and type alt+esc to get the autocompletion.
You have discovered the fundamental difference between a text editor and an IDE: a text editor edits text (duh!), i.e. an unstructured stream of characters. It doesn't know anything about objects, messages, methods, mixins, modules, classes, namespaces, types, strings, arrays, hashes, numbers, literals etc. This is great, because it means that you can edit anything with a text editor, but it also means that editing any particular thing is harder than it were with a specialized editor.
A Ruby IDE edits Ruby programs, i.e. a highly structured semantic graph of objects, methods, classes etc. This is great, because the IDE knows about the rules that make up legal Ruby programs and thus will e.g. make it impossible for you to write illegal Ruby programs and it can offer you automated transformations that guarantee that if you start out with a legal Ruby program, you end up with a legal Ruby program (e.g. automated refactorings). But it also means that you can only edit Ruby programs.
In short: it's simply impossible to do what you ask with a text editor. You need an IDE. (Note: you can of course build an IDE on top of a text editor. Emacs is a good example of this. But from what I have read, the TextMate plugin API is simply not powerful enough to do this. I could be wrong, though – since I don't have a Mac, I'm mostly dependent on hearsay.)
TM's "equivalent" is hitting escape, I believe.
You can make escape "go across files" for completion if you use the ruby amp TM bundle http://code.google.com/p/ruby-amp/
GL.
-r

Eclipse CDT and ESQL syntax errors

I am using Eclipse CDT (Helios release) to edit the source code of an (old) C application, which also uses ESQL. In this project, by convention, files containing ESQL code have a .sc extension (instead of the default .c)
All ESQL sections e.g. starting with EXEC SQL keywords are flagged as “syntax error” (vertical ruler, overview ruler and amber squiggly line). The actual compilation is performed on a different machine (Unix), which has the ESQL compiler. What can I do to check the syntax of the SQL code on the development machine?
Note: I can hide the notification from Preferences / General / Editors / Text Editors / Annotations / C/C++ Indexer Markers but this may hide possible useful warnings.
What you have isn't C code, in spite of what you might think.
Extra "syntax" (e.g, EXEC SQL plus whatever is inside) simply isn't C code, and any tool that processes conventional C code will by necessity reject it as a syntax error.
The "ESQL processor" (sounds like a mainframe given the EXEC SQL phrase) probably preprocesses what you are thinking of a C code to extract the SQL and replace it by function calls; that result is likely fed off to a real C compiler.
I doubt you can do anything useful with this using CDT.
If you use the Window->Preferences->C/C++->File Types and define a new file type with C or C++ as *.pc, or *.sc etc. as is appropriate to your extension, then the syntax highlighter will attempt to colour the keywords appropriately and provide hover tips. Of course the EXEC SQL type statements will show up as errors but those are relatively easy to ignore knowing that you're looking for some help for the elements in the file, but not all (i.e. doesn't parse embedded SQL).
Update (for vi(m) lovers): I found that I needed to create a file in ~/.vim/ftdetect/pc.vim containing:
au BufRead,BufNewFile *.pc set filetype=pc
and I also created a link from my /usr/share/vim/vim73/esqlc.vim to pc.vim (though we could have specified *.pc set filetype=esqlc)
and I installed vrapper, then after restarting eclipse, I my EXEC SQL or other keywords were no longer underlined, though they weren't colourized either. That may change in future vrapper updates. (Note: I'm using Eclipse Kepler as it supports vrapper)
Bonus: make sure to set your preferences for "Find and Replace" to CTRL-4 instead of CTRL-F to get page forward in vim working.

Performing expression evaluation/reduction in Visual Studio 2008

Is it possible to get Visual Studio to do mathematical expression evaluation/reduction?
For example if I type '-0.005 + -0.345' how do I get Visual Studio to reduce that (i.e. replace it with the reduction)? Do I have to write a macro? If so, are there any pre-existing macros to do this type of expression reduction?
Just to be clear, I want to be able to highlight an expression and have it replaced with the reduced result. Many are suggesting the immediate window but I fail to see how that will suffice?
Edit I should point out that this is while editing not running or debugging. The immediate window is of little to no use. I also consider this a language neutral question. I would certainly be interested in seeing alternative macros to the one I had posted.
Edit Going Once... Going Twice... (i.e. any other suggestions before I consider accepting my own answer?)
Thank you for the above answers.
There probably are better ways, but here's a quick and dirty macro that does what I need.
References to the System.Data and System.XML namespaces need to be added.
Highlight the expression you want to evaluate and run the macro (it uses the calculated column in the DataTable to evaluate the expression.) It will replace the expression with the reduced result.
Edit - Updated code below. It worked extremely well for reducing a large number of expressions. As pointed out by others there is the immediate window but this will not work for editing purposes. This macro is a language independent solution for basic expressions "(), +, -, *, /".
Sub Eval()
Dim ts As EnvDTE.TextSelection = DTE.ActiveDocument.Selection
Using dt As New DataTable()
dt.Columns.Add("Expression", GetType(Double), ts.Text)
dt.Rows.Add(dt.NewRow)
ts.Text = CDbl(dt.Rows(0).Item("Expression"))
End Using
End Sub
Visual Studio by default will not do any mathematical expression evaluation / reduction. I'm not sure if you can get support for that via items like ReSharper, but if it is available it will be in an add-in.
Also, it would be helpful to know the language you are working in?
Some languages may be helpful in this area. F# for instance makes it easy to evaluate expressions in the IDE via the interactive window and will display out the result. This could easily be added back into your code but it doesn't appear to be exactly what you're looking for.
Here's an answer: Yes, it is possible using the following steps. (While technically performing what you're asking for, I'm not sure it will be extremely useful. :-)
Set a breakpoint in your program that's likely to get hit when you debug the program.
Then, run your program under the Visual Studio debugger.
When the breakpoint is hit, open the Watch window.
In the Watch window, add a new watch by clicking in the Name column.
Enter your expression '-0.005 + -0.345' (without the quotes) then hit [Enter].
... You should see the Value column get populated with -0.35.
Of course, that isn't in the context of the editor window ... which is, presumably, where you'd want to perform the reduction. So again, not very useful, I imagine. An add-in is the likely way to do that in the editor window.
You could just go to the immediate window and type "?<yourExpression>"

Macro expansion in Visual Studio macro or add in

I have a VS project with an IntermediateDirectory like this: "....\temp\$(SolutionName)\$(ProjectName)".
I can read this value using a macro or add in, however, I would need the actual directory to manipulate files there. Right now, I manually replace the "$(SolutionName)" and "$(ProjectName)" with the respective values, which works fine but might become complicated when different macros or even user macros from property sheets are used.
So my question is:
Does the Visual Studio API have a built in function to expand macros like these? Or is there some other elegant solution?
There is an elegant solution! But I only know the one that applies to C++ projects.
Assuming you're in a C# add-in:
// Get the main project from the first startup project
VCProject vcMainProject = (VCProject)(_applicationObject.Solution.SolutionBuild.StartupProjects as IVCCollection).Item(1);
Project mainProj = (Project)_vcMainProject .Object;
// Get the configuration we'll be using
IVCCollection cfgs = (IVCCollection)_vcMainProject .Configurations;
VCConfiguration vcCfg = (VCConfiguration) cfgs.Item(mainProj.ConfigurationManager.ActiveConfiguration.ConfigurationName + "|" + mainProj.ConfigurationManager.ActiveConfiguration.PlatformName);
string finalString = vcCfg.Evaluate("....\temp\$(SolutionName)\$(ProjectName)");
You can also check out this page:
http://msdn.microsoft.com/en-us/library/czt44k0x%28VS.71%29.aspx
If you're not using this for C++, there should be a similar interface for the Project, Configuration, and Solution classes provided for other languages (C# and VB).
As far as i know, there is no API available that will expand those macro values. Although it shouldn't be too hard to write a quick and dirty implementation that deals with only the values that you care about.
For instance, in this case you only care about 2 values (SolutionName and ProjectName). If these are the values you are primarily interested in use a simple search and replace with the best values.
Yes this is a sub-optimal solution. But it may help to unblock your progress.

Resources