Thursday, March 08, 2007

vim * key

I watched the vim talk today that the vim author gave at google a while ago about effective editing. He talked about the * shortcut, which goes to the next occurence of the word under the cursor.

I used that to remove all the unused module function in my pet project, pytof. Here is an example:

from os import walk, sep, chdir, rmdir, getcwd, listdir, lstat, mkdir, makedirs
from os import walk, sep

I use * to go to the next occurence. If there is no such occurence, I delete it with 'dw'. If there is one, I go back to the from line with 'N'.

I did not made any statistics, but here is the subversion diff, quite a few were removed...

I'm still using emacs for a multiple of reason (gdb, make integration and I'm faster with creating new windows and splitting the windows), but vim is definitely a great editor.

Emacs may also be good for that, but the '*' is a good idea.


[bsergean@marge1 pytof]$ svn diff
Index: ftp.py
===================================================================
--- ftp.py (revision 266)
+++ ftp.py (working copy)
@@ -13,8 +13,7 @@

from log import logger
from os.path import join, basename
-from os import walk, sep, chdir, rmdir, getcwd, listdir, lstat, mkdir, makedirs
-from sys import exc_info
+from os import listdir, lstat
from stat import S_ISDIR, S_ISLNK
from utils import notYetImplemented
from ftplib import FTP, error_temp, all_errors
Index: photo.py
===================================================================
--- photo.py (revision 266)
+++ photo.py (working copy)
@@ -19,7 +19,6 @@
from utils import TryToImport
from exif import process_file

-# Once wxpil works, we should try to import PIL and then falback to wxpil
try:
import Image
except ImportError:
Index: options.py
===================================================================
--- options.py (revision 266)
+++ options.py (working copy)
@@ -11,12 +11,9 @@
__revision__ = '$Id$ (C) 2007 GPL'
__author__ = 'Benjamin Sergeant'

-from log import logger
-from os.path import expanduser, join, exists, isdir, splitext, basename
+from os.path import expanduser, isdir
import os, sys
-from utils import _err_, _err_exit, echo, GetTmpDir, ListCurrentDirFileFromExt
-from ConfigParser import RawConfigParser
-from shutil import copy
+from utils import _err_exit
from optparse import OptionParser
from log import quiet
from version import __version__
Index: utils.py
===================================================================
--- utils.py (revision 266)
+++ utils.py (working copy)
@@ -13,7 +13,7 @@

import sys
import os
-from os.path import splitext, expanduser, join, exists, basename, walk, isfile
+from os.path import splitext, join, exists, basename, walk, isfile
import tarfile
from zipfile import ZipFile, ZIP_DEFLATED
from log import logger
Index: wxpil.py
===================================================================
--- wxpil.py (revision 266)
+++ wxpil.py (working copy)
@@ -13,12 +13,7 @@
__author__ = 'Benjamin Sergeant'
__dependencies__ = ['wx']

-from log import logger
-from os.path import join, getsize, basename, splitext
-from shutil import copy
-import sys, os, time
from utils import TryToImport
-from exif import process_file

TryToImport(__dependencies__)
for mod in __dependencies__:
Index: config.py
===================================================================
--- config.py (revision 266)
+++ config.py (working copy)
@@ -14,7 +14,7 @@
from log import logger
from os.path import expanduser, join, exists, getsize
import os, sys
-from utils import _err_, _err_exit, echo, GetTmpDir
+from utils import _err_exit, GetTmpDir
from ConfigParser import RawConfigParser
from shutil import copy

Index: pytofmain.py
===================================================================
--- pytofmain.py (revision 266)
+++ pytofmain.py (working copy)
@@ -11,17 +11,15 @@
__revision__ = '$Id$ (C) 2004 GPL'
__author__ = 'Benjamin Sergeant'

-from log import logger, quiet
-from os.path import expanduser, join, exists, basename, isabs, walk, isdir
+from log import logger
+from os.path import join, exists, basename
from albumdataparser import AlbumDataParser, AlbumDataParserError
import os, sys
-from utils import _err_, _err_exit, echo, mkarchive
+from utils import _err_exit, echo, mkarchive
from config import configHandler
import makepage, makefs
from shutil import rmtree
-from ftp import ftpUploader, ftpPush
-from ftplib import error_perm
-from getpass import getuser, unix_getpass
+from ftp import ftpPush
from string import rstrip


Index: makefs.py
===================================================================
--- makefs.py (revision 266)
+++ makefs.py (working copy)
@@ -14,7 +14,6 @@
__revision__ = '$Id$ (C) 2004 GPL'
__author__ = 'Benjamin Sergeant'

-from albumdataparser import AlbumData
from utils import ProgressMsg
import os, sys

Index: albumdataparser.py
===================================================================
--- albumdataparser.py (revision 266)
+++ albumdataparser.py (working copy)
@@ -17,7 +17,6 @@
from photo import Photo
from utils import _err_, _err_exit, ListCurrentDirFileFromExt
from time import strptime
-from glob import glob
from cPickle import dump, load

class AlbumDataFromDir(object):
Index: makepage.py
===================================================================
--- makepage.py (revision 266)
+++ makepage.py (working copy)
@@ -16,11 +16,10 @@
__author__ = 'Mathieu Robin'

from log import logger
-from os.path import expanduser, join, exists, basename, isdir
-from albumdataparser import AlbumDataParser, AlbumDataParserError, AlbumDataFromDir
+from os.path import join, exists, basename, isdir
+from albumdataparser import AlbumDataFromDir
import os, sys
-from utils import _err_, _err_exit, echo, ProgressMsg
-from shutil import copy
+from utils import _err_exit, ProgressMsg
from template import pytofTemplate

def makePhotoPage(photo, topDir, prev, next, strip_originals, albumName, style):
Index: template.py
===================================================================
--- template.py (revision 266)
+++ template.py (working copy)
@@ -14,14 +14,9 @@
print __file__

from log import logger
-from os.path import expanduser, join, exists, isdir, splitext, basename
+from os.path import join, exists, splitext, basename
import os, sys
-from utils import _err_, _err_exit, echo, GetTmpDir, ListCurrentDirFileFromExt
-from ConfigParser import RawConfigParser
-from shutil import copy
-from optparse import OptionParser
-from log import quiet
-from version import __version__
+from utils import ListCurrentDirFileFromExt

class TemplateError(Exception): pass
class pytofTemplate(object):
Index: log.py
===================================================================
--- log.py (revision 266)
+++ log.py (working copy)
@@ -13,10 +13,6 @@

import logging

-from os import listdir, chdir, pardir, getcwd, walk
-from os.path import join
-from glob import glob
-
#TODO: Would be nice to have funcName here as well, but it's only available for python >- 2.5
format = "%(levelname)s\t[%(pathname)s:%(lineno)d] %(message)s"