Updating to intrepid broke my left arrow key!

Seems that the keycodes on my keyboard (thinkpad T43p) changed after installing the new version of intrepid. I note that the kernel version changed. This meant that my xmodmap was mapping this key to alt…

Add comment February 24, 2009

Flash broken by upgrade to ubuntu intrepid

Upgrading to ubuntu intrepid broke the sound in flash. Videos would play but there was no sound.

Attempting to install the apt non-free flash player failed complaining about the md5 checksum not matching (presumably becase the md5 sum is hard-code and the flash player that was being downloaded had changed). [aside: running apt-get clean and repeating made this work. ]

However downloading and installing the latest version of flash worked.

Add comment February 24, 2009

Using flymake in emacs to validate html as you type

Flymake is a general emacs plugin which allows you to run an external validator against a buffers content and visually report errors. The effects are quite similar to the red underlining you will see in some IDEs (e.g visual studio) – but can be used for any file format with a validator with some work. The following settings let flymake validate html in emacs.

Motivation

  • Seeing mistakes earlier can make them easier to correct
  • Many programs will simply die with little logging if given broken xml files
  • Remembering to run a validator takes effort
  • t

Setup

  • Install html tidy (this is available under cygwin on windows, and using apt under most linuxes)
  • Create this perl scripts, make it executable and place it on your path [1] call it flymakehtml
    #!/usr/bin/perl
    open(INPUT, "rxp $ARGV[0] 2>&1|");
    while (<INPUT>){
        /^Error/ && chomp;
        print;
    }
  • Add the following code to your .emacs file:
  • (defun flymake-html-init ()
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
    		     'flymake-create-temp-inplace))
    	 (local-file (file-relative-name
    		      temp-file
    		      (file-name-directory buffer-file-name))))
        (list "tidy" (list local-file))))
    
    (add-to-list 'flymake-allowed-file-name-masks
    	     '("\\.html\\'" flymake-html-init)) 
    
    (add-to-list 'flymake-err-line-patterns
    	     '("line \\([0-9]+\\) column \\([0-9]+\\) - \\(Warning\\|Error\\): \\(.*\\)"
    	      nil 1 2 4))
    
  • Also, ensure that you have the following command somewhere in your .emacs file
     (add-hook 'find-file-hook 'flymake-find-file-hook)

This should then work. You might like to change the face used to show errors with M-x customize-face flymake-errline. Hovering over an error will show you a description of the error

[1] This is to trim the tidied document from the output and only leave error messages.

Caveats
Sometimes error messages will use slightly strange tenses – since html tidy is a tool to tidy html rather than validate it – but the meaning is usually clear enough.

You might be interested in the nxhtml plugin as an alternative to this – but with more features such as context dependent autocompletion – though this looks like it could take a little setting up, and also seems a little overpowering

2 comments February 23, 2009

Using flymake in emacs to validate xml as you type

Motivation

  • Seeing mistakes earlier can make them easier to correct
  • Many programs will simply die with little logging if given broken xml files
  • Remembering to run a validator takes effort

