Content AND Presentation

2020-01-13 Automatic testing during rebasing

I am already accustomed to hidden gems in Git. Still, finding one is always nice. Recently, I was reading through git-rebase manpage, and two things drew my attention. The fact that one of the examples uses deadbee and fa1afe1 as commit hashes is of course funny, but not that important. What is much more interesting, however, is a feature I’ve never heard of before. Among various “actions” you can perform on commits during git rebase --interactive (you know, pick, edit, squash etc.), there is one which is different than others in that it is not associated with a commit, but may come between commits. You can say e.g. exec make, and when Git gets to this point during rebasing, it will execute make (or whatever command you want, say npm test). If this command exits with non-zero status (which means some kind of failure), Git will stop so that you can fix the problem. This way you can make sure that every commit on master compiles correctly (or even passes the tests). (See the manpage for details.) Very handy!

CategoryEnglish, CategoryBlog, CategoryGit

Comments on this page

2020-01-06 Org agenda statistics, part I

Some time ago I wrote about the org-batch-agenda macro. I decided to finally put it in good use. My goal is to write a command-line tool (or alternatively, an Emacs command) displaying some statistics about my pending tasks.

However, for that I needed to solve two (minor) problems. The first one is my Org-mode configuration. I didn’t want to load all my init.el when launching Emacs in a shell script (it takes about 15 seconds for my Emacs to start), and emacs -Q is not good, either, since my Org-mode (including the agenda) is heavily customized. The solution is quite obvious – I am going to put all my Org-mode-related settings in another file and just load it in my init.el. This way, I could use emacs -Q --load=~/.emacs.d/org-init.el to load just my settings and have Emacs start in under a second. Even better, I can prepare another start file, which will just load org-init.el and run org-batch-agenda with suitable parameters – in my case, I went with (org-batch-agenda-csv "a" org-agenda-span 'day). This way I could omit all the quoting problems with calling Elisp from the command line.

All this is a bit easier said than done. For instance, I have a few Org-related settings which do not need to be loaded in this scenario, like org-mru-clock. Also, I decided to kick (setq org-clock-persist 'history) out of org-init.el, since it made the Emacs print stuff like

Restoring clock data
Loading /home/mbork/.emacs.d/org-clock-save.el (source)...

to stderr, and while redirecting stderr to /dev/null is not hard, I didn’t really want extra steps.

Anyway, this is the first part. The second one is taking the agenda for today in csv format and do something useful with it. A natural solution would be probably to put the results of running org-batch-agenda into some buffer and use Elisp to analyze the resulting csv. This looks promising, but has some issues. One of them is that org-batch-agenda sends its output to standard-output. This is an Emacs concept, much similar to Unix’s stdout. By default, it is nil, which means that the output lands in the echo area – or on the real stdout if Emacs is launched in batch mode. (A minor gripe is that somehow org-batch-agenda seems to put an extra newline on stderr. I looked at its source, but I have no idea why it happens. So it looks like I am going to redirect stderr to /dev/null after all.)

A worse thing is how org-batch-agenda works under the hood: it just runs the agenda as usual and scans the created buffer to get all the info, then outputs it as csv. The problem here is that it is apparently only meant to be run in Emacs batch mode, since it does all the things normally done by the org-agenda command, like creating the agenda buffer and window and switching to it.

So, it seems that after all these preparations I can just say emacs -Q --script ~/.emacs.d/org-init.el 2> /dev/null, and get a nice csv agenda on stdout. I can now do all sorts of nice stuff with it. Some of my ideas are: counting the overdue tasks (so that I could beemind their number), randomly selecting an overdue task to work on, or prepare a simple web-based interface so that I can put Emacs on a server and look at my agenda for the day from my smartphone.

(to be continued)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode

Comments on this page

2019-12-24 Christmas 2019

So, it’s Christmas Eve again! Thanks be to God for His mercy and coming to us as the Child! This year, I have special reasons to be thankful, since my family got through a difficult time of serious illness of one of us. I am sure every one of my readers has something to be grateful for for – don’t hesitate to kneel before God the Almighty, his Son Jesus Christ and the Holy Spirit and give thanks!

As usual, my Christmas present to all my readers is a decade of Rosary for you.

CategoryEnglish, CategoryBlog, CategoryFaith

Comments on this page


CategoryEnglish, CategoryBlog