I'm writing a document of programming guidelines for my developers team. I use MS Word. We work with Eclipse CDT (C++). I need to copy-paste C++ code with syntax highlighting from Eclipse to Word. I've tried Notepad++ and it can export text with syntax highlighting, but it's highlighting is limited to basic syntax (it doesn't know about defined class, enum etc...).
Eclipse syntax highlighting is very powerful and I wish to export directly from Eclipse to Word using it's syntax highlighting.
Is there any Eclipse plugin that achieve this purpose? Or some trick to do it (without taking a screen snapshot)?
When you copy the code to word document, you can choose the option "keep source formatting" and the highlighting will be the same as the one in eclipse.
EDIT:
As mentioned in the comments below, this won't work on folded code, so you can right click on the line numbers and select Folding > Expand All
EDIT 2:
Also mentioned in the comments, as of eclipse oxygen, the code is automatically copied with syntax highlighting
When I copy from Eclipse straight to PowerPoint some of the formatting is messed up. Bold and color seems to "keep going". But if I copy from Eclipse to Word -- and then from Word to PowerPoint (with the keep source formatting CNTRL-K) -- the formatting is correct. I recently upgraded Eclipse to Mars and Office to 2013. I still have to go through Word first.
I was trying it too and for some reason not every compile unit would keep the formating.
After a while I've seen that you also won't get the formating kept if there are parts of the code hidden, so for the ones that cannot make it work with the answers above, just make sure that there are no "+" signs on the left of your code (mine were where the imports at the beggining).
Copying of formatting is supported since version 3.2
Note that everything is copied: highlighting of spelling errors, marked variables/types/etc and underscoring of warnings/errors.
To avoid that, turn off spell checking, "Mark Occurrences" and "Report problems as you type" respectively.
Related
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 have recently started using vim and i see my syntax files are located in /usr/share/vim/vim74 (I'm on linux Mint) and my c.vim seems to make the basic things like int and double keywords however when I edit any c or c++ files none of the types are highlighted however some things like const are highlighted. I am not sure why this is happening. Can anyone help me out?
To check whether the syntax parsing works as expected, check (when editing a C / C++ file) with
:syntax list
that those keywords (like int) are defined. You'll also get a preview of the highlight coloring there. Alternatively, the colors are shown via
:highlight
To change those, you have to switch to another :colorscheme or edit / augment the current one.
For advanced troubleshooting, I recommend the SyntaxAttr.vim - Show syntax highlighting attributes of character under cursor plugin.
I'm using VS2012 and I'm quite happy with it. But the problem is, whem I'm coding in C++, that the syntax highlighting is turning off an on all over again. Sometimes, the highlighting is off and I have to reload the file. Also, it highlighting is quite slow.
Does anyone know how to fix it?
I know this is a while ago but I have had this same problem appearing randomly until just now.
It would disable when the last line in a file was a single line comment. (// blah blah). As soon as i removed that the text highlighting worked again!
Edit: In this answer I assume that your problem description is correct. In other words, I'm assuming that occasionally C++ highlighting is working, and the other times the text appears as plain text: completely black and white.
My guess is you are using an extension which modifies or replaces the way Visual Studio highlights C++ code. Try temporarily disabling all of your extensions and checking again if the editor is working. Some extensions might have the Disable button disabled; in that case you'll need to uninstall the extension for this test (possibly through Control Panel → Programs and Features).
As an example of one common extension that completely replaces the C++ highlighter is Visual Assist. However, I do not personally use that product and I haven't heard of any specific problems with it of this nature. I am merely mentioning it as an example of an extension that completely changes the behavior of Visual Studio in regards to syntax highlighting of C++ code.
For me, highlighting always stops working when the first visible line in the editor begins with the characters '//' and I trigger reparsing somehow (CTRL + S for instance).
Highlighting always works fine when the first visible line in the editor begins with anything else, even with a whitespace, and I trigger reparsing somehow.
I could indent all my comments and never experience this problem, but now that I know about it, it's not so annoying anymore, so I let it be.
This is a bug in Visual Studio 2012:
https://connect.microsoft.com/VisualStudio/feedback/details/760154/syntax-highlighting-sometimes-not-working
If you're using only Intellisense, you may go to Edit->Intellisense->Toggle Completion Mode (or hit Ctrl + Alt + Space), play with it and see if it works (maybe you've pressed this combination of keys by accident).
I've also installed Update 3 and haven't had any problems since. Who knows..
I had the same problem. Disabling the extentions sadly did not work for me.
After searching around and realizing that it only happened on larger files,
I got it to work by turning harware acceleration off.
Tools->Options...->Environment->General
*Automatically adjust [...] (off)
*Use hardware graphics acceleration (off)
In my case, it turned out that a large block of code (a 200+ line method) was commented out with // starting in the first column, and this was causing the syntax coloring not to work. I changed the commenting delineation to /* ... */ for that method and all of the syntax coloring was fixed.
Personally, I found that things like:
#if 0// bla-bla
mess up syntax highlighting badly. The solution that works for is to put a space before a comment, like so:
#if 0 // bla-bla
I installed Visual Studio 2012 Update 3 yesterday and started experiencing the exact same behavior described in the original post. Based on some suggestions in this thread, I took at look at my extensions, and disabling AllMargins fixed the issue. I've since re-enabled AllMargins and everything appears to be working as it should.
Try disabling and re-enabling any of your extensions; hopefully that will fix the issue for you.
1) Are there any Geany users here who have gotten good syntax highlighting for Scala?
2) What should I do about syntax highlighting when I'm editing (Mako) templates that are generating things other than HTML/CSS/JS? (say, C/C++ code, or w/e) Is good syntax highlighting too much to ask out of Geany in this case (or any other editor, for that matter)?
I just wanted to chime in to note that the latest version of geany (1.22) does have syntax highlighting for Scala - it's rudimentary, but it will at least highlight comments and a few keywords. Annoyingly, the support is initially only activated for files named Foo.scl, rather than using the standard convention of Foo.scala, but this can be changed by modifying /usr/share/geany/filetype_extensions.conf (the format is pretty obvious).
i just wanted to know if there is an easy way to tell Eclipse (Helios Service Release 1) that every line in my code which is part of an assertion should be highlighted in a chosen color.
I'm aware of the fact, that assertions could be arbitrarily complex, so that parsing is needed. But maybe Eclipse supports something like "highlight all occurences of this function" out of the box.
Thanks.
Sascha