Line breaks don't show up right in YAML? - yaml

I am looking at a YAML config file for a database, and all I see is a big jumble of text. However, I notice that there is a missing character every now and then if I use my keyboard's arrow keys to navigate around, I notice that there is occasionally a spot where the cursor gets stuck and requires me to press the arrow key two times instead of one. I am currently assuming that this is a line break that only YAML parsers can read. When I force a line break by pressing ENTER, the YAML parser does not understand the config file anymore. How can I get past this limitation without using a non-windows program? This line break has a Hex value of 0A.
As requested, a snippet of what the current YAML text looks like and what I would like it to look like can be found at the links below (due to StackExchange's limited use of indents. Note that these are two different files for a game's configuration. The API for the parser is here.
What I would like the config to look like
What the config currently looks like
It has also come to my attention that the second link might show it as a YAML file since it registers the line-break as a line break. However, the chunk below might give you an idea of what it looks like to me.
RWtorchLight: Version 1.2 made by MYCRAFTisbest
indent1: ''
NOTE: 'The Meta data valuse is the number after the :'
For Example: Black wool, put 35 in Light_Block and 15 in Meta Data
Light_Block: 89
Meta_Deta_LB: 0
IMPORTANT: The torch and boots are not compatable with Meta Data yet
Torch_Item: 50
Helmet_Item: 314
Boot_Item: 317
indent2: ''
Torch_Use: true
Helmet_Use: true
Boot_Use: true
T-or-T Mode: Will create dim light when wearing pumpkin and all below features
Trick-or-Treat Mode: true
C of C: Chance of Cookie is the chance of how often trick-or-treaters get candy
Set to: '"0" for no chance'
Chance of Cookie: 5000
N of C: 'Will randomly chose a number between 1 and # when Cookies are received'
Number of Cookies: 5

BACKGROUND
After reviewing your question and the associated discussion in comments, a likely case is your YAML file is being corrupted either by:
notepad.exe;
your FTP/SFTP/Web page/whatever used for uploading the text; OR
a combination of both of the above
PROBLEM
YAML syntax is whitespace and indentation sensitive, and using MSFT notepad.exe is not recommended because it may not support the encoding specified in your YAML file.
Since YAML uses whitespace to delimit the data, any kind of modification to the text that is not consistent with the original encoding and whitespace of the original YAML will potentially render the file unusable.
This is one of the aspects of YAML that makes it potentially more brittle than alternative formats, such as JSON or XML.
SOLUTION
Use another editor such as Notepad++ (as recommended in the comments) or, if you do not have sufficient privileges to install another text editor, use an online text editor such as editpad (http://www.editpad.org/) to edit and save the YAML to a local file on your machine.
After saving the file to your local machine using a text editor besides notepad.exe, upload your file using an option that does not apply any kind of text filter to the text.
For example, some websites strip out characters from user-uploaded text to prevent things data corruption and security risks.
STEP BY STEP
start with a known well-formed YAML file, such as the one you specified in "What I would like the config to look like"
paste it into Notepad++ (local machine) or editpad (web-based editor)
modify the YAML file so it matches the settings you want
save your modifications to the original file
upload the file via SFTP or other means that preserves the original encoding

Related

How to prevent specific line/s inside a notepad file from being edited?

I have a file that can be opened thru notepad application.
Basically, this file(which can be opened thru notepad) is created by a software and that software uses the values inside that file to run. You can edit the values inside the file using its software.
I just want specific lines(values) to be restricted from being edited because I am implementing strict values inside that file that no one will be able to edit except me.
Is there any clever way to restrict specific lines inside that file from being edited?
I tried the basic way - I used the change permission read/write on that file but I can't change ANY values inside the file which is undesirable.
Note: I have very little to no experience about python, c++, or java but any suggestion will give me idea to learn from it.
Edit:
Here's an example inside the file:
[Type Data]
Comment=Standard Dispense
[Shared_A]
802=1
807=750
11=0
12=0
.
What I want is restrict the value from row/column "807" which is equal to number 750.
I want this number 750 not to be edited even from the software so that other people will not mess it up. I want to set this value as standard value.
Is there any program that you can write inside that file so that it cannot be edited from the software unless I open that file and edit it?
I work from a production/manufacturing company that uses the software that is used for dispensing.
A text file is simply a sequence of bytes that represent code units to encode code points in any given character set. Every byte value is a potentially legal character encoding, leaving no values to encode additional semantics (like guard regions).
With that it should be obvious that there is nothing you can do to partially limit editing of a file using a standard text editor. Whatever problem you are trying to solve, this is not a solution. Next time around you might want to ask about the problem you are trying to solve rather than your proposed solution.

What is the option that makes Sublime Text add whitespace at the left of wrapped lines?

I want Sublime to treat my text files like they are source code files and show whitespace at the left of wrapped lines, like so:
beginning of long line blah blah blah, now it wraps
and it keeps going after an automatic indent
I tried opening the console and setting the option manually:
view.settings().set('indent_subsequent_lines', True)
but nothing changes, any ideas?
Well, that was fun. There's no easily accessible setting for this. But as you indicate, ST decides whether to add an extra indent when soft wrapping, from whether the syntax is considered code-like or plain text-like.
Being one or the other is up to the package defining the syntax to specify. So lacking a global setting from ST, you need to change your text packages. As an example, let's take Text. That contains Plain text.tmLanguage. In that you change
<key>scopeName</key>
<string>text.plain</string>
to
<key>scopeName</key>
<string>source.plain</string>
I'm unsure of whether there'll be ill effects from not keeping .plain.
One easy way to do this is to get the PackageResourceViewerpackage.
After install, do:
cmdshiftp
Type: Open Resource
return
Type: Text
return
Type: Plain text.tmLanguage
Make your edit and save.
PackageResourceViewer will save the modified Text package to your Packages directory. And sublime will display files considered to have Plain text-syntax, like they are code.
The caveat is that you need to do this for every text-syntax you want to be considered code.
As #AdamAL said, it's dependent on both the 'indent_subsequent_lines' setting as well as whether it's considered a "source" or a "text" language ... by default, "markup" languages (such as HTML, CSS, etc.) and plain text, etc., are considered "text", and programming languages such as C++, Java, PHP, etc., are considered "source".
"Source" languages will indent subsequent soft-wrapped lines (if the indent_subsequent_lines is true), whereas "text" languages will only indent up to the same level as the current line.
For each one you want to change, you'll need to edit the settings of the given language. #AdamAL's answer provides a great way to do this using the PackageResourceViewer package:
After install, do:
[Ctrl/Cmd]+[shift]+p, "Open Resource"
Find the name of the language you want to change, and find either the .sublime-syntax file or the .tmLanguage file. .sublime-syntax is supported from build 3084 of ST 3 and appears that it may trump values in the .tmLanguage file in supported versions, if present (when editing the definition of TaskPaper files provided by the "PlainTasks" package, my change didn't take when just editing the PlainTasks.tmLanguage, I had to edit the PlainTasks.sublime-syntax before it took).
In .sublime-syntax (which are YAML files) look for the first scope: line, where the main scope name of the language is identified (there will be lots of other scope: entries further down under contexts:).
In .tmLanguage (which are XML .plist files) look for the <string> following the <key>scopeName</key>.
Sublime Text Syntax Definition Documentation Reference:
scopeName
Name of the topmost scope for this syntax definition. Either source.<lang> or text.<lang>. Use source for programming languages and text for markup and everything else.
The <lang> (without brackets) is just an identifier string for the given syntax/language definition.
I noted that it seems that (in ST 3, anyway), no restart of Sublime Text is needed to get the changes to apply, if the edit is in the right place.
And also note that there may be other effects of changing this in more complex packages -- For example, in PlainTasks, the additional keybindings that it defines depended on it looking for a context that included text.todo, which I changed to source.todo in several places. So in order for the keybindings to work properly again, I also had to update my .sublime-keymap for that package. (This could also be because I changed it in a place besides the .sublime-syntax that I didn't need to. Just sayin' -- YMMV.)

Custom syntax highlighting in Geany

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!
Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype
There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"

WinMerge: How to compare files with the same content but different encodings?

Motivation: I am rewriting a doc -- text files to be processed later. The new sources now use UTF-8. Large portions of the sources are the same. I need to find differences.
Details: The old doc sources use the cp1250 encoding, the new sources use the UTF-8. Both new and old sources use the same line endings (CR+LF). I am using the Unicode version of the WinMerge application (WinMergeU.exe), version 2.12.4.0.
It almost works, but... When the lines differ, they are initially marked as block by the dark yellow, and the different portions are marked using the lighter colour. When moving the red block cursor there, the panes below show the different part.
However, the block of text is marked by the dark yellow also in cases when (the Unicode representation of) the text is the same. The red block moves also to those portions of the files. In such case, the two panes below (that show the differences) containt the same text and nothing is marked as different. See the picture below:
The very first line differs -- this is OK. But the second line has visually the same content. The only character outside of the ASCII range is Ú there. It has a different representation in the encoded sources. This causes the line marked as different, but the panes below does not mark anyting at the line as different.
See also the following paragraphs that are exactly the same (only the encoding in the sources differ, the same line ending is used).
It looks as if the initial comparison were based on binary representation of the lines. Is there any setting to tell WinMerge that the comparison (I mean the block marking) should be based on Unicode content?
I tried hard, but no luck, yet.
Update: The above question was for the latest stable 2.12.4. The beta version 2.13.22 works just perfectly for me. See my answer below.
This doesn't really answer your question about WinMerge, but have you considered using another diff program? One of my favorites is kdiff - http://kdiff3.sourceforge.net/
When I do a compare on KDiff using one UTF8 file and another Unicode file, I get the following:
Here is the compare screen - note that the encodings on the files are different, but the files are considered to be equal from a text standpoint:
I think it really should not be the task of a merge tool to allow the merging of files stored in different encodings.
An encoding is a function that maps bytes (stored on the disk or in memory) to characters (displayed on screen). Unfortunately, by default the encoding of a file is not stored together with the file. Therefore, any program that wants to open the file and display its contents needs to guess the encoding. While this sometimes works, it is also an error prone procedure.
Now, the character sets of different encodings do not overlap in general. So what is the merge tool supposed to do if you merge a character C from file A in encoding X into a file B in encoding Y, if character C is not part of the character set of encoding Y?
Thus, I think the task of a merge tool should be to merge the binary content. Anything else is a dirty hack and damned to fail at some level. (A merge tool maker may decide to provide character level merging, which also might work most of the time. But there is some guesswork involved.)
Therefore, I'd also recommend you first translate the old files to UTF-8 and then merge those with the new versions.
Just for your information. The question was for the latest stable 2.12.4. I have tried the beta version 2.13.22, and it works just perfectly for me. See the difference for exactly the same files -- only the first lines in the files were removed. (My big thanks to authors.)
Edit -> Options
Select 'Compare' from categories pane on left.
Check box 'Ignore carriage return differences' (UNIX, Windows, Mac)
I would recommend converting the files to the same encoding before diffing.
If you are working with a version control system I'd recommend the following:
Create a fresh checkout of the files
Convert all files to UTF-8
Commit the files
Copy your new files over
Use WinMerge
That way you end up with two commits in the history - one for the encoding change and another for the content changes and WinMerge will work as expected.
What about option File -> File Encoding... in WinMerge? It allows to set encoding for files independently.

Ruby: Create files with metadata

We're creating an app that is going to generate some text files on *nix systems with hashed filenames to avoid too-long filenames.
However, it would be nice to tag the files with some metadata that gives a better clue as to what their content is.
Hence my question. Does anyone have any experience with creating files with custom metadata in Ruby?
I've done some searching and there seem to be some (very old) gems that read metadata:
https://github.com/kig/metadata
http://oai.rubyforge.org/
I also found: system file, read write o create custom metadata or attributes extended which seems to suggest that what I need may be at the system level, but dropping down there feels dirty and scary.
Anyone know of libraries that could achieve this? How would one create custom metadata for files generated by Ruby?
A very old but interesting question with no answers!
In order for a file to contain metadata, it has to have a format that has some way (implicitly or explicitly) to describe where and how the metadata is stored.
This can be done by the format, such as having a header that says where the "main" data is stored and where the "metadata" is stored, or perhaps implicitly, such as having a length to the "main" data, and storing metadata as anything beyond the "main" data.
This can also be done by the OS/filesystem by storing information along with the files, such as permission info, modtime, user, and more comprehensive file information like "icon" as you would find with iOS/Windows.
(Note that I am using "quotes" around "main" and "metadata" because the reality is that it's all data, and needs to be stored in some way that tools can retrieve it)
A true text file does not contain any headers or any such file format, and is essentially just a continuous block of characters (disregarding how the OS may store it). This also means that it can be generally opened by any text editor, which will merely read and display all the characters it finds.
So the answer in some sense is that you can't, at least not on a true text file that is truly portable to multiple OS.
A few thoughts on how to get around this:
Use binary at the end of the text file with hope/requirements that their text editor will ignore non-ascii.
Store it in the OS metadata for the file and make it OS specific (such as storing it in the "comments" section that an OS may have for a file.
Store it in a separate file that goes "along with" the file (i.e., file.txt and file.meta) and hope that they keep the files together.
Store it in a separate file and zip the text and the meta file together and have your tool be zip aware.
Come up with a new file format that is not just text but has a text section (though then it can no longer be edited with a text editor).
Store the metadata at the end of the text file in a text format with perhaps comments or some indicator to leave the metadata alone. This is similar to the technique that the vi/vim text editor uses to embed vim commands into a file, it just puts them as comments at the beginning or end of the file.
I'm not sure there are many other ways to accomplish what you want, but perhaps one of those will work.

Resources