Archive for February, 2009

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…

February 24, 2009 at 11:18 pm Leave a comment

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.

February 24, 2009 at 11:04 pm Leave a comment

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 buffer’s 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, with some work, be used for any file format with a validator. The following settings let flymake validate html in emacs.

Motivation

  • Seeing mistakes earlier can make them easier to correct
  • Valid html makes future browsers less likely to mangle your page
  • Remembering to run a validator takes effort

Setup

  • Install html tidy (this is available under cygwin on windows, and using apt under most linuxes)
  • Create this perl script[1]; make it executable and place it on your path. 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))
    
  • Ensure that you have the following command somewhere in your .emacs file
     (add-hook 'find-file-hook 'flymake-find-file-hook)

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: this has more features such as context dependent autocompletion. Beware that this can take some setting up, and is a little overwhelming at times.

February 23, 2009 at 11:46 pm 3 comments

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.

February 23, 2009 at 11:44 pm Leave a comment


February 2009
M T W T F S S
« Sep   Mar »
 1
2345678
9101112131415
16171819202122
232425262728