Add gcc error text parsing to Kate? - parsing

It seems an obvious improvement, in Kate, to jump directly to the error location given in a gcc error message. It would great if it can be made to work directly in Kate's terminal, but I would settle for a tool that can yank text off the x clipboard. Failing that, is there a way to write an add-on for Kate to do this?
Thanks.
Mike.

from the terminal we can run something like this:
$ kate source.cpp --line=45
you could write a script to parse gcc output and re-open kate to that line in the source. If kate already has the source code open, it will simply emulate a jump to the line.

There is "Build" plugin for Kate, which does also stderr parsing, and understand GCC error syntax.
So for example you can easily configure in Kate to build your project with make (and KDevelop is sharing this part of Kate source and plugin, although KDevelop has extra plugins for project management), and you will see in the Build plugin output parsed errors, clicking on them will direct you to the particular source file and line.
(but I was just looking around if it can even mark the error lines in the source visually, and actually there's nothing like it? From my limited understanding of the Kate plugin API I would be slightly afraid this is not trivial to add to current Build plugin, but I didn't dig into the Kate sources enough to fully understand its architecture and what are the true limits for plugin code).

Related

Getting llvm-cov to talk to codecov.io

I'm in the process of (finally!) setting up code coverage monitoring for my brand new C++ project. Due to the fact that I need some advanced C++20 features (read, coroutines), I am using clang 6 as compiler.
Now, I followed this guide on how to do basic code coverage for your project, and everything worked like magic. If I do:
clang++ -fprofile-instr-generate -fcoverage-mapping test.cpp -o test.out
LLVM_PROFILE_FILE="coverage/test.profraw" ./test.out
llvm-profdata merge -sparse coverage/test.profraw -o coverage/test.profdata
llvm-cov show ./test.out -instr-profile=coverage/test.profdata
I get a nice, colored report on my terminal that tells me what is covered and what is not.
So far so good! I thought I was close to what I wanted, but then the pain started when I tried to get the report uploaded to codecov.io.
I have tried a few things, including:
Running their https://codecov.io/bash script on my coverage folder in the hope that maybe it would catch on my test.profdata. No dice, and it makes sense, since even llvm-cov needs the path to the executable file to run.
Using the export functionality: when running llvm-cov export --instr-profile=coverage/test.profdata ./test.out I get a good-looking JSON file (via terminal). I tried throwing the output in a coverage.json file, which actually got uploaded, but then codecov just says that there was an error parsing it, with no further information.
I'm feeling completely lost. Everything seems so black-box-ish on their website that I just don't understand how to get anything done that doesn't by chance perfectly fit the cases that they can manage.
How can I get this working with codecov? If codecov can't handle my reports, is there any other equivalent online code coverage that I can use to get this to work?
It looks like the bash script codecov uses to upload coverage data to their site looks for files matching a wide range of patterns associated with formats that it understands. These are poorly documented, but you can at least see which patterns are viable by looking at the script on Github. Of course, this doesn't tell you what expectations codecov has about the format of files matching a given pattern, as you discovered when your coverage.json file was rejected.
Through trial and error I have found that the following produces a file that codecov will interpret correctly when you run the bash script:
llvm-cov show ./test.out -instr-profile=default.profdata > coverage.txt
I haven't extensively tested what file names are allowed, but it seems that you can put whatever additional characters you want between coverage and .txt in the name of the file that you're piping the coverage data to (e.g. you could call it coverage_my_file_name.txt).
EDIT: Just in case this is helpful to anyone, it turns out that an important corollary to the above is that it's critical that you avoid naming anything that isn't a coverage report something that matches this pattern. I just dealt with a scenario where I had a bunch of executables named coverage_[more_text_here].out that were getting uploaded with the reports. It turns out that attempting to parse assembly code as a coverage report can cause codecov to mysteriously fail without any useful errors.
Another option is to use GCOV profiling, which is a little less precise than source-based, but it is supported by codecov.io. You need the "--coverage" compiler flag to enable it.
You can use grcov (which you can also download from https://github.com/mozilla/grcov/releases) to parse the gcno/gcda files and upload them via the codecov.io bash uploader:
grcov OBJ_DIR -s SRC_DIR -t lcov --branch > lcov.info
bash codecov.sh -f "lcov.info"
I'm planning to add support for source-based reports to grcov, which will make it easier to support the format on codecov too.

How to print Smalltalk code from Pharo/Squeak?

What is the best way to print - syntax colored and well formatted - code from Pharo/Squeak on paper?
1) Is there a way to print directly from within Pharo/Squeak? (i use it on macosx)
2) Is there a way to export syntax colored, well formatted code from Pharo/Squak?
3) Are there external tools to color and format a filed out piece of code?
For the appendix in my master thesis I used the Pier CMS-to-LaTeX converter in the Pier-Documentation package. However, this plugin only takes class comments and method comments into consideration, it does not print the source code. Pier also provides a package ShoutPier for syntax highlighting of Smalltalk code, so I guess it would require little work to bring the two together. You can find the mentioned extension packages in http://source.lukas-renggli.ch/pieraddons.html.
Pharo browsers seem to use syntax highlighting.
What difficulty are you having reading Smalltalk code using the browsers and senders/implementors ?
Edit: Would something that produces UML give the overview you're looking for? The Dandelion website only shows downloads for old Squeak versions - I don't know if they would work with Pharo.
And perhaps this GSoC project "Generate UML diagrams from Smalltalk code for Pharo" suggests not.
Here's how I did it on my Mac, I think this should work on other platforms too.
Save your categories to a Monticello local folder on your disk -- see the Pharo manual on how to do this: http://book.pharo-project.org/book/PharoTools/Monticello/?_s=hdGOLc_FXsvVY1iR&_k=YYH-Ln8f5mtWZ8z2&_n&148
Browse to this folder, and unzip the .mcz file
You'll see all your code in snapshot/source.st file
You'll need to edit this a bit, to remove the ! characters for e.g., there might be a tool to do this?
-Eric.
There is webdoc project, which allows you navigating code in web browser:
http://ss3.gemstone.com/ss/webdoc.html
(and of course you can print code from your favorite web browser)..
1) Install shout from www.squeaksource.com
2) I don't know. May be you can customize shout.
3) In gnu-smalltalk you have a smalltalk mode for emacs. But I am not pretty sure to understand what you are looking for.

