How to fix indentation in Systemverilog source - indentation

I am using systemverilog very often.
I am using UltraEdit as text editor. I use also VIM.
Sometimes I have to copy code from some other places and paste it into my code.
It may not be indented properly. It is a difficult task to indent it properly again.
Can anybody suggest any method or tool to do it easily?

Method
Visit EDA Playground
Paste your code into one of the editor windows
Select all text with CTRL-A
Reindent all text with SHIFT-TAB
Some backgroud
There is a Verilog mode for Code Mirror which supports SystemVerilog. CodeMirror is an in-browser text editor written in JavaScript which is used on a number of websites, including EDA Playground.
You could also paste and reindent in the example window here, or you could download it yourself and run it locally.

The verilog mode in Emacs supports indentation, so you can open your file in Emacs (from the command line, run emacs file-name.v, select all by pressing Ctrl+H, then reindent by pressing TAB and save with Ctrl+S.

UltraEdit has command ReIndent Selection at bottom of menu Format.
All lines of a selection of any type of text file can be re-indented (not reformatted, i.e. not inserting line breaks or removing line breaks) with this command as long as
the file is syntax highlighted based on a wordfile (*.uew) suitable for type of text file,
the syntax highlighting wordfile contains appropriate indent/unindent string definitions.
Therefore it is no problem to re-indent code after paste by selecting pasted block and use the command ReIndent Selection with a good syntax highlighting wordfile for SystemVerilog.
The syntax highlighting wordfile currently used for active file can be opened for editing or improvement by clicking on button Open left of language list box preselected according to used syntax highlighting for active file at Advanced - Setttings or Configuration - Editor Display - Syntax Highlighting.
The lines of interest in the wordfile regarding indent/unindent start with
/Indent Strings =
/Unindent Strings =
/Ignore Strings SOL =
More information about those three lines can be found
in help of UltraEdit on page Syntax Highlighting,
in online help on page about wordfiles, and
in user forum topic template for syntax highlighting language wordfile.
A user contributed syntax highlighting wordfile for SystemVerilog can be downloaded from wordfiles page.
Note: As command ReIndent Selection is a basic command for all languages, it is not as smart as tools written to re-indent or even reformat source files written for specific languages with true language intellisense like Artistic Style for C / C++ / C# and Java (also supported built-in by UE).

Related

Excessive cursor reference highlighting VS Community

so I have been using VS Community for a while now to code in c++ and somehow must have activated reference hightlighting. Now every time my cursor is inside a word it highlights every occurence in the entire file. This gets very confusing especially inside nested loops:
I tried looking for reference highlighting but could only find it in the C# section in the options.
I also tried changing the background color of the highlight to the background color of the plain text but this still draws the rectangle highlight box around it.
Is there no way to disable this cursor highlighting for c++? Basicly I only want the highlight to show when I actually hightlight stuff.
If you want to disable all cursor highlighting, you could set True in Tools->Options->Text Editor->C/C++->Advanced->References->Disable Reference Highlighting.
If you want to customize the cursor highlighting, here is a solution for reference.
This tip was proposed by Sairama Jamalapuram. Syntax coloring for user-defined keywords is used for C++ files only.
Here are the steps you need to take to enable syntax coloring for user-defined keywords. The steps are taken from the online help.
In the same directory as msdev.exe (for Visual Studio .Net search
for ...\Microsoft Visual Studio.NET\Common7\IDE\devenv.exe), use the
Text editor or Windows Notepad to create a text-only file named
usertype.dat.
Add your keywords to usertype.dat, one keyword per line. Note: The
usertype.dat file is read during initialization. It cannot be
renamed, nor can it be reloaded during an editing session. The
syntax coloring mechanism checks the usertype.dat file last. Thus,
all previously defined color settings take precedence over the
user-defined keywords.
Save the file as a text-only file, exit, and then restart Visual
Studio.
From the Tools menu, choose Options.
Select the Format tab.
In the Colors box, select User Defined Keywords.
Set the font, font size, foreground color, and background color to
your preferences.
Click OK.
Restart DevStudio.

How to make Vim format C++ code automatically as I type

I have setup clang-format to reformat the current line/selection when I press Ctrl-K in Vim (see the official documentation how to do that). However, it's annoying to be constantly pressing Ctrl-K whenever I edit a line.
Is there a way to make Vim call clang-format as I type or edit code automatically, without me having to press Ctrl-K? In other words, probably after each key stroke in insert mode?
I haven't seen anybody setup vim this way --- what are the potential problems with this setup?

Vim isnt highlighting basic types in c/c++

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.

Can WebStorm automatically format the code when I am writing?

In Visual Studio when I type some special characters like ;} it will automatically format related code segment, but in WS, nothing happens. I tried to find that option but ended without fruits.
// e.g. In VS, if we type something like:
var abc=123
// and then type ; it will be formatted as:
var abc = 123;
I am trying to understand why many people love WebStorm as a JS IDE. :)
PC: Ctrl + Alt + L
MAC: Command + Alt + L
Here you can find a nice tutorial by John Lindquist: http://www.youtube.com/watch?v=xIxDar8CbJA
This option is provided in WebStorm 8 (coming soon) - see IDEA-120066
Haven't used VS recently so I'm not sure what ;} does, but WebStorm can definitely expand templates. Above a function declaration, try typing /** and then Enter, for example - WebStorm will automatically generate a JSDoc heading.
Look also in the IDE Settings under Live Templates -> JavaScript. Typing us<Enter> will insert a "use strict;" etc.
If you want to reformat code, there's an option under Code -> Reformat Code to reformat the selected text (or the entire file). Though probably it's best to get used to writing code abiding by JavaScript style guidelines :) Comes in handy when you don't have an IDE at hand, e.g. editing on GitHub, in a terminal, on StackOverlfow (cough) etc.
Also, you should enable JSHint, which would highlight abc=123 as needing style improvements.
select Code > Reformat Code from the main menu, code formatting popup will appear.

Eclipse copy code with syntax highlighting

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.