Showing D Coverage Results as Overlays in Source Buffer - emacs

The D language compiler DMD outputs its coverage analysis in a file containing the original source as
| inout(Ix)[] prefix() inout
| {
2037| assert(!keys.empty);
2037| final switch (keys.length)
| {
000000000| case 1:
000000000| return keys.at!0[];
2037| case 2:
| import std.algorithm.searching : commonPrefix;
2037| return commonPrefix(keys.at!0[], keys.at!1[]);
| }
| }
that is, the original source where each line has been prefixed by a 10-character column containing the execution count (if relevant).
When opened in Emacs I would like this file to be presented as a read-only version of the original source buffer with an green overlay for the lines exercised at least once and with red overlay for the lines never exercised.
How is this most conveniently implemented in Emacs-Lisp? For instance is there a way to efficiently hide the first 10 characters of each line in a buffer?
See also: https://github.com/flycheck/flycheck/issues/1074

Related

Replacement of text in xml file by AHK - get error when trying to open as xml file

I am using an AHK script to replace some text in an .xml file (Result.xml in this case). The script then saves a file as Result_copy.xml. It changes exactly what I need, but when I try to open the new xml file, it won't open, giving me the error:
This page contains the following errors:
error on line 4 at column 16: Encoding error
Below is a rendering of the page up to the first error.
I only replaced text at line 38 using:
#Include TF.ahk
path = %1%
text = %2%
TF_ReplaceLine(path, 38, 38, text)
%1% and %2% are given by another program and are working as should
I also see that the orginal Result.xml is 123 kb and Result_copy.xml is 62 kb, even though I only add text. When I take Result.xml and manually add the text and save it, it's 123 kb and still opens. so now both files contain exactly the same Characters, but one won't open as xml. I think that something happens during saving/copying, which I don't understand.
Could someone help me out on this one? I don't have a lot of experience in AHK scripting and do not have a programming background.
Thank you in advance!
Michel
TF.ahk contains this:
/*
Name : TF: Textfile & String Library for AutoHotkey
Version : 3.8
Documentation : https://github.com/hi5/TF
AutoHotkey.com: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=576
AutoHotkey.com: http://www.autohotkey.com/forum/topic46195.html (Also for examples)
License : see license.txt (GPL 2.0)
Credits & History: See documentation at GH above.
TF_ReplaceLine(Text, StartLine = 1, Endline = 0, ReplaceText = "")
{
TF_GetData(OW, Text, FileName)
TF_MatchList:=_MakeMatchList(Text, StartLine, EndLine, 0, A_ThisFunc) ; create MatchList
Loop, Parse, Text, `n, `r
{
If A_Index in %TF_MatchList%
Output .= ReplaceText "`n"
Else
Output .= A_LoopField "`n"
}
Return TF_ReturnOutPut(OW, OutPut, FileName)
}

VSCode Folders Not Sorting Alphabetically

Visual Studio Code Explorer pane is sorting my folders oddly. I want to validate this is truly an issue before reporting it as a bug. I have vscode 1.47.2. I'm fairly sure this wasn't always an issue. Here's an example:
I would expect that a folder named "aaa.xxx.iii" would be alphabetically sorted before the folder named "aaa.yyy". In fact, when I look at the list in File Explorer, it is indeed sorted correctly.
I am not using a workspace file. I have searched the entire directory structure and I have no files suffixed with .code-workspace. I know this can be an issue in multi-root workspaces. However, I am just using "Open Folder" to open this solution.
I have also checked the settings under Workspace Settings, Features, Explorer, Sort and it is set to default (Alphabetic, Folders before Files). I tried changing to Modified sort order and back with no luck.
I would expect that a folder named "aaa.xxx.iii" would be alphabetically sorted before the folder named "aaa.yyy"
It is alphabetically sorted, just ASCII sorted!
ASCII values:
a = 97
b = 98
i = 105
x = 120
y = 121
. = 46
Therefore:
aaa = 291
aaa.xxx = 697
aaa.yyy = 700
aaa.xxx.iii = 1,012
However, there seems to be some variation to their logic. They actually split filenames via a filename regex (and they use the same logic for comparing directories and filenames). They effectively compare against a filename first, before even considering the extension using the following regex:
const FileNameMatch = /^(.*?)(\.([^.]*))?$/;
And then it will only consider extensions when it returns 0, for not greater than or less than.
Using that regex: in your example, aaa.xxx, aaa is the filename, .xxx is the 'extension`.
With aaa.yyy; aaa is the filename and compared against aaa.xxx.iii, you get it .iii is the extension. Ergo, aaa.yyy, or the name without the .yyy extension: aaa < aaa.xxx or aaa.xxx.iii with the extension
Here is their logic:
explorerViewer.ts
comparers.ts:
export function compareFileNamesNumeric(one: string | null, other: string | null): number {
const [oneName, oneExtension] = extractNameAndExtension(one, true);
const [otherName, otherExtension] = extractNameAndExtension(other, true);
const collatorNumeric = intlFileNameCollatorNumeric.value.collator;
const collatorNumericCaseInsensitive = intlFileNameCollatorNumericCaseInsenstive.value.collator;
let result;
// Check for name differences, comparing numbers numerically instead of alphabetically.
result = compareAndDisambiguateByLength(collatorNumeric, oneName, otherName);
if (result !== 0) {
return result;
}
// Check for case insensitive extension differences, comparing numbers numerically instead of alphabetically.
result = compareAndDisambiguateByLength(collatorNumericCaseInsensitive, oneExtension, otherExtension);
if (result !== 0) {
return result;
}
// Disambiguate the extension case if needed.
if (oneExtension !== otherExtension) {
return collatorNumeric.compare(oneExtension, otherExtension);
}
return 0;
}
So it appears, for the most part, they are just using Intl.Collator with basic name value a < b logic, with some variations of course.
It also appears they disambiguate by length, meaning foo1 and foo01 are considered equal. line 169
Settings
The setting you described only affects 'how they are displayed', in a way sorted yes, but mostly how they are shown to the user, not really how they are sorted programmatically as I interpret it.
// Controls sorting order of files and folders in the explorer.
// - default: Files and folders are sorted by their names, in alphabetical order. Folders are displayed before files.
// - mixed: Files and folders are sorted by their names, in alphabetical order. Files are interwoven with folders.
// - filesFirst: Files and folders are sorted by their names, in alphabetical order. Files are displayed before folders.
// - type: Files and folders are sorted by their extensions, in alphabetical order. Folders are displayed before files.
// - modified: Files and folders are sorted by last modified date, in descending order. Folders are displayed before files.
"explorer.sortOrder": "default",
So it's more of a presentation setting for files/directories not the names themselves.
If you look at the explorerViewer.ts control flow you will see:
switch (sortOrder) {
case 'type':
if (statA.isDirectory && !statB.isDirectory) {
return -1;
}
if (statB.isDirectory && !statA.isDirectory) {
return 1;
}
if (statA.isDirectory && statB.isDirectory) {
return compareFileNamesNumeric(statA.name, statB.name);
}
break;
And now we can visualize going back to how directories are sorted with the same function; re if (statA.isDirectory && statB.isDirectory)
It appears this is an outstanding issue. I changed my search terms on GitHub and found the original discussion. It seems there's no resolution as of this comment.
https://github.com/microsoft/vscode/issues/99955

Julia macros: #__FILE__ #__LINE__ in macro

This code:
macro FL(message)
return #sprintf("%s:%d | %s", #__FILE__, #__LINE__, message) # line 2
end
println(#FL("m")) # line 4
prints fl.jl:2 | m. How can I make it print fl.jl:4 | m?
The following will work in the current Julia nightly:
macro FL(message)
return :(#sprintf("%s:%d | %s", $(string(__source__.file)), $(__source__.line), $(esc(message)))) # line 2
end
println(#FL("m")) # line 4
This was made possible by the following implementation pull request. It is not possible in any officially released version, unfortunately.
Though there may be more elegant ways to do this, if you don't want this to block your progress on other fronts, why not just pass the line number to the macro...
macro FL(message, line)
return #sprintf("%s:%d | %s", #__FILE__, line, message)
end
println(#FL("m", #__LINE__))

Creating macros in netbeans

I wish to create macro in Netbeans to put block comment over function. I have preference of code formatting over file save. So When I close file it saves code automatically and format it.
Issue is when I create function and comment it. It unformatted my whole block of code like this.
/**
*function abc(){
*var a, b = 50;
*}
*/
I wish to create comment like this. so it keep my coding properly formatted as well.
/*
|
| function abc(){
| var a, b = 50;
| }
|
*/
You can add your own macro by Following this instructions:
Edit->Start Macro Recording
Edit->Stop Macro Recirding
It Will pop-up one Box For Editor Macros->Add Your Choice of Macro Name
In code area add Your custom comment code in " your code "; Like,
Blockquote
"/*
|
| function abc(){
| var a, b = 50;
| }
|
*/"
Assign a Short Cut Key to your Custom Macro.
That's It
Though I couldn't find macro for the same. But I found alternative. Use Ctrl+Shift+R toggle, for multiple line action at same time & add pipeline sign. But it take extra effort for starting and ending comment.