How can I build PDF LaTeX documents with ANT (or some other build system if you prefer)?

The team I work for manages a large collection of technical documentation which is written in LaTeX.
Currently all the documentation we have is manually built by the editors and then checked into a version control system. Sometimes people forget to compile their documents so we have a situation where the PDF and .tex files are often out of step. Unfortunately when this happens our users find themselves reading old versions of our document.
I've managed to hack a simple script to build PDFs using Make - it's rather clumsy.
I was wondering if there was a better way to do it? Most people in our department use Eclipse + Pydev for a Python project which means we are all very familiar with this IDE. I know that Ant plays nicely with Eclipse, so might we be able to use this tool for our doc building?
So what's the best way of doing this? I hope I will not have to learn everything there is to know about a new build-system in order to automate the building of some quite simple docs.
There is an external Ant task for LaTeX PDF generation, though the site is in German.
To use it, download the jar to a location on your machine, then define a taskdef as follows:
<taskdef name="latex" classname="de.dokutransdata.antlatex.LaTeX"
classpath="/path/to/ant/lib/ant_latex.jar"/>
Then to use it, define a target like this:
<target name="doLaTeX">
<latex
latexfile="${ltx2.file}"
verbose="on"
clean="on"
pdftex="off"
workingDir="${basedir}"
/>
</target>
Where ltx2.file is the file to process.
This is a link to the howto page listing the parameters. If you need any more options, my German is just about passable enough to explain, maybe.
There is also a maven plugin for LaTeX, but I can't find any documentation.
Haven't tried it, but I remember seeing a blog post about it.
If you know python, this blog post might be interesting
EDIT: Also, I would assume that you're using some kind of version control system, and I can't say for sure, but I use git to manage all my latex docs, and it might be possible to use some kind of post-commit hook to execute a script to rebuild the document. This would depend on how your repository is structured... just thinking out loud, so to speak.
I went into great detail on a large number of build systems for latex in this question, but its slightly different in your case. I think you want rubber or latexmk. The latex-makefile seems a good idea, but only supports building via postscript, which might not be your build process.
In general, its a good idea to keep generated files outside of version control for just this reason. A good exception is when specialist build tools are not widely available, and your situation sounds similar. You might do better with a commit-hook to build automatically upon commit.
I guess I should also point out that committing something without first building it and checking it is a deadly sin, so a better solution might be to stamp that out.
Maven is a better alternative as build system compared to Ant. So I would recommend a maven-plugin to generate PDF from LaTeX sources. Have a look at mathan-latex-maven-plugin

Texments package not working on Ubuntu

I am trying to use the Texments Latex package on Ubuntu to do syntax highlighting.
Texments is a wrapper around Pygments.
I installed Texments and followed the steps to add the style file to the path.
But when I try to compile the .tex file, I get the error.
!Undefined Control Sequence
and then it prints out a bunch of wierd characters and places the ? prompt.
Anybody facing this error? What is the resolution?
If there is any other better way to provide syntax highlighting of source code I would be glad to accept it.
I know there is something called "listings" but frankly, i did not find the colors so good in it.
Thanks,
Perhaps you could give minted a try … it basically does the same as texments but has more features and is a little more robust in the face of errors.
Furthermore, as the maintainer of minted I’m always glad of error reports. ;-)
Texments uses a special control sequence for pdftex to allow shell escapes, needed to call the pygmentize binary. You need to call it with pdflatex, and you need to pass pdflatex the -shell-escape switch. Cf. the texments documentation.

