Giter Site home page Giter Site logo

codealignment's Introduction

Code alignment

Code alignment is the practice of formatting your code vertically to improve readability.

Based on principles borrowed from mathematics and other disciplines, code alignment gives extra meaning to your code by lining up similar data in columns. This is something we do naturally when working with tables and spreadsheets, but unfortunately it doesn't get applied to code often enough.

The usual excuses are, "It's too hard. It takes too long. They don't pay me enough." With this extension, these excuses are no longer valid.

For more information, examples, bug tracker and change logs visit the the code alignment website.

codealignment's People

Contributors

chcg avatar cpmcgrath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codealignment's Issues

Code Alignment does not work with Visual Studio 15 Preview with just the Core Editor

It installs, then when you try to run it you get an error. The critical part of the Activity log is...

Could not load file or assembly 'Microsoft.VisualStudio.Shell.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

In short, I consider this a problem with the Lightweight installer they should fix on their side, I mainly made this issue so if people experience it they can understand why.

However, if someone knows how to fix this (While keeping compatibility with old versions of Visual Studio!) more than happy to accept a pull request.

Allow the user to customise the Characters that define a "block"

Currently a block is defined as the area between lines which just contain one of the following sets of characters
{ } }; ( )
This option would allow a user to add and remove from this list. They should also be a second list where instead of the line equaling the list it only has to end in it. This is useful for people who don't put { on new lines.

In Notepad++, Code Alignment does not work on Unicode Glyphs

UNICODE GLYPH POINTS
… Elipsis.Alt +0133
⸘⸘ Upside-Down Interrobang.Alt +2E18
test test.test
test0 test0.test0

Aligning by space on the above causes the second line to align 2 short, and the third line to be 4 short. So each glyph is being treated as 3 characters long instead of one.

Worth noting: It seems like some fixed width fonts don't count glyphs as needing to conform to the width.

If possible this should be fixed.

Notepad++ Code Alignment Error - System.IO.FileNotFoundException

In the last couple of weeks I've stopped being able to use the code alignment plugin for NP++.

I get the following unhandled exception message when I try to use the align by character option:

System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
File name: 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
   at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)
   at System.Configuration.MgmtConfigurationRecord.CreateSectionGroupFactory(FactoryRecord factoryRecord)
   at System.Configuration.MgmtConfigurationRecord.EnsureSectionGroupFactory(FactoryRecord factoryRecord)
   at System.Configuration.MgmtConfigurationRecord.GetSectionGroup(String configKey)
   at System.Configuration.Configuration.GetSectionGroup(String sectionGroupName)
   at System.Configuration.ClientSettingsStore.DeclareSection(Configuration config, String sectionName)
   at System.Configuration.ClientSettingsStore.GetConfigSection(Configuration config, String sectionName, Boolean declare)
   at System.Configuration.ClientSettingsStore.WriteSettings(String sectionName, Boolean isRoaming, IDictionary newSettings)
   at System.Configuration.LocalFileSettingsProvider.SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
   at System.Configuration.SettingsBase.SaveCore()
   at System.Configuration.SettingsBase.Save()
   at System.Configuration.ApplicationSettingsBase.Save()
   at CMcG.CodeAlignment.FormCodeAlignment.Ok(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.PerformClick()
   at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

If I try to do alignment by one of the default characters like equals (the ones in the menu), it all works fine.

I'm using Windows 8.1 x64 and have the latest versions of Dot Net (4.5.1 and 4.6.1) installed and the latest versions of Notepad++ (6.9.2) and the code alignment plugin (12.0).

On another Windows 7 computer which has the same software installed, I don't have the issue.

I'm trying to work out what must have changed on my computer to make it stop working and I can't seem to figure out what has changed. The only thing I have installed since I last remember it working is the Intel OpenCL SDK, but I doubt that will be causing the issue. There haven't been any windows updates installed either, so I am really not sure what is going on.

Option to repeat alignment.

There should be an option to continue aligning until it can't find anything more to align.

var a = b = c = d = e;
var foo = foobar = bar = buzz = fuzzbuzz;

With the option with a single shortcut, should become

var a   = b      = c   = d    = e;
var foo = foobar = bar = buzz = fuzzbuzz;

Add support for Visual Studio Code

It might be possible to do this in a similar way to Sublime. But I plan on porting the entire Code Alignment code to Javascript for this.

This will hopefully mean the code base could be used with many more IDEs.

Use tabs instead of spaces to indent ( if the user chooses ).

Tabs should be used for aligning because 1 character vs 4/5 characters over 10s of thousands of lines will increase file-size. Using this plugin to 13961 lines won't allow me to use my save macro ( which converts 5 spaces to tab, 4 spaces to tab, 3 spaces to tab, 2 spaces to tab, and trim trailing white-space ) because of the spaces-spam...

The file I'm editing is 690kb when using tabs as aligners. However, when using spaces as aligners from this plugin made the file size 1,731KB... Over 1.1mb of just SPACES which is stupid. Yes, stupid because there are more spaces in the document than content whereby if using tabs the content would still outweigh tab content by more than 2 times.

I don't see why the option doesn't exist, and why it was edited in 2012 to remove the option to use tabs if the user wants: f79b6c7

Can't install your extension in new VS"15"Preview

Hi,

Installed product versions

  • Visual Studio: [15 Preview]

Description

At build 2016 Microsoft released Visual Studio 15 Preview.
There are some extensions that work there, but some that are not even searchable in "Extensions and Updates". Yours is one of those that are not searchable and not installable.

Steps to recreate

  1. Install Visual Studio 15 Preview: https://www.visualstudio.com/en-us/downloads/visual-studio-next-downloads-vs.aspx (Visual Studio "15" Preview with new installer)
  2. Open VS15Preview
  3. Open Extensions and Updates
  4. Click on Online in the menu
  5. Search for Code Alignment
  6. Your extension doesn't pop up

Current behavior

Your extension is not searchable in new Visual Studio 15 Preview

Expected behavior

Your extension should or could be also in VS15Preview :)

