[ Content | Sidebar ]

Archives for linux

Making Emacs GUD Usable

June 9th, 2019

Emacs provides a wrapper for various debuggers including GDB called the Grand Unified Debugger (GUD). I’ve tried it in the past but always run into lots of minor annoyances with the UI so I just use command line GDB instead. But recently I’ve being trying to adopt a more “Emacs native” workflow, including using EShell instead of a separate terminal window for Bash, Magit instead of command line git, ERC for IRC, etc. So let’s see if we can fix these GUD problems…

Basic configuration

(setq gdb-many-windows t
      gdb-use-separate-io-buffer t)

The default mode of GUD just creates a single window with the the normal GDB terminal. This doesn’t seem to offer much over running GDB directly. The “many windows” mode splits the screen into six separate windows showing the current source file, locals/registers, output, etc.

Source file opens in the wrong window

By default if you jump to a source file from e.g. the stack trace window it will open on top of the command input window (labeled “2” below) rather than the source file window “1”.

This seems to be “normal” behaviour, and there are loads of threads on Stack Overflow complaining about it but with no conclusive solution. E.g. see here or here.

The problem here is that GUD makes all the popup windows “dedicated” except for the command window. When you jump to a file it opens in the first non-dedicated window, which sort-of makes sense. The function that sets up the windows is called gdb-setup-windows so we can use Emacs’ “advice” system to hook this function and run some extra code afterwards to make the command window dedicated:

(advice-add 'gdb-setup-windows :after
            (lambda () (set-window-dedicated-p (selected-window) t)))

This works because gdb-setup-windows always leaves the command window selected when it finishes.

Quitting messes up the window configuration

How do you quit anyway? I think the correct way is just to run quit in the command window. But no matter how you quit GUD always messes up whatever window configuration you had before you opened it.

We can fix that by saving the window layout when we run M-x gdb by storing the layout into a register in gud-mode-hook. The gud-sentinal function runs when some event occurs on the inferior gdb process. We can hook that to restore the window state when the process exits.

(defconst gud-window-register 123456)
(defun gud-quit ()
  (gud-basic-call "quit"))
