Archive for the ‘Tech’ Category

Another day, another Ubuntu upgrade, another broken Marble Mouse. Have I written this before? Well, yes, several times before.

With the release of 17.10, everything broke because Wayland was bought into replace X. With 18.04, wayland is out again — something which I am pretty glad about, because in my experience it was pretty unstable, with the desktop crashing out to login fairly often.

The 17.10 solution appears to have been:

gsettings set org.gnome.desktop.peripherals.trackball scroll-wheel-emulation-button 8

This fails again on 18.04. Fortunately, the solution is quite simple which is to just return to the libinput configuration that we had before.

xinput --set-prop "Logitech USB Trackball" "libinput Scroll Method Enabled" 0 0 1
xinput --set-prop "Logitech USB Trackball" "libinput Button Scrolling Button" 8

I look back to the good old days of gpointing-device-settings which uses to work and looked nice. Why have we come so far from here?

Oh dear, if it seems that we have been here before, it’s because we have. Another Ubuntu upgrade, another broken Marble Mouse.

Took my a while to work out this one, but the answer is hidden in a bug report for RedHat. Actually, if I had read my last blog post I might have worked it out also.

What happens is Wayland, the new, er well what ever it is, for 17.10 looks at the marble mouse, says “it has no scroll wheel”, so disabled the input method. Which is unfortunate because then the emulation doesn’t work.

The solution is to turn it on again:

xinput --set-prop "Logitech USB Trackball" "libinput Scroll Method Enabled" 0 0 1
xinput --set-prop "Logitech USB Trackball" "libinput Button Scrolling Button" 8

Dearie me.


Worked. Was happy. Now it’s stopped working. Less happy.

Years ago, after problems with my wrist, I moved to using a trackball when ever I can. Good move it was too, but I am left with one pain. I use a Logitech Marble Mouse and it has no scroll wheel; this is sad because I have loved scroll wheels since they came out. So, instead, I use scroll wheel emulation — you hold down a button and trackball moves are interpreted as scroll events.

Now, this leaves me with one remaining pain. For no readily apparent reason, the method for configuring it has moved from one place to another, normally every couple of releases. At one point, it was in xorg.con, then in HAL, for a joyful period with the gpointer-settings GUI which then broke and disappeared, and I ended up with xinput run from a shell script.

Having just upgrading to Ubuntu 17.04 guess what? Broken again.

I have been using this:

xinput set-button-map "Logitech USB Trackball" 1 2 3 4 5 6 7 8 9
xinput set-int-prop "Logitech USB Trackball" "Evdev Wheel Emulation Button" 8 8
xinput set-int-prop "Logitech USB Trackball" "Evdev Wheel Emulation" 8 1
xinput set-int-prop "Logitech USB Trackball" "Evdev Wheel Emulation Axes" 8 6 7 4 5
xinput set-int-prop "Logitech USB Trackball" "Evdev Wheel Emulation X Axis" 8 6
xinput set-int-prop "Logitech USB Trackball" "Evdev Drag Lock Buttons" 8 9

Well from a bug report here:

It turns out that the reason this no longer works is because Evdev is not used anymore, thanks to the move to Wayland; now I need to use libinput. Unfortunate, since these “big” linux issues (unity, wayland, systemd) are something that I try very hard not to have to care about at all.

I tried lots of dead reckoning with libinput but got all sorts of errors, or just non-functioning. Eventually, I worked out the right way forward this way.

xinput --list
⎡ Virtual core pointer                        id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                    id=4    [slave  pointer  (2)]
⎜   ↳ HID 1267:0103                                 id=11   [slave  pointer  (2)]
⎜   ↳ Logitech USB Trackball                        id=12   [slave  pointer  (2)]

Which gives the device number (12). Then

xinput --list-props 12
Device 'Logitech USB Trackball':
        Device Enabled (136):   1
        libinput Scroll Methods Available (284):        0, 0, 1
        libinput Scroll Method Enabled (285):   0, 0, 1
        libinput Scroll Method Enabled Default (286):   0, 0, 1
        libinput Button Scrolling Button (287): 2
        libinput Button Scrolling Button Default (288): 2

This is mostly correct — the last 1 on Scroll Method Enabled means “button”. But the 262 on Button Scrolling Button is not so good. It needs to be 8.

Next up, set-int-prop is deprecated, so lets not use that. So I tried this instead:

xinput set-prop 12 287 8

The 12 is the device number, 287 is the property number (found from --list-props above), and the 8 is the correct button. But this is ugly and incomprehensible; more, I do not know if the numbers (12 and 287) will remain the same across all my computers. So, let’s use names instead.

