I just started using Visual Studio Code. In my company they use Whitesmiths indentation style, but I cannot find a way to set it on VSC.
I'm programming in C, so I installed the C/C++ plugin. In this, the "Indent: Braces" option looks like the one for me, but it does not seem to work.
My json looks like this:
"C_Cpp.vcFormat.indent.braces": true,
"editor.detectIndentation": false,
"editor.tabSize": 3,
i set detect.Indentation to false, because i don't want it to interfere with indent.braces.
This is the user json. I did not modify the workspace nor the folder settings.
However, my code still looks like this
void main()
{
if(condition)
{
do something
}
else
{
whatever
}
}
while it should look like this
void main()
{
if(condition)
{
do something
}
else
{
whatever
}
}
what am I missing? Is there a way to set this from the VSC settings without using the plugin?
this post is for c# but it worked for me using the visual studio c++ formatter:
Visual Studio Code custom indentation style
my full .json file:
{
"[c]": {
"editor.defaultFormatter": "ms-vscode.cpptools"
},
"editor.autoClosingQuotes": "never",
"editor.autoClosingBrackets": "never",
"workbench.list.automaticKeyboardNavigation": false,
"workbench.settings.openDefaultKeybindings": true,
"update.enableWindowsBackgroundUpdates": false,
"update.mode": "manual",
"C_Cpp.formatting": "vcFormat",
"C_Cpp.vcFormat.indent.braces": true
}
PFE32 is an ancient editor that will indent in that style. The much newer Code::Blocks editor will handle it as well. Use Astyle to reformat to that style.
By the way, this is the style used with the original Whitesmith's tool chain. It was the first commercially available C compiler. This is the style that God uses when he writes in C. It is not ugly. It is correct, proper for the Backus-Naur definition of the language. It is pretty, just like me. ;-D
Related
When I've used Settings Designer before, I've been able to browse to find non-standard Types (e.g. uncommon enums etc) to use in my Settings via a "Browse" button at the bottom of the drop down under the "Type" column. I'm developing a WPF desktop application for .net Core and there is no Browse option as pictured below:
I did go into the code behind (Settings.Designer.cs.) and edit the code manually, but on saving, this just reverted to string. I'm guessing this may have something to do with settings also having an element in App.config and I notice it has a "serialiseAs" tag - didn't know what to put here. Exmaple of the code behind settings and App.config:
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string UiTheme {
get {
return ((string)(this["UiTheme"]));
}
set {
this["UiTheme"] = value;
}
}
<userSettings>
<GameBoxer.WPF.Properties.Settings>
<setting name="UiTheme" serializeAs="String">
<value />
</setting>
</GameBoxer.WPF.Properties.Settings>
</userSettings>
Does anyone know how to bring back the 'Browse'?? Or, how to correctly do it in code?
I'm using Visual Studio 2022 Community
Thanks
UPDATE: So, I learn that this is "By Design" in VS2022 according to MS here. It's still present in VS2019! But they've taken it out of VS2022 and I can't figure how to do it in code. MS, you're one of my faves out the bunch, but sometimes, you're as mad as a box of frogs. unfortunately that link doesn't provide the poster with any alternatives other than "that's not a bug." Not very helpful, really.
As mentioned in the link you provided, this change was by design due to .NET Core and while I very strongly disagree with their stance on this - I'm assuming this was done because it could be quite fiddly to get your own types to work as expected, especially for new users.
One simple workaround if your custom data has several values, you can use string and simply write your own little parser using delimiters such as ;. You could also use StringCollection to achieve the same result.
Inconvenient, yes. But a simple solution nonetheless.
I sincerely hope Microsoft changes their stance on this and looks at reimplementing this as it worked remarkably well once you figured out the procedure to get it to serialize properly.
Edit:
Figured I might as well provide an example;
// Storing the Settings
// Parameter: Struct { Location(Point), Size(Point), Margin(Thickness) }
var settingString = $"{e.Location.X};{e.Location.Y};{e.Size.X};{e.Size.Y};{e.Margin.Left};{e.Margin.Top};{e.Margin.Right};{e.Margin.Bottom}";
Properties.Settings.Default.MySetting = settingString;
Properties.Settings.Default.Save();
// Parsing the Saved Setting
var settingString = Properties.Settings.Default.MySetting;
if (!String.IsNullOrWhiteSpace(settingString))
{
List<string> splitStrings = settingString.Split(';', StringSplitOptions.RemoveEmptyEntries).ToList();
List<double> parsedValues = new List<double>();
splitStrings.ForEach(x => parsedValues.Add(double.Parse(x)));
var location = new Point(parsedValues[0], parsedValues[1]);
var size = new Point(parsedValues[2], parsedValues[3]);
var margin = new Thickness(parsedValues[4], parsedValues[5], parsedValues[6], parsedValues[7]);
}
There's probably better ways of doing this, but I find this to be a very simple workaround and has worked great thus far.
I'm now using the bsd style in emacs. It's a style I started with years back after coming from learning pascal and I've decided will use over other styles for new projects.
However, there is two things that bug me with the emacs bsd style. It indents inline methods.
1) How do I stop it indenting like this?
i.e.
class A
{
A()
{
// do stuff
}
};
I want the brace to be on the same line as methods like this.
class A
{
A()
{
// do stuff
}
};
Looking around it appears like I need to set
c-set-offset substatement-open' 0)
But I don't know how to attach this to the bsd style in lisp. I gave it a go, but got parse errors on starting emacs.
2) How to make the tab key insert 4 spaces?
I just doubled checked my emacs setup and this does what you describe for me:
(setq c-default-style "bsd"
c-basic-offset 4)
Try this to insert spaces instead of tabs:
(setq tab-width 4)
(setq indent-tabs-mode nil)
I have the following values in my hiera yaml file:
test::config_php::php_modules :
-'soap'
-'mcrypt'
-'pdo'
-'mbstring'
-'php-process'
-'pecl-memcache'
-'devel'
-'php-gd'
-'pear'
-'mysql'
-'xml'
and following is my test class:
class test::config_php (
$php_version,
$php_modules = hiera_hash('php_modules', {}),
$module_name,
){
class { 'php':
version => $php_version,
}
$php_modules.each |String $php_module| {
php::module { $php_module: }
}
}
While running my puppet manifests I get the following error:
Error: Evaluation Error: Error while evaluating a Function Call, create_resources(): second argument must be a hash at /tmp/vagrant-puppet/modules-f38a037289f9864906c44863800dbacf/ssh/manifests/init.pp:46:3 on node testdays-1a.vagrant.loc.vag
I am quite confused on what exactly am I doing wrong. My puppet version is 3.6.2 and I also have parser = future
I would really appreciate any help here.
Looks like your YAML was slightly off.
You don't really need quotes in YAML.
Your indentation was two instead of one.
Your first colon on the first time was spaced. This will throw a syntax error.
it should look more like this:
test::config_php::php_modules:
- soap
- mcrypt
- pdo
- mbstring
- php-process
- pecl-memcache
- devel
- php-gd
- pear
- mysql
- xml
In the future try and look up YAML parsers like this: link
The problem was with my puppet version, somehow version 3.6 acts weird while creating resources, for instance it was failing on the following line,:
create_resources('::ssh::client::config::user', $fin_users_client_options)
The code snippet above is part of ssh module from puppet labs, which I assume is throughly tested and shouldn't be a reason for the an exception.
A further analysis led to the fact that the exception was thrown when the parameter parser = future was set in the config file
I cannot iterate using each without setting future as the parser, therefore I decided to change my source as follow:
I created a new class:
define test::install_modules {
php::module { $name: }
}
and then I changed the config config_php to:
class test::config_php (
$php_version,
$php_modules = [],
){
class { 'php':
version => $php_version,
}
install_modules { $php_modules: }
}
Everything seems to be much better now.
I'm completely new to emacs (mostly used vim and eclipse/netbeans etc.) I was playing with multi-level nesting of C code and wrote a sample code in emacs to test how it indents codes where nesting is way too deep (not real life code though).
int foo()
{
if (something) {
if (anotherthing) {
if (something_else) {
if (oh_yes) {
if (ah_now_i_got_it) {
printf("Yes!!!\n");
}
}
}
}
}
}
This looked exactly like this as I typed in emacs and saved it. But opening it on a different text editor showed the actual text saved is this:
int foo()
{
if (something) {
if (anotherthing) {
if (something_else) {
if (oh_yes) {
if (ah_now_i_got_it) {
printf("Yes!!!\n");
}
}
}
}
}
}
So I was wondering is there any way in emacs to save the text the way it actually displays?
My current c-default-style is set to "linux".
EDIT:
Ok, I was using Notepad++/Vim to view the file saved by emacs and it showed that "wrong" indentation, but looks like, opening with good old notepad (or even doing a cat file.c) shows the correct indentation as displayed by emacs. Will try the other approaches mentioned here. Thanks!
Try using spaces instead of tabs for indentation. Add the following to your init.el:
(setq-default indent-tabs-mode nil)
This will make all buffers use spaces by default. You will want to add the following exception for makefiles:
(add-hook 'makefile-mode-hook (lambda () (setq indent-tabs-mode t)))
When trying to generate our application with the variant "qx.debug" set to "on" in the config.json I get a lot of errors like this:
Error: Variantoptimizer: No default case found for (qx.debug:off) at (qx.core.Property:1004)
I could fix those by adding the "default" cases, but I was wondering, if I was doing something wrong in the first place or if this these are actual issues in the qooxdoo SDK.
For one thing, qx.debug is set to "on" in the source version by default, so you don't have to do anything for that.
For the build version, you need to configure this in your config.json, e.g. in the "jobs" section add
"build" : {
"variants" : {
"=qx.debug" : [ "on" ]
}
}
Is this what your config looks like? The error message you gave is weird, which qooxdoo version are you using? You shouldn't need to provide any "default" cases for this variant in the framework code.