Showing posts with label check. Show all posts
Showing posts with label check. Show all posts

Tuesday, August 12, 2008

Vim Can Spell

Thanks to Chris Suter for contributing the following tip:

I always knew this was in there somewhere, but usually my compiler tells me when I'm an idiot, so I've never needed it. Latex, however, does not.

:setlocal spell spelllang=en_us

turns on spell-check and highlighting for incorrectly spelled words.

navigation:
]s - next misspelled word
[s - prev "

interaction:
zg - add misspelled word to system dictionary
zG - add misspelled word to buffer-local set of "good" words
zw - add word to 'bad' list
zW - add word to buffer-local 'bad' list
z= - view a numbered list of suggested spellings from which to choose for auto-replacement

side note: Maybe there's a word list for php fn's, since it seems to assume that when you've mistyped something, you obviously meant 0, "zero", false and NULL simultaneously and chooses arbitrarily between them. This might prevent some headaches/suicides.

Friday, June 6, 2008

Syntax Check

When working on anything important, it makes sense to check the syntax of your file before setting it live. This is usually accomplished with a simple command-line flag. Consider the following:

travis@travis-ubuntu:/home/travis% ruby -c test.rb
Syntax OK

travis@travis-ubuntu:/home/travis% perl -c test.pl
test.pl syntax OK

travis@travis-ubuntu:/home/travis% php -l test.php
No syntax errors detected in test.php

Python doesn't make this as easy. I'm not sure why because it seems to have a pretty well defined separation between it's compiler and runtime, but the general consensus is to break your code into classes and just have a single "main" file for your runtime code. That way you can just run python filename, which will compile the file to bytecode as well as check syntax; however, this is frustrating if you just want to check the syntax and not actually run the program (common with DB applications). Consider the following hack an alternative, which could easily be wrapped up in a helper shell script.

python -c "import py_compile; py_compile.compile('test.py')"

This produces no output on success and an error on failure. It has the possibly unwanted side effect of compiling to bytecode, but I don't think there's any getting around that.