(add-hook 'gud-mode-hook
          (lambda ()
            (window-configuration-to-register gud-window-register)
            (local-set-key (kbd "C-q") 'gud-quit)))
(advice-add 'gud-sentinel :after
            (lambda (proc msg)
              (when (memq (process-status proc) '(signal exit))
                (jump-to-register gud-window-register)

I’ve bound C-q to gud-quit which send the quit command to GDB to save typing.

A Final Samsung Q320 Update

April 23rd, 2017

You almost certainly don’t remember but back in 2009 I published a series of articles detailing my travails getting Linux to run smoothly on my then-new Samsung Q320 laptop. Well you’ll be pleased to know that eight years on I’ve finally solved all my remaining issues:

  • The fan randomly spinning up and down
  • The “always-powered” USB port not working
  • General sluggishness

The first two can be fixed by downloading the 06LH BIOS update from July 2010. Maddeningly this can only be installed from Windows. To fix the third problem I swapped the original magnetic disk for a modern SSD (really easy), and at the same time temporarily installed Windows 10 and applied the BIOS update. Then I dd-ed my old disk over the SSD using a USB-SATA adapter.

I’m really happy with the result. Running Debian Stretch everything Just Works and with the SSD it’s pretty speedy. At the moment I’m using it whenever I go home to visit my parents.

GnuCash Quotes for UK Unit Trusts

January 3rd, 2015

In the past I’ve tried and failed to get GnuCash to automatically download stock quotes. At the moment I have to type them in manually which is an excruciating chore. Unfortunately the documentation for how to do this for non-US funds is patchy and the only feedback you get is an unhelpful “computer says no” pop-up.

But today I finally got it to work! Hopefully these steps will save someone else this pain…

  1. Find out the fund’s ISIN code: this is normally on the fact sheet somewhere. It should be a long alphanumeric string starting with “GB” like “GB00BMHTPT71”.
  2. Open the securities editor for that fund. Paste the ISIN code into the box labelled “Symbol/abbreviation” not the one labelled “ISIN, CUSIP or other code”: that’s just there to confuse you.
  3. Select the “Get Online Quotes” checkbox and then the “Unknown” quote source. Then search through the enormous unsorted list in the drop-down for the “ftfunds” option. It should look something like this:
  4. Open the price editor and click “Get Quotes”
  5. ????
  6. PROFIT!

If that doesn’t work you could try the command line tool gnc-fq-dump. (That’s how I figured this stuff out in the first place.) For example:

$ gnc-fq-dump ftfunds GB0001036531
Finance::Quote fields Gnucash uses:
    symbol: GB0001036531         <=== required
      date: 01/02/2015           <=== required
  currency: GBP                  <=== required
      last: 2.268                <=\       
       nav: 2.268                <=== one of these
     price: 2.268                <=/        
  timezone:                      <=== optional

Filed in linux - Comments closed

Firefox Back to Normal

December 30th, 2014

I’ve been stubbornly ignoring the recent updates to Firefox and using 24 ESR instead as the new Australis changes ruined what was a perfectly nice minimal UI. The biggest problem for me was the inability to move the address bar into the title bar: once you’re accustomed to this having it hanging below is a heinous waste of screen real estate.

Today I decided to give the new ESR version 31 a go and after half an hour or so tweaking with Classic Theme Restorer I managed to make it look like my old Firefox! The “customize” interface now lets me drag the address bar up into the menu bar and get rid of that giant “back” button. For reference, here’s version 24:


And here is what I’ve got in version 31:


Sticking with Firefox 24

June 20th, 2014

Oh dear. I unwittingly updated to Firefox/Iceweasel 29 in Debian testing. What a mistake! My Firefox setup has remained basically the same since the 3.5 days with a nice unobtrusive layout where I have the menu, navigation buttons, and the address bar in one strip and the tabs below. Despite hours of hair pulling there’s no way to get anything remotely satisfactory with the new UI, even with the “Classic Theme Restorer” addon.

Panic not! It’s possible to just stick with the stable 24.4 version from Debian wheezy! For future reference, this needs to go into /etc/apt/sources.list:

deb [arch=amd64] http://security.debian.org/ wheezy/updates main

Then do this:

sudo apt-get install -t wheezy iceweasel
sudo apt-mark hold iceweasel

UPDATE: I later upgraded to 31 ESR and worked around most of the problems.

Filed in linux - Comments closed

Blurry Chinese Characters on Linux

April 21st, 2014

For future reference, this fixes all woes:

sudo apt-get install xfonts-wqy

UPDATE: a much better solution is to install a pretty TTF font and then make all the characters bigger.

sudo apt-get install fonts-wqy-zenhei fonts-wqy-microhei

Then create a file ~/.config/fontconfig/fonts.conf with the following contents:

<?xml version = "1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
  <match target="font">
    <test qual="any" name="family" compare="eq">
      <string>WenQuanYi Zen Hei</string>
    <edit name="pixelsize" mode="assign">

Oh yeah: am trying to learn some Chinese characters! Prompted by the arrival of an enormous Chinese phone at work.

Filed in linux - Comments closed

Best Feature

February 5th, 2012

If you needed any convincing that Clementine is the best Linux music player since Amarok 1.4, here it is:

Nyanalyser mode!

Filed in linux - Comments closed

Conky BBC weather

April 17th, 2011

I’ve written a Ruby script called bbc-weather.rb that parses the BBC weather RSS for a particular location and formats the data for conky. Here’s an example:

To use it insert the following in your .conkyrc:

${execpi 600 ruby /path/to/bbc-weather.rb 4197}

This will refresh every hour. Replace 4197 with the number of your local weather station. You can find this by looking at the BBC weather URL which is of the form weather/forecast/XXXX. You also need to define two colours for the script to use, in the options section before TEXT, like so:

color1 white
color2 grey

You might also need the following, as conky limits the about of text it will read from a sub-process:

text_buffer_size 2048

UPDATE: apparently this script no longer works with recent BBC Weather updates. Check out the comments for an improved version.

Reducing DVD drive noise

September 25th, 2010

Fan noise from CD/DVD drives can be very loud. It probably doesn’t matter if you’re just reading something off it but if you’re watching a DVD for example, it can get annoying. The fans are required in modern drives when the disc is spinning very fast – e.g. 16x – and by default it spins as fast as it can. So there is a simple solution: slow down your drive! This is easy enough in Linux, but oddly the command you need is eject. For example, to reduce your drive to 4x speed:

eject -x 4 /dev/dvd

The parameter -x is simply the multiplier: pick a low value (except 0, which means full speed). 4x seems sufficient on my device to completely disable the fans.

Filed in linux - Comments closed

Samsung Q320 Fn-keys in Linux 2.6.32

February 20th, 2010

If you’ve been following my attempts to get the brightness up/down and other fn-keys on my Samsung Q320 laptop to work in Linux, you might like to know the saga has reached a happy conclusion. Previously I published a hack to the atkbd kernel driver to get these problematic keys to send key release events. My attempt to get this included in the kernel failed, but I was told the 2.6.32 kernel would contain a new mechanism for fixing this from userspace.

Well, 2.6.32 is here so how can we fix the fn-key release problem? Documentation for the new sysfs attribute is a bit scanty as it’s intended to be used only by udev/HAL/DeviceKit, but you can set it yourself quite easily. The relevant file is /sys/devices/platform/i8042/serio0/force_release – this lets you manipulate a bitmap in atkbd.c indicating which scancodes don’t send key release events.

echo 130-132,134,136,137,179,247,249 \
    > /sys/devices/platform/i8042/serio0/force_release

The bitmap editing syntax is quite nice – done in lib/bitmap.c rather than the atkbd driver itself. I got those scancodes from the array atkbd_samsung_forced_release_keys in atkbd.c. They were originally intended for the NC20 but the Q320 keyboard seems to be the same. It works for me anyway.

You still need to map the brightness up/down keys to the correct X11 codes, which you can do like this:

setkeycodes e008 225 e009 224

Job’s a good’un.

All my Samsung Q320 coverage is here.