Btw, I created recently one analyzer and made it to be an extension and it works there fine:
https://github.com/jakubsuchybio/DebuggingUsingsInsertor-Analyzer
If you needed something to compare yours setup of extension with.
Regards.

Add ability to remove excess white space

If you edit a line which has an alignment on it, there's a good chance that this will break the alignment. Doing the alignment again fixes it but can add too much white space. For example,

var distanceTravelled = 10;
var x                 =  5;

And then we decide to improve the name of x

var distanceTravelled = 10;
var xCoordinate                 =  5;

And then we do an alignment

var distanceTravelled           = 10;
var xCoordinate                 =  5;

There should be a way to remove the excess white space...

var distanceTravelled = 10;
var xCoordinate       =  5;

align by comma?

consider the following:
Maps.addMap("Quantity", "Quantity Qualifier", "MMM-6-1");
Maps.addMap("Quantity", "Quantity", "MMM-6-2");
Maps.addMap("Quantity", "Code List Qualifier", "MMM-6-3");

None of the current options will work for lining up the code without changing the strings. If I could align by comma, or if I could align by only the leftmost quote that would help. Or if I could align by space ignoring spaces inside of strings.

Is there any solution? I really want to use the extension, but it won't work for me without doing a find/replace of comma to period and then back again :(

Add ability to specify a condition which will skip lines.

The purpose of this is to allow code alignment to skip lines. If you have

int value1;
//Something about value2
string value2;

and you want to use align by space to align the variable names you end up with

int         value1;
//Something about value2
string      value2;

This option would let the center line be ignored.

We may also proved an option on the Align by screen to ignore this or not.

Finally, this will only skip whole lines, not part of lines after the specified condition. So it would not stop

 int foo; //comment after code
 var valueone = 64;
 var valuetwo = 64;

becoming

 int foo; //comment after code
 var valueone       = 64;
 var valuetwo       = 64;

Feature: Comment alignment

I would love to see the ability to make this code...

int i = 4;     // another comment
int x = 7;        // some comment
int y = 5;                        // another comment
int myFatAssVarWithIrritatinglyLongName = 5; // a final comment

indented with an algorithm like:
1: find the longest line in selection
2: indent all code-comments to the next TAB position after the found longest line's endpoint

so the code above would similar to this instead:

int i = 4;                                      // another comment
int x = 7;                                      // some comment
int y = 5;                                      // another comment
int myFatAssVarWithIrritatinglyLongName = 5;    // a final comment

That would be very, very useful!

Can't get to work

I can't get this plugin to work correctly in Visual Studio. I'm trying to align multiple lines with commas.

[foo, bar, baz]
[1,2,3]

Desired:

[foo, bar, baz]
[1  , 2  , 3]

The closest thing I've found is this wiki page, but when I try that regex, it doesn't do anything but align the first commas on the lines I have highlighted. I want all commas aligned.