xinput --set-prop "Logitech USB Trackball" "libinput Button Scrolling Button" 8

Which leaves me with these properties:

xinput --list-props 12
Device 'Logitech USB Trackball':
        Device Enabled (136):   1
        libinput Scroll Methods Available (284):        0, 0, 1
        libinput Scroll Method Enabled (285):   0, 0, 1
        libinput Scroll Method Enabled Default (286):   0, 0, 1
        libinput Button Scrolling Button (287): 8
        libinput Button Scrolling Button Default (288): 2

In the end, the configuration is simple. Now, please, please devs, don’t break it again!

  • Update

The original post was wrong but settings from earlier experiments were persisting when I thought they were not.

I have written about assess previously (; it is a tool which provides predicates, macros and functions to support testing for Emacs. It is actually agnostic to the test environment, although has specialised support for ERT.

My new release of assess (v0.3.2) includes one significant change, and two new features. I have updated the call capture functionality — the first version stored all the call data in a global variable, which was quick and easy, but clearly not a log term solution. It now uses closures instead which means that several functions can be captured at once. This also allows the first new feature, which is the ability to capture calls to hooks, with the function assess-call-capture-hook, which takes a hook and a lambda, and returns any calls to the hook when the lambda is evaluated. As an example usage, from assess-call-tests.el:

  '(nil nil)
   (lambda ()
     (run-hooks 'assess-call-test-hook)
     (run-hooks 'assess-call-test-hook)))))

This is good functionality and should be very useful. The API could be improved a bit; a macro version would avoid the explicit lambda, for example. And returning a list of nil means this function also works with hooks with args, but is a bit ugly for hooks without (which are the majority).

The second area that I wanted to address has come about because of my hacking into the Emacs undo system. This is hard to test automatically; I have often found myself writing things like this test from simple-test.el.

   (setq buffer-undo-list nil)
   (insert "hello")
   (member (current-buffer) undo-auto--undoably-changed-buffers)))

This is okay, but it’s painful to write; I am trying to robotize Emacs, and it’s not easy. Some times it’s hard to work out exactly what set of functions you need to call. It would be much easier just to type a key sequence and have Emacs run this for you.

Fortunately, Emacs has special support for this in the form of keyboard macros; you can remember, store and save any set of keypresses and run them, rerun them, automate them or, most importantly, save them to a file as a lisp expression. This example, for instance, comes from viper-test.el.

(kmacro-call-macro nil nil nil
                    ;; Delete "c"
                    left left left
                    ;; Delete "a"
                    ;; C-/ or undo

This is okay, but it’s still not ideal. I have had to add comments to make the test clear by hand. It’s not easy to read, and what is that 67108911 about? It comes from somewhere in Emacs and is stable into the future. But, you only have my word for it that this is undo. It would be all too easy to get this wrong, to have the wrong comment. Tests need to be readable.

Fortunately, Emacs provides a nice solution, in the form of edmacro — this is a major-mode for editing macros after they have been created. It also defines a human readable version of a macro. We can parse this and then execute it directly. This example comes from simple-test.el.

C-c C-o                 ;; latex-insert-block
RET                     ;; newline
C-/                     ;; undo

The advantage of this is that I didn’t actually write this string; I recorded the macro, the edited it and copied the contents of the edmacro buffer.

This is still not easy enough, though; I want an easier way of editing the macro as it appears in the test. This is, unfortunately, difficult as the edit-kbd-macro is not easy to invoke programmatically — it absolutely hard-codes user interaction (I did even try invoking edit-kbd-macro using a keyboard macro!). So, I have given up with that approach in the short term. Instead, I have written a function assess-robot-execute-macro that combines read-kbd-macro and execute-kbd-macro, but also sets the macro as the last macro, making it easy to edit. I’ve also added a keybinding to edmacro to copy the macro to the kill-ring. And here is a test using it:

hello                   ;; self-insert-command * 5

This also demonstrates the final quirk. Keyboard macros work in which ever buffer is selected — not the one which is current. We cannot use with-temp-buffer to select on temporarily and run the macro in it. So I have added macros to display a buffer temporarily instead.

As with many parts of assess, the back end is quite convoluted and complex, as many parts of Emacs were not written with testing in mind (that is they predate the whole idea of unit testing by many years!). But, I hope that the API that assess provides is simple, clear and flexible.

Assess is available at github and MELPA.

Feedback is, as always, welcome.


Assess is my new package supporting testing in Emacs. It has grown out of my frustration with the existing framework while building the lentic package (

For quite a while, the only testing framework in Emacs has been ERT (the Emacs Regression Testing tool) which is part of core. More recently, there have been a number of new ones arriving. For example, buttercup and ecukes both provide behaviour driven testing, rather like Jasmine or Cucumber respectively. Both worth looking at — I’ve used Ecukes for testing Cask, and it’s nicely implemented and very usable. Assess is rather less radical than this though. It focuses on providing a general set of tools for testing, mostly in terms of some macros and predicates that should be useful.

For example, a recurrent problem during the development of lentic was ensuring that no buffers were left around after a test. Particularly when a test fails, this can lead to unexpected failures in later tests. For this purpose, I have added a macro called assess-with-preserved-buffer-list. Any buffers at all created inside this macro will be removed after. Hence this:

  (get-buffer-create "a")
  (get-buffer-create "b")
  (get-buffer-create "c"))

Which preserves the buffer state. a, b and c will be removed after the macro exits.

Assess also provides some handy predicates for testing. So, we can compare the contents of strings, buffer and files easily. For example:

;; Compare Two Strings
(assess= "hello" "goodbye")

;; Compare the contents of Two Buffers
  (assess-buffer "assess.el")
  (assess-buffer "assess-previous.el"))

;; Compare the contents of Two files
  (assess-file "~/.emacs")
  (assess-file "~/.emacs"))

Again, this has all been done carefully to avoid changing state. The last example, should work whether ~/.emacs is open already or not, and will not result in new buffer creation.

As well as string comparison, we can also check that indentation is working correctly. This example, for instance, takes a indented string, un-indents and re-indents according to a specific mode, then checks that nothing has changed.

  "(assess-with-find-file\n    \"~/.emacs\"\n  (buffer-string))")