xText Variable/Attribute Assignment

I built a grammar in xText to recognize formal expressions of a specific format
and to use the generated object tree in Java.
This is what it looks like:
grammar eu.gemtec.device.espa.texpr.Texpr with org.eclipse.xtext.common.Terminals
generate texpr "http://www.gemtec.eu/device/espa/texpr/Texpr"
Model:
(expressions+=AbstractExpression)*
;
AbstractExpression:
MatcherExpression | Assignment;
MatcherExpression:
TerminalMatcher ({Operation.left=current} operator='or' right= MatcherExpression)?
;
TerminalMatcher returns MatcherExpression:
'(' MatcherExpression ')' | {MatcherLiteral} value=Literal
;
Literal:
CharMatcher | ExactMatcher
;
CharMatcher:
type=('text'|'number'|'symbol'|'whitespace') ('(' cardinality=Cardinality ')')?
;
/* Kardinalitäten für CharMatcher*/
Cardinality:
CardinalityMin | CardinalityMinMax | CardinalityMax| CardinalityExact
;
CardinalityMin: min=INT '->';
CardinalityMinMax: min=INT '->' max=INT;
CardinalityMax: '->' max=INT;
CardinalityExact: exact=INT;
ExactMatcher:
(ignoreCase='ignoreCase''(' expected=STRING ')') | expected=STRING
;
/* Variablenzuweisung
*
* z.B. $myVar=number
* */
Assignment:
'$' name=ID '=' expression=MatcherExpression
;
Everything works fine except for the 'cardinality' assignment.
The Expressions look like this:
text number(3) - (an arbitrary amount of letters followed by exactly 3 numbers)
symbol number(2->) - (an arbitrary amount of special characters followed by at least 2 numbers)
whitespace number(->4) - (an arbitrary amount of whitespaces followed by a maximum of 4 numbers)
number(3->6) - (at least 3 numbers but not more than 6)
When I run Eclipse with this grammar (so that my language is recognized and has code completion and so on), everything I type is shown in the "Outline"-tab as a tree-structure as it should, except for the cardinality values.
When I add a cardinality statement to a CharMatcher, the little plus appears before it, but when I click on it it just disappears.
Can anyone tell me why this does not work?
I found the solution myself, I think the problem was that the compiler could not decide which class to create at this point:
Cardinality:
CardinalityMin | CardinalityMinMax | CardinalityMax| CardinalityExact
;
CardinalityMin: min=INT '->';
CardinalityMinMax: min=INT '->' max=INT;
CardinalityMax: '->' max=INT;
CardinalityExact: exact=INT;
So I simplified the whole thing a little, it now looks like this:
Cardinality:
CardinalityMinMax | CardinalityExact
;
CardinalityMinMax: (min=INT '..' max=INT) | (min=INT '..') | ('..' max=INT);
CardinalityExact: exact=INT;
It is still not shown in the "Outline"-Tab, but I suppose that is a problem of the visualisation.
The generated classes now work as intended.