Setup

  • Install rxp (this is available under cygwin on windows, and using apt under most linuxes)
  • Create this perl scripts, make it executable and place it on your path [1] call it xmlparse
    #!/usr/bin/perl
    open(HA, "rxp $ARGV[0] 2>&1|");
    while (){
        /^Error/ && chomp;
        print;
    }
  • Add the following code to your .emacs file
  • (defun flymake-xml-init ()
      (let* ((temp-file (flymake-init-create-temp-buffer-copy
    		     'flymake-create-temp-inplace))
    	 (local-file (file-relative-name
    		      temp-file
    		      (file-name-directory buffer-file-name))))
        (list "xmlparse" (list local-file))))
    
    (add-to-list 'flymake-allowed-file-name-masks
    	     '("\\.xml\\'" flymake-xml-init)) 
    
    (add-to-list 'flymake-err-line-patterns
    	     '("\\(.*\\) at line \\([0-9]+\\) char \\([0-9]+\\) of file://\\(.*\\)"
    	      4 2 3 1))
  • Also, ensure that you have the following command somewhere in your .emacs file
     (add-hook 'find-file-hook 'flymake-find-file-hook)

This should then work. You might like to change the face used to show errors with M-x customize-face flymake-errline. Hovering over an error will show you a description of the error

Caveats

The behavior for unclosed tags is not what I want. The error is reported where the parent tag closes – which can be quite some distance from the opening tag. However at least the message is informative.

There is an existing emacs host, nxhtml, which has some of these things built in together with other editing tools – but it looks a little monolithic.

[1] This ensures that each error is written on only one line. Flymake appears to only be able deal with output in this form.

Add comment February 23, 2009

Directory Links on Windows

You can create directory symlinks in windows using the junction command line property available here.

This command is analogous to the mount command in linux.

To use it:

  1. Create an empty directory where you want to make your link.
  2. Run junction <link> <target>

Not that this doesn’t work for individual files – for this use the fsutil utility.

Add comment September 23, 2008

Recording screencasts on Ubuntu Hardy

I’ve just been playing with recording my desktop on ubuntu hardy.

I didn’t spend very long on this – but the fact that the first two applications I tried didn’t work at all suggests that writing something don’t might be mildly useful.

The applications I tried were

* istanbul

* byzanz

* gtk-recordMyDesktop

Out of these gtk-recordMyDesktop was the only one to work adequately – though I managed to think it wasn’t working for a while.

The problems I encountered:

  • byzanz only produced animated GIFs and had a tendency to stop recording after short lengths of time (like seven seconds)
  • instanbul would produce videos which would frequently become entirely black – only showing a few frames of the recorded video

gtk-recordMyDesktop seemed to work fairly well however it confused me quite a lot at first. Its dialog has a Save As button that must be pressed before recording – this meant for a while I was convinced that the application wasn’t producing output, or was using the previous filename I entered to produce output. I guess I’m just rather slow. In gtk-recordMyDesktop’s defence I didn’t actually read anything about it before attempting to use it. Perhaps Save As should be changed to Select save path.


Summary for the impatient

If you want to record on Ubuntu, gtk-recordMyDesktop seems to work adequately. Though you have to click the Save As button to specify the save-path before clicking the record button. Also, to stop recording you have to click a stop button that will (probably unbeknownst to you) appear in your system tray after you start recording.

istanbul didn’t work – but this may well be something to do with my machine – or something to do with ubuntu’s distributed version. I don’t mean to malign its makers.

3 comments August 30, 2008

Hardcoding parameters into function names

Code seems to sometimes be slightly easier to read if information is pushed out of the arguments and into the function name.

I.e: Set(‘Color’, red) —> SetColor(red)

This has the nasty effects of making one’s APIs rather large, but if used sparingly it:

  1. Makes APIs more discoverable – the naming of function now contains information which would otherwise be in the usage of functions
  2. Makes code slightly easier to parse – Mostly just because we have removed an argument from the argument list
  3. Make code using the API slightly easier to write

Bear in mind that this statement is heuristic and general… so is probably wrong most of the time. Also I kind of suspect that all of this may immediately become false when two arguments rather than on are pulled out of the argument list and into the functional name.

This statement is, however, particularly true when your different operations take slightly different data as one of the other arguments vary.

Add comment July 30, 2008

Emacs version control

I discovered how emacs version control worked today… and was duelly impressed. (Having previously thought that it didn’t work at all well – guess this means I should learn to read manuals).[1]

Regardless, emacs comes with a unified version control front-end which supports back-ends for most version control systems : I believe this includes git, svn and bzr).  This can do most of the things that one wants to do.

One of my only irritations is that one can’t revert individual lines of the diffs that it shows.

Summary for the impatient

Emacs version control is wonderful, I’m dim for not realising this earlier. To make it work do the following:

C-x v = in a file for a diff

To submit:

C-x v d <TOP LEVEL DIR> to get a list of all modifed files, then mark everything (hold down m) and press C-x v v.

If you want to see diffs for individual files press v=.

[1] As an aside, one of the reasons I hadn’t found this out earlier was because I was under the false impression the mode help (C-h m) would show all relevant keybindings… I’m not quite sure why, C-h b is (strangely!) better for this purpose.

3 comments July 30, 2008

Searching multiple buffers emacs

In the past I’ve complained about emacs not being able to search multiple buffers for regular expressions, and I’ve resorted to using the additional package moccur.el. This was pretty good but had the irritating (though understandable) caveat that if you changed the text in one of the searced files then all the links from the output pane became slightly wrong.

However, I take it all back. I’ve just found that the standard FSF emacs has two functions which do what I want to do without these caveats. These allow one to search several buffers simultaneously for a given regexp and maintain links even if context is chaged… I’m not quite sure how I managed to miss this before – since the first thing that one would think to do if you wanted to search multiple strings for buffers would be to type “C-h a o-c-c-u-r-<ENTER>” and then search for multi… but I guess I’m just dim.

Anyway:

Precis for the impatient

In FSF emacs, you can search several buffers for a given string

multi-occur: – Search specified buffers to a string

multi-occur-in-matching-buffers: Allows one to search a subset of one’s open buffers or files specified as a regexp:

Given .* as its first argument this allows one to search all currently open files for a given regular expression.

Given a prefix argument and .* as its first argument this allows one to search all currently open buffers for a regexp.

Also (occur-1 regexp nil buffer-list) can be usefully adapted to search for other things.

2 comments July 27, 2008

Emacs buttons – an introduction for the somewhat impatient

Working out how to make buttons work in emacs took rather too much effort – I suspect I was just being slow. However, I thought I’d write a tiny how-to for anyone else who tries to do this:


Below is a prototypical emacs lisp function call to create a new button in your text between characters beg and end is:

(defun f (button)
    (call-interactively 'find-file))

(make-button beg end 'action 'f 'follow-link t)

Note the following:

  • The properties are defined via a variable number of arguments . It does does not take a list.
  • Removing the follow-link property would cause left mouse-clicks on the link to have no effects
  • f must take a single argument otherwise this will fail.

For more on emacs buttons see:

http://www.gnu.org/software/emacs/manual/html_mono/elisp.html#Buttons

If you want to make your button more anonymous (so that changing the function value associated with f has no deleterious results) you can use the following

(make-button beg end 'action
    (lambda (button) (call-interactively 'find-file))
    'follow-link t)

3 comments May 14, 2008

Next Posts Previous Posts


Meta

Facets

abstruse Add new tag AOP apt aspect oriented programming assumes knowledge autiobiographical bash scripts bell books clarity code samples configuration console emacs for the benefit of google functional programming graphical design hacks higher-order functions howtos intention revealing programming keyboard links linux note to self opinions parsing patterns philosophising philosophizing programming python random ideas refactoring removing packages short stories succinct svn systems stuff theoretical philosophizing typing work ethic you probably don't want to read this

Archives

Pages

 

November 2009
M T W T F S S
« Aug    
 1
2345678
9101112131415
16171819202122
23242526272829
30