Likewise, we can check fontification with the assess-face-at= function. In this case, we are checking that three words get highlighted correctly.

 "(defun x ())\n(defmacro y ())\n(defun z ())"
 '("defun" "defmacro" "defun")

Finally, in terms of test functions, I have recently added two new pieces of functionality. Call capturing was an idea I stole from buttercup — this is a non-interative equivalent to the function tracing, returning parameters and return values to a function call.

    (+ 1 1)))
;; => (((1 1) . 2))

And discover provides a drop in replacement for ert-run-tests-batch-and-exit except that it automatically finds and loads test files, based on a set of heuritstics. I’ve already started to use this instead of ert-runner, as it requires no configuration.

The final thing I wanted to address was better reporting. While everything described so far as test environment agnostic, I’ve only managed to advance reporting for ERT. All of the functions that I have written plug into ERT, so produce richer output. So instead of:

F temp
       (string= "a" "b"))
      (string= "a" "b")
      :value nil))

When comparing "a" and "b", this output is fine, but if the strings are more complex (say, for example, the a short piece of code that you expect to indent in a certain way), it is hard to work out what the differences are.

So, assess extends ERT so that that it now calls diff on the strings. We now get this explanation instead:

F test-assess=
       (assess= "a" "b"))
      (assess= "a" "b")
      :value nil :explanation "Strings:
Differ at:*** /tmp/a935uPW      2016-01-20 13:25:47.373076381 +0000
--- /tmp/b9357Zc        2016-01-20 13:25:47.437076381 +0000
*** 1 ****
! a
\\ No newline at end of file
--- 1 ----
! b
\\ No newline at end of file


Verbose for sure, but very useful for identifying issues, especially white space related. By default, this uses the diff command, but this is also extensible, and has a simple fallback in its absence.

There is more functionality to assess than that shown here: it can create multiple temporary buffers in a single scope; it can create “related” temporary files, prevent conflicts if files are already open; it can re-indent the contents of files rather than buffers, and so on. I think assess is a nice addition to the testing capabilities of Emacs.

More is needed and some of this involve changes to Emacs core — packages which are noisy, enforce interactivity, and so forth. I would also like to add support for “robotized” tests running keyboard macros, tests for checking hooks, output to the message buffer, and testing for asynchronous call backs. But assess is quick, easy to use and makes testing of many features of Emacs much easier. I’ve started to use it in my own packages, and will eventually use it in all of them.

My plans for the future are to move assess to ELPA, and then eventually to Emacs core after 25.1, probably as ert-assess. I hope that along with my restructuring of the Emacs unit tests files, this will make testing of Emacs core simpler and more straight forward; if it does this should make the merge hassles (mostly to other people, sadly) caused by file moves worthwhile. Emacs will be easier to develop, and simpler to change.