Printing code with syntax highlighting? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 months ago.
Improve this question
I have occasion to need to print code (Horrors!!! ;) ), and i was wondering what editor or tool would i use to print that code out with proper formatting and syntax highlighting? If it's important, it will be c# code but ideally the tool will work for as many languages as possible. Can Notepad++ or something handle this?
You can use Vim! It's probably installed already if you're on modern Linux/MacOS and an easy install if not.
:syntax will turn syntax highlighting on and :hardcopy will print it. There's syntax highlighting definitions for many languages out there. The default look is usually optimised for screen display, but you can fix that.
Simply open the file on command line with vim <filename>, type :syntax on<ENTER>, then :hardcopy<ENTER> to print it. Quit Vim with :q!<ENTER>.
There's also the :TOhtml command which will open the current selection as HTML in a new Vim window. Capture the entire document with :%y<ENTER> followed by :TOhtml<ENTER> to open it.
Yes, Notepad++ can certainly print code with syntax highlighting.
Colour printing would obviously be preferable, but on the occasions when I've printed in black and white, the subtle differences in colour [rendered as shades of grey, of course] can be difficult to distinguish.
However, I think a little customisation of the colour schemes should make this less of a problem.
New Answer:
Use TextMate. It prints colored code automatically. There's no setup. Just print. In case previous or newer versions can't do this I'm using TextMate version 2.0.23
Old Answer, and the answer for people who don't have Macs:
Use vim. Its the easiest method to do it in my experience by far, that is, once you know how.
Vim comes pre-installed on Macs, btw. And I know how you special people like colors, so I'm going to make this impatientbusinessman-proof for the benefit of all.
1.) open file
vim filename.m
2.) enable syntax coloration (mine did not have enabled by default)
:syntax on
3.) print
:hardcopy
Vim will choose your system's default printer without asking you so make sure you set that up first.
4.) exit the program (this is actually not a given)
:q
http://pygments.org/ is one option. It supports a ton of languages, and since it's written as a python library, you can script the conversion process however you want.
Visual Studio will, and allows you have a completely separate configuration for printing.
I recently compared the 2 solutions already mentioned : vim & pygments. They both give great results, but there is how you can practically use them quickly:
pygments does not provide direct export to PDF. Hence, the simplest solution I found was to export to HTML and then use wkhtmltopdf. You can combine both operations using the following bash script:
src2pdf () {
local noext="${1%.*}"
pygmentize -O full -o "$noext.html" "$1"
# enabling line wrapping in <pre> blocks
perl -i -wpe '/<style.*>$/&&($_.="pre{white-space:pre-wrap;}\n")' "$noext.html"
wkhtmltopdf "$noext.html" "$noext.pdf"
rm "$noext.html"
}
for vim, it's as simple as this: TERM=xterm-256color vim '+hardcopy >out.ps' +q code.src
I found out that the $TERM environment variable can affect the output colors, so I prefer to set it explicitly.
And finally, you may need to tweak your .vimrc a little:
set printfont=:h9
set printoptions=number:y,left:5pc
The tool called enscript is very much the tool for doing this. It is very powerful, is not tied to an editor nor a language and you can create PDF's with syntax highlighting.
The documentation pretty much says it all.
enscript man page
Under unix you might want to try a2ps. It is flexible and produces nice results.
I while ago I created a household python script that wraps pygments into a small console utility. It works with any language supported by pygments.
Also if you happen to use eclipse, you could simply copy the selected text in the editor and then paste it in a RTF-aware editor like MS Word - it will preserve all the colors, fonts and formatting.
If you have problems with Visual Studio 2012 concerning the highlighted printing an handeling the described problem:
Download and install this Power Tool which implements the color
printing, besides some other features and bug fixes. Works for me!
Solution For Bash Shell
Add this line to ~/.bashrc if you are using UBUNTU
or, to ~/.bash_profile if you are using MAC
If that file does not exists, create it.
alias lprc='vim -me -c ":syntax on" -c ":hardcopy" -c ":q"'
source ~/.bashrc or source ~/.bash_profile
To print colored hello.py just do this:
lprc hello.py instead of lpr hello.py
Use ConTEXT programming editor (which is free). I am using it for both generating .pdf-s with syntax highlighted source code and printing to paper.
There are many ConTEXT syntax highlihting definitions to download and you can make your own highligher file which will BTW be highlighted using the ConTEXT Highlighter Files highlighter definition.
I do it downloading js and css files from
https://prismjs.com/
There are so many 5-7 options to select the theme and language highlighter. Once you select a theme and download the tiny js/css files the next thing you need to do is rename the code file to html, and call the css/js files. Open the html in a browser and print it. Done!
You can also use this in case you've to print with bnw syntax highlighting https://github.com/SGI-CAPP-AT2/code-highlight-n-print

Resources