So I have a few issues:

  • Can't align by commas successfully.
  • I can't figure out how to invoke the custom CodeAlignment shortcuts in VS- they're not listed in keyboard shortcuts. I've been manually pasting in the commas regex to the align-by-string.
  • Why is comma alignment listed on the wiki but not a default in the plugin? Seems like a pretty common use-case.

Thanks for any help.

Store Default settings in JSON

#4 will lead to the settings being stored in JSON, the defaults should be updated to be consistent.

This should not be done immediately as we don't want people to lose their settings.

Update the description in the Visual Studio package

Replace "principals" with "principles"

On the website and tooltip it gets cut off at "most data using tables and spreadshee"

Would also be good to get to the point by, "other displines, code alignment giv" which is where it cuts off the description at the default extension window size (when the download button isn't visible)

Add ability to specify where to add spaces (ability to right align).

Not sure how useful this would be. Feedback welcome.

Alignment Regex's have the
(?) Match Group.
This will not change, but the following enhancements should be made.
(?) Match Group should have an alias (?)
compare is the preferred syntax as it's more descriptive.

A new matching group (?) which defines where the spaces should be inserted. If it doesn't exist it should then use compare/x then the start of the matching regex.

Support multiple instances of the same character

I'd like to format this:

int[] Numbers = {
    1, 2, 3,
    4 , 5 , 6 ,
    7  ,  8  ,   9
}

like this:

int[] Numbers = {
    1, 2, 3,
    4, 5, 6,
    7, 8, 9
}

So far the only way to do it is to move the caret and align again which become a hassle with a lot of columns. Regular expressions didn't seem to work.

Usage scenarios:

  1. Array initializers
  2. Server logs (ftp, http, etc.)
  3. SQL statements with many columns (select, insert)
  4. Working with CSV files

TextFX can handle all of them as long as Unicode is not involved but I've had it insert 4k spaces in some instances when parsing server logs.

Seperate UI Logic into its own assembly

When the Common assembly was first created there was only one pretty simple screen. Since then a lot of screens has been added an it's start to make the Common assembly a bit messy.

By seperating the WinForms logic, not only do we get a cleaner design but we have the option to introduce different UIs (e.g. WPF) without removing the WinForms logic (Which could still be useful if ported to linux with mono).

Have an option to align only by tabs

Currently when you "Use IDE tab settings" with tabs on, code alignment will align exactly to the furthest instance. It does this by inserting tabs then spaces. Some people would like it to just insert tabs and move the furthest along a bit to match that.

This issue is to discuss the possibility of introducing an option - not a guarantee that it will be done. And to see if anyone would like to volunteer to implement it.

Before contributing please read https://github.com/cpmcgrath/codealignment/wiki/Tabs-&-Alignment and consider if you really want to use tabs at all.

How to align with 4 spaces?

Tabs are evil, you know.
But I'd prefer to get this (not tabs, just spaces but more than 1):

SomeMethod(
    param1:    arg1,
    param2:    arg2, // 4 spaces.
    param3:    arg3)
{
    // ...
}

instead of this:

SomeMethod(
    param1: arg1, 
    param2: arg2, // 1 space.
    param3: arg3)
{
    // ...
}

BTW, I'm using this regular expression: :\s*(?<x>[^\s]).

AlignByKey - '{' stopped working

Hi,

Previously up until today I would highlight a bunch of properties in a C# file, press Ctrl+Shift+= to 'Align By Key' and then press '{' to align them as follows:


public bool Failed              { get; private set; }
public string FailureMessage    { get; private set; }
public string ExceptionInfo     { get; private set; }
public string ErrorInfo         { get; private set; }

This morning this appears to no longer work. I get the "Waiting for second key chord.." pop up (which I'm sure I never saw before..) and pressing the '{' key does nothing. It works if I align by equals, or AlignBykey and then '=', and I can't see any updates or anything newly installed in VS2013 that would have broken this.

Any thoughts? It's very frustrating as using this extension has been wonderful and is now more of a habit than anything.

Add a toolbar for Notepad++

Visual Studio has a toolbar which is a great way to get started. It makes sense for Notepad++ to have one too.

Chained Alignments

If you hold down ctrl during a shortcut you should be able to press the next key without pressing ctrl = again. The next alignment will always start from the position of the last alignment. This is called "Chained Alignments"

var a = b = c = d = (e - 2);
var foo = foobar = bar = buzz = (fuzzbuzz - 2);

If you press ctrl =, then hold ctrl and press ====- it could turn the above into...

var a   = b      = c   = d    = (e        - 2);
var foo = foobar = bar = buzz = (fuzzbuzz - 2);

Note: This assumes you've written an alignment for -

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.