It seems the EOL style in our current project isn't consistent. I'm looking for a Visual Studio plugin/extension to show the EOL style in the currently opened file as either LF, CRLF or Mixed.
try to used the below codes
Dim TextLine As String
FileOpen(1, "TESTFILE", OpenMode.Input) ' Open file.
Do While Not EOF(1) ' Loop until end of file.
TextLine = LineInput(1) ' Read line into variable.
Debug.WriteLine(TextLine) ' Print to the Command window.
Loop
FileClose(1)
Not exactly what you looking for, but there is a build-in feature:
Tools -> Options
Environment -> Documents -> Check for consistent line endings on load
Related
We are using Visual Studio (2017) in a project (one solution) with two different configuration types: DynamicLinkLibrary and Makefile. The Makefile configuration is controlled by the maekfile of a third party compiler (Greenhills for Embedded Applications), DynamicLinkLibrary of course runs Visual Studio internally. The Makefile configuration uses the elements of the Visual Studio NMake template, for the compiler call itself there are these command lines, in which a batch file is called with transfer parameters
$(ProjectDir)..\mm.bat PLL02#$(MSBuildProjectName) bin_comp 3 LIBYES 2 /F DIAGNO
mm.bat is the batch control with seven parameters for the Greenhills compiler.
In case of a compiler error in our source code, detected by the third-party compiler, we would now like to activate a comfortable ErrorParser, which loads the corresponding source code file by double-clicking on the erroneous line in the VisualStudio output window into the source code editor window of Visual Stuido and automatically places the cursor there on the erroneous line of code. If Eclipse is used as our second IDE for our Makefile project, this works very well via a Regex control ('Regex Error Parser'). However, this does not work in Visual Studio. Is it even possible to do this directly from the output window? Does anyone have any advice here? Roughly speaking, is it at all possible to trigger an action from the Visual Studio output window by double-clicking (in the sense that the clicked line is 'read' by the output window for further processing; the further processing should ultimately display the erroneous source code line).
Best Regards, Roger
P.S.
Here is shown, what I like to know:
Situation in error case
I don't believe that you can make VSS understand other formats than its own.
But there is another way that works.
Format the error output of your compiler into the VSS format and put it out in the output window off VSS.
The VSS Error format ist:
d:\MyProg\main\Sourcefiles\myModul\src\myFile.c(2426): error C2039:
Maybe you have a format like this from your compiler to change to the VSS format:
d:\/MyProg\main\Sourcefiles/myModul/src/myFile.c", line 2426: error #136:
struct "_Ts_braketest" has no field "braketest_stepx"
S_btest.braketest_stepx = 2520;
^
The stream editor sed does a good job for such a task.
For a simple way you can format step by step with a command file for sed.
command file socToVss.sed:
s,\\/,\\,g #replace \/ to \ (delimiter , to prevent escaping slash)
s,\/,\\,g #replace / to \ (delimiter , to prevent escaping slash)
s/\"//g #replace " to nothing
s/c,[[:space:]]line[[:space:]]/c(/g #formating line number
s/\(([0-9]*\):/\1):/g #formating line number
s/\(error[[:space:]]\)#\([0-9]*\)/\1C\2/g #formating error number
Example for your makefile to use the sed command file to format the errors from errors.txt to errorsVssFormat.txt and type ist out:
make 2> errors.txt
sed -f socToVss.sed errors.txt > errorsVssFormat.txt
type errorsVssFormat.txt
You can use the Open Source GNU utilities for Win32
[http://unxutils.sourceforge.net/]
Good luck with your job ;-)
I made a git hook that checks my code style before commit. It passes the staged files to CodeSniffer. I use the PSR-2 code style which means newlines should be \n even on Windows. However even after changing PhpStorm settings and git settings it still gives me the error that the newlines are \r\n. Why does this happen?
PhpStorm
Searching for \r\n with regex on does not return instances, so I believe the problem to lie with git.
.gitconfig
[core]
autocrlf = false
editor = \"C:/Program Files (x86)/GitExtensions/GitExtensions.exe\" fileeditor
eol = lf
[user]
name = Thomas Moors
email = thomas.moors#*****.nl
[merge]
tool = kdiff3
[mergetool "kdiff3"]
path = C:/Program Files (x86)/KDiff3/kdiff3.exe
[diff]
guitool = kdiff3
[difftool "kdiff3"]
path = C:/Program Files (x86)/KDiff3/kdiff3.exe
The error
Transcription:
FILE: ...\Thomas\Documents\example-live\laravel\app\Models\DoMdokUser.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
1 | ERROR | [x] End of line character is invalid; expected "\n" but
| | found "\r\n"
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
Time: 105ms; Memory: 4Mb
Fix the error before commit please
edit: using another editor (n++) the problem does seem to lie with phpstorm. Replacing \r\n fixes the problem. So why does PHPStorm not work properly?
Searching for \r\n with regex on does not return instances, so I believe the problem to lie with git.
Not necessarily with git.
IDE (PhpStorm) stores all lines in memory with normalized line separator (which is \n / LF) and when you saving the file it replaces them with actual line separator symbol detected on file opening. This also means that if you happen to have mixed line endings in one file (e.g. both CRLF and LF) .. after save it will use only one style (e.g. only LF).
Normalized line ending allows you to execute your regex searches/replaces in a bit more simpler way -- no need to worry about what the actual symbol is.
Now -- the Code Style settings page -- as you can see in that hint below the field, it says: "Applied to new files". This means that this setting does NOT affect existing files in any way.
To change line ending for a particular existing file: open the file and either change it via appropriate section in Status Bar .. or via File | Line Separators
So why does PhpStorm not work properly?
It works properly -- you just happen to not know how to change the line separator style.
Because of all the sub-directories my code typically lives in, whenever I do a Find In File for something, the code gets run off the screen because the results window has wasted so much valuable real estate by repeating the long file path for every object in my solution. More often than not, they are in the same parent directory, or I don't really care where there from.
Is there an option to shorten the path name to perhaps just the file?
Also, the Display File Names Only option in the Find in Files dialog does not do this, it only omits the code from the result.
You can change the VS search result formatting by changing the registry.
According to the article Customize how Find in Files results are displayed in the Find Results Window:
Open up RegEdit
Go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Find
Add a new string called Find result format with a value of $f$e($l,$c):$t\r\n
DANGER: This involves hacking the Registry so use this tip at your own risk!
Further, here's the syntax to use if you'd like to customize the string further:
Files
$p - path
$f - filename
$v - drive/unc share
$d - dir
$n - name
$e - .ext
Location
$l - line
$c - col
$x - end col if on first line, else end of first line
$L - span end line
$C - span end col
Text
$0 - matched text
$t - text of first line
$s - summary of hit
$T - text of spanned lines
Char
\n - newline
\s - space
\t - tab
\\ - slash
\$ - $
Things are different on Visual Studio 2017. You won't find the registry keys for Visual Studio 2017 anymore as Visual Studio 2017 now stores registry keys in a private binary file under %VsAppDataFolder%\privateregistry.bin.
However, according to this link, there is still a way to find and modify registry keys for Visual Studio 2017.
Close Visual Studio 2017
Open regedit
Select HKEY_LOCAL_MACHINE from the left bar
Select File > Load Hive...
Load the privateregistry.bin file from %localappdata%\Microsoft\VisualStudio\15.0_[instanceid]{RootSuffix}\privateregistry.bin. The RootSuffix for a normal VS installation will be blank. This is mostly used for the experimental instance
Name the key whatever you want (e.g. "VS2017") when prompted
From there, you should be able to view the entries just like any normal registry.
Customise it according to accepted answer's suggestions.
Important! Once you're finished, you need to make sure that you "Unload" the private registry, by selecting the "root" key ("VS2017" in this example) and selecting File > Unload Hive . If you don't do this, VS won't be able to read the privateregistry.bin file when it runs, causing major problems.
Update:
It also works on Visual Studio 2019 (version 16.0) too.
There is an option you can select "Find results table".
Then you can do a Ctrl+ALL and copy the tab delimited results to a spreadsheet such as Excel. Then you can see only the code instead of file names.
How does one enforce a newline at end of file in RubyMine (v 4.5.3, on Mac OS)?
e.g., similar to Sublime Text 2
Enable Ensure blank line before end of file on Save option in the Editor settings:
In RubyMine 6 or above (on Mac OSX):
Enable 'Ensure line feed at file end on Save' option in the Editor settings.
RubyMine 2021.2
"Ensure every saved file ends with a line break"
RubyMine alongside many other editors supports the EditorConfig standard for basic configuration.
You can enforce newlines at the end of every file by placing a file named .editorconfig at the root of your project:
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
It's possible to disable the setting for specific file types or filenames.
In RubyMine 2016.2.1 you have to go to Preferences > Editor > General > Other > Ensure line fedd at file end on Save.
Screenshot of the Preferences in RubyMine 2016.2.1
There's a "tabify" command in
Edit > Advanced > Tabify Selected Lines
(and the Power Tools 2010 also provide this functionality on a per-file basis) but is there a way to do this for all code files in a solution?
ReSharper has a Clean Up command but the only half-suitable option I found there is to run formatting on all files which does more than I want (I don't want to run a complete formatting, just tabifying).
If you have added the Microsoft Productivity Power tools extension (which if you haven't I would recommned) it adds an option to tabify files. This does not apply across all files in a solution, but it's prompted for when editing each file, on a per file basis. Not quite what you're after but a help.
Also you might try setting your IDE editor settings to use tabs, then do menu-edit-advanced-format document (CTRL+E,D). This will replace groups of tab length spaces with a tab, and that should be scriptable for all files in the solution via a macro.
The request contains links to IDE macros that can do the job:
http://blogs.msdn.com/b/kevinpilchbisson/archive/2004/05/17/133371.aspx
http://web.archive.org/web/20090217094033/http://chriseargle.com/post/Format-Solution.aspx
Here is sample code for a Visual Studio macro that automatically formats all *.cs, *.h, *.cpp, and *.hpp files in an open solution, which includes converting spaces to tabs (depending on your Tab settings in Tools > Options > Text Editor > specific language or "All Languages" > Tabs):
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module ConvertTabsToSpaces
Public Sub FormatSolution()
Dim sol As Solution = DTE.Solution
For i As Integer = 1 To sol.Projects.Count
FormatProject(sol.Projects.Item(i))
Next
End Sub
Private Sub FormatProject(ByVal proj As Project)
If Not proj.ProjectItems Is Nothing Then
For i As Integer = 1 To proj.ProjectItems.Count
FormatProjectItem(proj.ProjectItems.Item(i))
Next
End If
End Sub
Private Sub FormatProjectItem(ByVal projectItem As ProjectItem)
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
If projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.FormatDocument")
window.Close(vsSaveChanges.vsSaveChangesYes)
ElseIf ((projectItem.Name.LastIndexOf(".cpp") = projectItem.Name.Length - 4) OrElse (projectItem.Name.LastIndexOf(".hpp") = projectItem.Name.Length - 4) OrElse (projectItem.Name.LastIndexOf(".h") = projectItem.Name.Length - 2)) Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.SelectAll")
projectItem.Document.DTE.ExecuteCommand("Edit.FormatSelection")
window.Close(vsSaveChanges.vsSaveChangesYes)
End If
End If
'Be sure to format all of the ProjectItems.
If Not projectItem.ProjectItems Is Nothing Then
For i As Integer = 1 To projectItem.ProjectItems.Count
FormatProjectItem(projectItem.ProjectItems.Item(i))
Next
End If
'Format the SubProject if it exists.
If Not projectItem.SubProject Is Nothing Then
FormatProject(projectItem.SubProject)
End If
End Sub
End Module
Instructions (Visual Studio 2005, but similar for newer versions):
Launch Visual Studio
Tools > Macros > Macros IDE...
Right-click MyMacros > Add > Add New Item...
Select Module
Enter "ConvertSpacesToTabs" without quotes in the Name field
Click Add
Replace the contents of the new module with the code above
Click Save
Close the Macros IDE
Tools > Macros > Macro Explorer
Expand MyMacros > ConvertSpacesToTabs
Double-click on FormatSolution
Wait for the macro to finish
Edit
I updated the code to also support *.h, *.cpp, and *.hpp files using code from Siegmund Frenzel here:
https://stackoverflow.com/a/14766393/90287
as far as I know what "Tabify" does is this - it only replaces " " (4 spaces) with a tab, it does not change the formatting or anything else.
Although I would suggest using document formatting, the "tabification" could easily be done via a custom application which would mimic the same action on all the files that you want.
Hope this helps!
For vs2010, you can use the following find and replace (this example is for tabs to 4 spaces).
In the find box, enter: ^{ *} (^{ space *} tab)
In the replace box, enter \1 (\1 space space space space)
Check the condition box and set to regular expressions.
Newer versions of vs use different regular expression syntax, but the same should be doable.
Update
This worked by executing once for vb files, but required multiple passes for a resx file, so you may have to execute multiple times depending on the file type...
There's a new way using the dotnet CLI:
Install dotnet format by running the following command:
dotnet tool install -g dotnet-format
Run it, replacing SolutionFile.sln with the path to your solution file, with the following command line:
dotnet format SolutionFile.sln
The indent_style of .editorconfig will be used to determine if the code will use tabs or spaces.
Macros have been removed from Visual Studio 2013 onwards (and the new version of Macros uses JavaScript rather than VBScript), so to get Rami A.'s answer to work in Visual Studio 2019:
Download and install the Visual Commander extension
Extensions > VCmd > Edit macro
Name it
Paste the following code. I have had to make some changes to it to make the code work with Visual Commander. I have also changed the file extensions that it tabifies to .cs, .aspx and .ascx so change these if you need C++/other file extensions.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports Microsoft.VisualStudio.Shell
Imports VisualCommanderExt
Public Class ConvertTabsToSpaces
Implements ICommand
Sub Run(DTE As DTE2, package As Package) Implements ICommand.Run
Dim sol As Solution = dte.Solution
For i As Integer = 1 To sol.Projects.Count
FormatProject(sol.Projects.Item(i))
Next
End Sub
Private Sub FormatProject(ByVal proj As Project)
If Not proj.ProjectItems Is Nothing Then
For i As Integer = 1 To proj.ProjectItems.Count
FormatProjectItem(proj.ProjectItems.Item(i))
Next
End If
End Sub
Private Sub FormatProjectItem(ByVal projectItem As ProjectItem)
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
If (projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 OrElse (projectItem.Name.LastIndexOf(".aspx") = projectItem.Name.Length - 5 OrElse (projectItem.Name.LastIndexOf(".ascx") = projectItem.Name.Length - 5))) Then
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
Try
projectItem.Document.DTE.ExecuteCommand("Edit.RemoveAndSort")
Catch
' Do nothing
End Try
Try
projectItem.Document.DTE.ExecuteCommand("Edit.SelectAll")
projectItem.Document.DTE.ExecuteCommand("Edit.FormatSelection")
Catch
' Do nothing
End Try
window.Close(vsSaveChanges.vsSaveChangesYes)
End If
End If
'Be sure to format all of the ProjectItems
If Not projectItem.ProjectItems Is Nothing Then
For i As Integer = 1 To projectItem.ProjectItems.Count
FormatProjectItem(projectItem.ProjectItems.Item(i))
Next
End If
'Format the SubProject if it exists
If Not projectItem.SubProject Is Nothing Then
FormatProject(projectItem.SubProject)
End If
End Sub
End Class
Save
Run
To save for future use: Extensions > VCmd > Save macro as command > Name it > Save