Feedback is, as always, welcome.


My last blogpost was on logging ( with the SLF4J library, its inclusion in the OWL API, and its impact on Tawny-OWL. It raised quite a response, not least because it suggested that people ignore the advice of the authors of the library.

Perhaps, unsurprisingly, the general feeling was against my position — something that I expected given that this had already happened on the SLF4J mailing list. Now, of course, it does have to be said that there is a significant sampling bias here: anyone on the mailing list, or who reads and responds to a post about a logging API, is likely to be interested in logging rather than a passive user (or non-user) of such a library. None the less, I think it is worth reflecting on the reasons for the comments.

Of course, I am aware, that as many people pointed out, the problem is not huge (a three line error message) and my solution is messy. Well, I agree, the solution is messy, but it is the only method that SLF4J has support for. There are alternatives; for example, this commit from the OWL API provides another solution. I have not decided yet whether this is the right way to go or not.

Several people complained that including the nop dependency will silently turn off all logging. Actually, this is not true: in applications which have logging already, including a nop dependency, will trigger an error message; whether logging is turned off or not is hard to determine — it depends on the classpath ordering. I am, however, clearly making life harder for those who want logging on. Specifically, I am requiring that instead of using:

[" "1.5.0"]

It will require this:

[" "1.5.0" :exclusions ["org.slf4/slf4f-nop"]]

(or the equivalent for maven). So, harder, but not much harder.

The other two main suggestions are that I split my code into library and application, even though this is artificial (the “application” would currently contain no code). But this approach would require most of my downstream dependencies to also be split into two for the same reason; it was even suggested that the Clojure REPL or Leiningen that should do the work, and that they should be split into two. Introducing such complexity for a logging API is surely not good engineering.

Finally, there were many suggestions that I leave the decision to the “end user”. But, as I have said, while I like allowing the “end user” to have a choice, I do not believe in imposing it on them. Choose a default where it is at all possible and do not sit on the fence.

During this process, though, I have thought a lot about logging, and I have come to the conclusion that the core of the problem is that logging is heavily overloaded. Quite a few people were frankly amazed that I would not want to see logging, asserting that most people would want to see it.

Now, I use a web server, and use its logs all the time. Logs are critical for many reasons, and many tools like webalyser or fail2ban work over them. I would never want to turn these off. But, here, though, the logging is effectily a part of the application: apache logs are part of the adminstration user interface, as well as forming an ad hoc API to downstream tools; part of the plumbing in git parlance. Why would you want to switch this off? I would not.

In this case, though, if logging is part of the application, why on earth are people so keen on libraries logging — the application should not be deciding the location of the logs only, but also how and what is logged. Libraries should just not be logging at all; they should be taking callbacks, returning values and leaving the outcome of this to the application.

What about “error messages” though? Surely libraries can produce these? The OWL API (which is the library that makes use of SLF4J) is an example of this. Most of the logging message are errors: for example, this situation:

if (loadCount.get() != importsLoadCount.get()) {
               "Runtime Warning: Parsers should load imported ontologies using the makeImportLoadRequest method.");

which is effectively a form of active documentation or this:

try {
    return optional(new XZInputStream(new BufferedInputStream(new FileInputStream(file))));
} catch (IOException e) {
    LOGGER.error("File cannot be found or opened", e);
    return emptyOptional();

which is sort of an error but one that has actually been dealt with. These are mostly debugging statements that the authors think they may use again. That’s fine and an entirely reasonable use of a logging framework. Equally, and I feel entirely reasonably, I want this off by default.

The “error message” from SLF4J that started me down this path falls into the same category. It is not an error, or it would throw an exception (as it used to do in the past). It is a debugging statement that is there for a normal condition that the authors are, nonetheless, not entirely happy about. There are two reasonable defaults (be noisy, or be silent), and they do not know which to choose.

My previous trip into the field of logging was twenty years ago, when I wrote a fun Emacs packages for putting System.out.println statements into the code (then taking them out again); as one person said of me, I “simply lack the knowledge” of logging frameworks to comment. I am happy to accept that this is entirely correct. Despite this my conclusions are simple. I remain convinced that SLF4J should have the courage of its convictions; if there is an error, signal an error, otherwise remain silent. Until it does this, adding the nop dependency remains the right way forward for me. Take my advice with a distinct pinch of salt, certainly. At the same time, think how many people have been irritated by that error message and not taken the time to comment. If you are worried about these people, then using the nop dependency may be the right way forward for you to.

And there I shall leave the discussion and comment no more.