How to make VS Code treat files without extension as a certain language? - visual-studio-code

At work there are a lot of file without extension. They are all COBOL files, so now I manually change their associating to COBOL each time I open one. But I was looking for a way to make VS Code treat files without extension as COBOL automatically.
I know you can add file associations in the settings, but the only thing that works is to add "*": "COBOL" there, but then everything is considered a COBOL file... I also tried `"[^.]": "COBOL" hoping regex would work but it didn't.
Is there a way to do this?

You can apply the file associations to all files in a given directory only:
"files.associations": {
"**/RootDir/**/*": "COBOL"
}
This way, all files in /RootDir/, or one of it's sub-directories, will be mapped to COBOL.
All files outside of /RootDir/ will still be mapped as usual according to their extensions.
Suppose your /RootDir/ doesn't contain only COBOL-files, but also some other file types. In this case you can go further and define exceptions for the file associations:
"files.associations": {
"**/RootDir/**/*.bat": "bat",
"**/RootDir/**/*.sh": "shellscript",
"**/RootDir/**/*": "COBOL"
}
Basically you're instructing Visual Studio Code to map all files in /RootDir/ to COBOL, except for .bat and .sh which are mapped as Batch and Shellscript, respectively.
As above, all files outside of /RootDir/ will still be mapped as usual according to their extensions.

I went through the same problem with php_cs-fixer config file.
This one is generally .php_cs.
I only have to add this line
"files.associations": {
"*.php_cs": "php"
},
AND relaunch vscode and .php_cs is now a php formatted file.
hope this help.

Just found another possible solution which works best for me.
I was trying to get shell lang selected for the .ssh/config and it worked by just adding
#!shellscript
at the very beginning of the file, maybe this doesn't work with all files/languages but it can be useful

Related

How do I configure mplayer to use a default edl file name?

I want to configure mplayer to look for an edl when playing a video. Specifically, I want it to use "show.edl" when playing "show.mp4", assuming both are in the same directory. Very similar to how it looks for subtitles.
I can add a default edl in the config file by adding the following:
edl=default.edl
And this will look for the file "default.edl" IN THE CURRENT DIRECTORY, rather than in the directory where the media file is. And it isn't named after the media file either, and thus even if it did look in the right place, I'd have one single edl file for every media file in that directory.
Not really what I wanted.
So, is there a way, in the "~/.mplayer/config" file, to specify the edl relative to the input file name?
Mplayer's config file format doesn't seem to support any sort of replacement syntax. So there's no way to do this?
MPlayer does not have a native method to specify strings in the config file relative to the input file name. So there's no native way to deal with this.
There's a variety of approaches you could use to get around that. Writing a wrapper around mplayer to parse out the input file and add an "-edl=" parameter is fairly general, but will fail on playlists, and I'm sure lots of other edge cases. The most general solution would of course be to add the functionality to mplayer's config parser (m_parse.c, iirc.)
The simplest, though, is to (ab)use media-specific configuration files.
pros:
Doesn't require recompiling mplayer!
Well defined and limited failure modes. I.E. the ways it fails and when it fails are easily understood, and there aren't hidden "oops, didn't expect that" behaviors hidden anywhere.
Construction and updating of the edl files is easily automated.
cons:
Fails if you move the media around, as the config files need to full path to the edl file to function correctly.
Requires you have a ".conf" file as well as an EDL file, which adds clutter to the file system.
Malicious config files in the media directory may be a security issue. (Though if you're allowing general upload of media files, you probably have bigger problems. mplayer is not at all a security-hardened codebase, nor generally are the codecs it uses.)
To make this work:
Add "use-filedir-conf=yes" to "/etc/mplayer.conf" or "~/.mplayer/config". This is required, as looking in the media directory for config files is turned off by default,
For each file "clip.mp4" which has an edl "clip.edl" in the same directory, create a file "clip.mp4.conf" which contains the single line "edl=/path/to/clip.edl". The complete path is required.
Enjoy!
Automatic creation and updating of the media-specific .conf files is left as an exercise for the student.

What was the .txt file which allows clangd to understand with what compile arguments a program gets compiled in?

I remember that there's a ".txt" file which allows to define link/compile-time arguments, but I've forgotten it's name.
I tried to google for answer.
The text file is called compile_flags.txt.
It's discussed at https://clangd.llvm.org/installation#compile_flagstxt.
Note that there are some shortcomings of compile_flags.txt compared to the more common way of configuring a project for use with clang-based tooling, compile_commands.json; most notably, clangd won't index your project with compile_flags.txt.

Can I perform a find/replace driven by a CSV/Excel file?

I have to perform a find/replace across my project's files using a rename rule-set which I have in CSV format.
My rename CSV is simple and in the format from value,to value:
foo,bar
car,dog
...
zip,zip
All from and to values are exact (so no need to do weird regex).
Is there any way (even w/ an extension) to feed this CSV into VS Code and have it perform the find and replace against all files in my project?
I can of course reformat this CSV to other formats (JSON, excel, etc.) fairly easily if that helps.
You could write a simple python script to do the replacing for you.
I ended up using Batch Replace extension for VS Code.
https://marketplace.visualstudio.com/items?itemName=angelomollame.batch-replacer
Originally I had tried this extension but it wasnt working. I had an ah-ha momement as to why (i have about 500 replace rules). I also use a local history VS Code extension which creates a (massive) local history in a .history folder in the workspace. This extension was choking on processing the 10,000's of files in that (since technically its in my workspace).
Once i excluded that, it worked - though it did take ~1 min to process all my files, and during that time there is no indication that its running.

Scratch output file .txt or similar

I want to know if there is an easy way to open a .txt file and load some comma delimited data into variables in Scratch and furthermore add some variable data from Scratch to a .txt file or similar?
I have done a fair bit of google searching but not come across anything so I thought I would ask you guys.
I would love to use Java or something but its for my school kids and I cannot teach them to do it in Java or something else as they need to do what they have to in Scratch which is annoying but something I cannot change.
Scratch does not have file IO capabilities, and i doubt it ever will.
The closest thing that i know of is importing/exporting a list. Right-click on the list watcher from the Scratch IDE, and export. It will produce a .txt file, with each list item on a new line. If you have a similarly formatting TXT file, you can import it using the same method. Each line corresponds to a list item. Comma delimited data doesn't work with this.
You can download and edit the json script for the Scratch project.
From the "See Inside" screen, File->Download to your computer.
Rename the file to have a ".zip" extension instead of just ".sb2".
Unzip the file to edit the "project.json" file.
Edit the list data under "ListName": "[your list]" as desired.
Reassemble the zip file
Remove the ".zip" extension. (Back to ".sb2")
Update the Scratch project by going to the original project and selecting File->Upload from your computer.
In this sample project I have a list called "Jobs". The project.json file has a section like this...
"listName": "Jobs",
"contents": ["Accountant",
"Actor",
"Advocate",
"Appraiser",
"Architect",
"Baker",
...
Make whatever changes you want directly to the section for your list.
Currently, Scratch has no IO abilities, as the answer above me said, But there is a mechanism called JS extenions. Currently it's a closed beta, but when it will be released everyone would be able to program Javascript extensions for scratch. That means that you will be able to create a "Open file" block yourself.

How can I add a custom package to the startup path in Dymola/Modelica?

I have a custom package that I find myself reusing repeatedly in Dymola models, and I'd like to put this package in a common directory that is automatically loaded whenever I start Dymola. My current strategy is to load the custom package when a model I'm working on is loaded and then save total. This is not elegant because the contents of the custom package end up saved in multiple locations across my hard drive, and if I change one of them, the changes are not reflected everywhere. I would like a more robust way of distributing this custom package to all of my models. Is there a way to tell Dymola to automatically load my custom packaged every time?
The trick is to add the following lines to settings.mos in c:/Users/USERNAME/AppData/Roaming/Dynasim:
Utilities.setenv("MODELICAPATH", "C:\Users\USERNAME\Documents\Dymola");
openModel("c:\Users\USERNAME\Documents\Dymola\UserDefined\package.mo")
The first line adds the directory to the path that Dymola uses to search for packages that have not been loaded prior to the first run of a model, and the second line loads the specified package. These two commands may be somewhat redundant, but I am doing both because I want to make sure my custom packages are on the path in addition to loading the UserDefined package.
Two suggestions. First, you need to add your package to the MODELICAPATH. You'll have to consult the Dymola documentation to figure out exactly what you need to do. But normally, what this means is that you have to set an environment variable that gives a list of directories (; separated) to be searched for your package. Now that will put it in your path so it can find it automatically, but it won't load it until it needs it.
If you want it to always appear in the package browser, you'll probably need to set up a .mos file (script) to load it. Dymola has that capability, but you'll have to read the manual to figure out what that script has to be called and where Dymola expects to find it.
I hope that helps.
In the instalation folder of Dymola 2018 -> insert -> dymola.mos
I've added the lines:
Utilities.setenv("MODELICAPATH", "C:\Users\XXXX\Documents\Dymola");
openModel("C:\Users\XXXX\Documents\Dymola\DCOL\package.mo");
openModel(“C:\Users\XXXX\Documents\Dymola\Annex60 1.0.0\package.mo”);
Now I don't get the utilities sentence, as the DCOL package loads fine without it and the added 'utilities' package in the package menu is useless.
But it does not open the Annex60 package.
I've tried a lot of different combinations and can't get multiple packages to load. I doubt that "cd" and "Advanced.ParallelizeCode", which are also added in the text work.
The accepted answer does not work since Dymola 2017 FD01, as the file settings.mos is not used anymore. User settings are stored in the setup.dymx file instead, located in
C:\Users\USERNAME\AppData\Roaming\DassaultSystemes\Dymola
In contrast to the setup.mos file you can not include custom lines with modelica script in setup.dymx.
The answer using dymola.mos still works, but you need admin privileges to modify this file.
Here is a simple solution which works with all Dyomola versions:
You can pass a .mos-script as first parameter to the dymola.exe.
This can e.g. be done like this:
Create a .mos script somewhere with commands like openModel(), etc.
Create a desktop shortcut to Dymola.exe
Open the properties of the shortcut and add the path to the .mos script in the Target text field. It will then look something like this:
"C:\Program Files\Dymola 2018 FD01\bin64\Dymola.exe" "C:\<some-path>\startup.mos"
Start Dymola with the desktop shortcut. The script will be executed and eventual errors or messages are displayed in the Commands window
Another suggestion where you don't need to hardcode your package into an environment variable of your operating system (and maybe more safe for inexperienced programmers):
Go to the folder where Dymola is installed (e.g. C:\Program Files\Dymola 2020).
Search for the Dymola.mos file in the insert-folder. 'insert' folder
Open the script (e.g., in notepad++)
Add the link(s) to your Dymola-library-package.mo file(s) here with the openModel statement
e.g., openModel("C:/IDEAS/package.mo"); Dymola.mos script
Save the script. Now, every time you open Dymola, your libraries will be loaded automatically.