diff --git a/application.py b/application.py index e94a469..419b9fe 100755 --- a/application.py +++ b/application.py @@ -84,90 +84,47 @@ class Application(object): self.set_error("Dynamic color not available") # initialize our modes - self.modes = { - 'blame': mode.blame.Blame, - 'c': mode.c.C, - 'console': mode.console.Console, - 'consolemini': mode.consolemini.Console, - 'diff': mode.diff.Diff, - 'dir': mode.dir.Dir, - 'fundamental': mode2.Fundamental, - 'mini': mode.mini.Mini, - 'nasm': mode.nasm.Nasm, - 'perl': mode.perl.Perl, - 'python': mode.python.Python, - 'replace': mode.replace.Replace, - 'search': mode.search.Search, - 'sh': mode.sh.Sh, - 'text': mode.text.Text, - 'text2': mode.text2.Text2, - 'which': mode.which.Which, - 'xml': mode.xml.XML, - 'html': mode.html.HTML, - 'css': mode.css.CSS, - 'mutt': mode.mutt.Mutt, - 'javascript': mode.javascript.Javascript, - 'sql': mode.sql.Sql, - 'template': mode.tt.Template, - #'bds': mode.bds.BDS, - 'rst': mode.rst.RST, - 'java': mode.java.Java, - 'hex': mode.hex.Hex, - 'make': mode.make.Make, + # the first dict stores our modes by (lowercase) name, and the other + # dicts all store various ways to "auto-detecting" the correct mode, + # in the precedence with which they are used. + self.modes = {} + self.mode_paths = {} + self.mode_basenames = {} + self.mode_extensions = {} + self.mode_detection = {} - 'ocaml': mode.ocaml.Ocaml, - - # lisp dialects - 'lisp': mode.lisp.Lisp, - 'scheme': mode.scheme.Scheme, - 'elisp': mode.elisp.ELisp, - } - - # these are used in this order to determine which mode to open certain - # kinds of files - self.mode_paths = { - '/etc/profile': 'sh', - } - self.mode_basenames = { - '.bashrc': 'sh', - '.bash_profile': 'sh', - '.profile': 'sh', - #'components.xml': 'bds', - '.emacs': 'elisp', - 'Makefile': 'make', - } - self.mode_extensions = { - '.py': 'python', - '.pl': 'perl', - '.pm': 'perl', - '.t': 'perl', - '.c': 'c', - #'.txt': 'text', - '.txt': 'text2', - '.s': 'nasm', - '.sh': 'sh', - '.bash': 'sh', - '.xml': 'xml', - '.xml.in': 'xml', - '.html': 'html', - '.htm': 'html', - '.js': 'javascript', - '.sql': 'sql', - '.tt': 'template', - '.css': 'css', - '.rst': 'rst', - '.java': 'java', - '.el': 'elisp', - '.scm': 'scheme', - '.mli': 'ocaml', - '.ml': 'ocaml', - } - self.mode_detection = { - 'python': 'python', - 'perl': 'perl', - 'sh': 'sh', - 'bash': 'sh', - } + mode2.Fundamental.install(self) + mode.blame.Blame.install(self) + mode.c.C.install(self) + mode.console.Console.install(self) + mode.consolemini.ConsoleMini.install(self) + mode.css.CSS.install(self) + mode.diff.Diff.install(self) + mode.dir.Dir.install(self) + mode.elisp.ELisp.install(self) + mode.hex.Hex.install(self) + mode.html.HTML.install(self) + mode.java.Java.install(self) + mode.javascript.Javascript.install(self) + mode.lisp.Lisp.install(self) + mode.make.Make.install(self) + mode.mini.Mini.install(self) + mode.mutt.Mutt.install(self) + mode.nasm.Nasm.install(self) + mode.ocaml.Ocaml.install(self) + mode.perl.Perl.install(self) + mode.python.Python.install(self) + mode.replace.Replace.install(self) + mode.rst.RST.install(self) + mode.scheme.Scheme.install(self) + mode.search.Search.install(self) + mode.sh.Sh.install(self) + mode.sql.Sql.install(self) + mode.tt.Template.install(self) + mode.text.Text.install(self) + mode.text2.Text2.install(self) + mode.which.Which.install(self) + mode.xml.XML.install(self) # initialize our methods self.methods = {} diff --git a/code_examples/imacfb.c b/code_examples/imacfb.c index 9b0129d..3b3ab07 100644 --- a/code_examples/imacfb.c +++ b/code_examples/imacfb.c @@ -1,6 +1,6 @@ /* * framebuffer driver for Intel Based Mac's - * + * * (c) 2006 Edgar Hucek * Original imac driver written by Gerd Knorr * @@ -23,39 +23,39 @@ #include #include -#define dac_reg (0x3c8) -#define dac_val (0x3c9) +#define dac_reg (0x3c8) +#define dac_val (0x3c9) typedef enum _MAC_TAPE { - M_I17, - M_I20, - M_MINI, - M_NEW + M_I17, + M_I20, + M_MINI, + M_NEW } MAC_TAPE; /* --------------------------------------------------------------------- */ static struct fb_var_screeninfo imacfb_defined __initdata = { - .activate = FB_ACTIVATE_NOW, - .height = -1, - .width = -1, - .right_margin = 32, - .upper_margin = 16, - .lower_margin = 4, - .vsync_len = 4, - .vmode = FB_VMODE_NONINTERLACED, + .activate = FB_ACTIVATE_NOW, + .height = -1, + .width = -1, + .right_margin = 32, + .upper_margin = 16, + .lower_margin = 4, + .vsync_len = 4, + .vmode = FB_VMODE_NONINTERLACED, }; static struct fb_fix_screeninfo imacfb_fix __initdata = { - .id = "IMAC VGA", - .type = FB_TYPE_PACKED_PIXELS, - .accel = FB_ACCEL_NONE, + .id = "IMAC VGA", + .type = FB_TYPE_PACKED_PIXELS, + .accel = FB_ACCEL_NONE, }; static int inverse = 0; static int mtrr = 0; /* disable mtrr */ -static int vram_remap __initdata = 0; /* Set amount of memory to be used */ -static int vram_total __initdata = 0; /* Set total amount of memory */ +static int vram_remap __initdata = 0; /* Set amount of memory to be used */ +static int vram_total __initdata = 0; /* Set total amount of memory */ static int depth; static int model = M_NEW; static int manual_height = 0; @@ -64,361 +64,361 @@ static int manual_width = 0; /* --------------------------------------------------------------------- */ static int imacfb_setcolreg(unsigned regno, unsigned red, unsigned green, - unsigned blue, unsigned transp, - struct fb_info *info) + unsigned blue, unsigned transp, + struct fb_info *info) { - /* - * Set a single color register. The values supplied are - * already rounded down to the hardware's capabilities - * (according to the entries in the `var' structure). Return - * != 0 for invalid regno. - */ - - if (regno >= info->cmap.len) - return 1; + /* + * Set a single color register. The values supplied are + * already rounded down to the hardware's capabilities + * (according to the entries in the `var' structure). Return + * != 0 for invalid regno. + */ + + if (regno >= info->cmap.len) + return 1; - if (regno < 16 && info->var.bits_per_pixel != 8) { - switch (info->var.bits_per_pixel) { - case 16: - if (info->var.red.offset == 10) { - /* 1:5:5:5 */ - ((u32*) (info->pseudo_palette))[regno] = - ((red & 0xf800) >> 1) | - ((green & 0xf800) >> 6) | - ((blue & 0xf800) >> 11); - } else { - /* 0:5:6:5 */ - ((u32*) (info->pseudo_palette))[regno] = - ((red & 0xf800) ) | - ((green & 0xfc00) >> 5) | - ((blue & 0xf800) >> 11); - } - break; - case 24: - case 32: - red >>= 8; - green >>= 8; - blue >>= 8; - ((u32 *)(info->pseudo_palette))[regno] = - (red << info->var.red.offset) | - (green << info->var.green.offset) | - (blue << info->var.blue.offset); - break; - } - } + if (regno < 16 && info->var.bits_per_pixel != 8) { + switch (info->var.bits_per_pixel) { + case 16: + if (info->var.red.offset == 10) { + /* 1:5:5:5 */ + ((u32*) (info->pseudo_palette))[regno] = + ((red & 0xf800) >> 1) | + ((green & 0xf800) >> 6) | + ((blue & 0xf800) >> 11); + } else { + /* 0:5:6:5 */ + ((u32*) (info->pseudo_palette))[regno] = + ((red & 0xf800) ) | + ((green & 0xfc00) >> 5) | + ((blue & 0xf800) >> 11); + } + break; + case 24: + case 32: + red >>= 8; + green >>= 8; + blue >>= 8; + ((u32 *)(info->pseudo_palette))[regno] = + (red << info->var.red.offset) | + (green << info->var.green.offset) | + (blue << info->var.blue.offset); + break; + } + } - return 0; + return 0; } static struct fb_ops imacfb_ops = { - .owner = THIS_MODULE, - .fb_setcolreg = imacfb_setcolreg, - .fb_fillrect = cfb_fillrect, - .fb_copyarea = cfb_copyarea, - .fb_imageblit = cfb_imageblit, + .owner = THIS_MODULE, + .fb_setcolreg = imacfb_setcolreg, + .fb_fillrect = cfb_fillrect, + .fb_copyarea = cfb_copyarea, + .fb_imageblit = cfb_imageblit, }; static int __init imacfb_setup(char *options) { - char *this_opt; - - if (!options || !*options) - return 0; - - while ((this_opt = strsep(&options, ",")) != NULL) { - if (!*this_opt) continue; - - if (! strcmp(this_opt, "inverse")) - inverse=1; - else if (! strncmp(this_opt, "mtrr:", 5)) - mtrr = simple_strtoul(this_opt+5, NULL, 0); - else if (! strcmp(this_opt, "nomtrr")) - mtrr=0; - else if (! strncmp(this_opt, "vtotal:", 7)) - vram_total = simple_strtoul(this_opt+7, NULL, 0); - else if (! strncmp(this_opt, "vremap:", 7)) - vram_remap = simple_strtoul(this_opt+7, NULL, 0); - else if (! strcmp(this_opt, "i17")) - model = M_I17; - else if (! strcmp(this_opt, "i20")) - model = M_I20; - else if (! strcmp(this_opt, "mini")) - model = M_MINI; + char *this_opt; + + if (!options || !*options) + return 0; + + while ((this_opt = strsep(&options, ",")) != NULL) { + if (!*this_opt) continue; + + if (! strcmp(this_opt, "inverse")) + inverse=1; + else if (! strncmp(this_opt, "mtrr:", 5)) + mtrr = simple_strtoul(this_opt+5, NULL, 0); + else if (! strcmp(this_opt, "nomtrr")) + mtrr=0; + else if (! strncmp(this_opt, "vtotal:", 7)) + vram_total = simple_strtoul(this_opt+7, NULL, 0); + else if (! strncmp(this_opt, "vremap:", 7)) + vram_remap = simple_strtoul(this_opt+7, NULL, 0); + else if (! strcmp(this_opt, "i17")) + model = M_I17; + else if (! strcmp(this_opt, "i20")) + model = M_I20; + else if (! strcmp(this_opt, "mini")) + model = M_MINI; else if (! strncmp(this_opt, "height:", 7)) manual_height = simple_strtoul(this_opt+7, NULL, 0); else if (! strncmp(this_opt, "width:", 6)) manual_width = simple_strtoul(this_opt+6, NULL, 0); - } - return 0; + } + return 0; } -#define DEFAULT_FB_MEM 1024*1024*16 +#define DEFAULT_FB_MEM 1024*1024*16 static int __init imacfb_probe(struct platform_device *dev) { - struct fb_info *info; - int err; - unsigned int size_vmode; - unsigned int size_remap; - unsigned int size_total; + struct fb_info *info; + int err; + unsigned int size_vmode; + unsigned int size_remap; + unsigned int size_total; - screen_info.lfb_base = 0x80010000; - screen_info.lfb_depth = 32; - screen_info.lfb_size = DEFAULT_FB_MEM / 0x10000; - screen_info.pages=1; - screen_info.blue_size = 8; - screen_info.blue_pos = 0; - screen_info.green_size = 8; - screen_info.green_pos = 8; - screen_info.red_size = 8; - screen_info.red_pos = 16; - screen_info.rsvd_size = 8; - screen_info.rsvd_pos = 24; + screen_info.lfb_base = 0x80010000; + screen_info.lfb_depth = 32; + screen_info.lfb_size = DEFAULT_FB_MEM / 0x10000; + screen_info.pages=1; + screen_info.blue_size = 8; + screen_info.blue_pos = 0; + screen_info.green_size = 8; + screen_info.green_pos = 8; + screen_info.red_size = 8; + screen_info.red_pos = 16; + screen_info.rsvd_size = 8; + screen_info.rsvd_pos = 24; - switch(model) { - case M_I17: - screen_info.lfb_width = 1440; - screen_info.lfb_height = 900; - screen_info.lfb_linelength = 1472 * 4; - break; - case M_NEW: - case M_I20: - screen_info.lfb_width = 1680; - screen_info.lfb_height = 1050; - screen_info.lfb_linelength = 1728 * 4; - break; - case M_MINI: - screen_info.lfb_width = 1024; - screen_info.lfb_height = 768; - screen_info.lfb_linelength = 2048 * 4; - break; - } + switch(model) { + case M_I17: + screen_info.lfb_width = 1440; + screen_info.lfb_height = 900; + screen_info.lfb_linelength = 1472 * 4; + break; + case M_NEW: + case M_I20: + screen_info.lfb_width = 1680; + screen_info.lfb_height = 1050; + screen_info.lfb_linelength = 1728 * 4; + break; + case M_MINI: + screen_info.lfb_width = 1024; + screen_info.lfb_height = 768; + screen_info.lfb_linelength = 2048 * 4; + break; + } - /* if the user wants to manually specify height/width, - we will override the defaults */ - /* TODO: eventually get auto-detection working */ + /* if the user wants to manually specify height/width, + we will override the defaults */ + /* TODO: eventually get auto-detection working */ if(manual_height > 0) - screen_info.lfb_height = manual_height; + screen_info.lfb_height = manual_height; if(manual_width > 0) - screen_info.lfb_width = manual_width; + screen_info.lfb_width = manual_width; - /* - static void *videomemory; - static u_long videomemorysize = (64*1024*1024); - videomemory = ioremap(0x80000000,videomemorysize); - memset(videomemory, 0x99, videomemorysize); - */ + /* + static void *videomemory; + static u_long videomemorysize = (64*1024*1024); + videomemory = ioremap(0x80000000,videomemorysize); + memset(videomemory, 0x99, videomemorysize); + */ - imacfb_fix.smem_start = screen_info.lfb_base; - imacfb_defined.bits_per_pixel = screen_info.lfb_depth; - if (15 == imacfb_defined.bits_per_pixel) - imacfb_defined.bits_per_pixel = 16; - imacfb_defined.xres = screen_info.lfb_width; - imacfb_defined.yres = screen_info.lfb_height; - imacfb_fix.line_length = screen_info.lfb_linelength; - imacfb_fix.visual = (imacfb_defined.bits_per_pixel == 8) ? - FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; + imacfb_fix.smem_start = screen_info.lfb_base; + imacfb_defined.bits_per_pixel = screen_info.lfb_depth; + if (15 == imacfb_defined.bits_per_pixel) + imacfb_defined.bits_per_pixel = 16; + imacfb_defined.xres = screen_info.lfb_width; + imacfb_defined.yres = screen_info.lfb_height; + imacfb_fix.line_length = screen_info.lfb_linelength; + imacfb_fix.visual = (imacfb_defined.bits_per_pixel == 8) ? + FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; - /* size_vmode -- that is the amount of memory needed for the - * used video mode, i.e. the minimum amount of - * memory we need. */ - size_vmode = imacfb_defined.yres * imacfb_fix.line_length; + /* size_vmode -- that is the amount of memory needed for the + * used video mode, i.e. the minimum amount of + * memory we need. */ + size_vmode = imacfb_defined.yres * imacfb_fix.line_length; - /* size_total -- all video memory we have. Used for mtrr - * entries, ressource allocation and bounds - * checking. */ - size_total = screen_info.lfb_size * 65536; - if (vram_total) - size_total = vram_total * 1024 * 1024; - if (size_total < size_vmode) - size_total = size_vmode; + /* size_total -- all video memory we have. Used for mtrr + * entries, ressource allocation and bounds + * checking. */ + size_total = screen_info.lfb_size * 65536; + if (vram_total) + size_total = vram_total * 1024 * 1024; + if (size_total < size_vmode) + size_total = size_vmode; - /* size_remap -- the amount of video memory we are going to - * use for imacfb. With modern cards it is no - * option to simply use size_total as that - * wastes plenty of kernel address space. */ - size_remap = size_vmode * 2; - if (vram_remap) - size_remap = vram_remap * 1024 * 1024; - if (size_remap < size_vmode) - size_remap = size_vmode; - if (size_remap > size_total) - size_remap = size_total; - imacfb_fix.smem_len = size_remap; + /* size_remap -- the amount of video memory we are going to + * use for imacfb. With modern cards it is no + * option to simply use size_total as that + * wastes plenty of kernel address space. */ + size_remap = size_vmode * 2; + if (vram_remap) + size_remap = vram_remap * 1024 * 1024; + if (size_remap < size_vmode) + size_remap = size_vmode; + if (size_remap > size_total) + size_remap = size_total; + imacfb_fix.smem_len = size_remap; #ifndef __i386__ - screen_info.imacpm_seg = 0; + screen_info.imacpm_seg = 0; #endif - if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) { - printk(KERN_WARNING - "imacfb: cannot reserve video memory at 0x%lx\n", - imacfb_fix.smem_start); - /* We cannot make this fatal. Sometimes this comes from magic - spaces our resource handlers simply don't know about */ - } + if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) { + printk(KERN_WARNING + "imacfb: cannot reserve video memory at 0x%lx\n", + imacfb_fix.smem_start); + /* We cannot make this fatal. Sometimes this comes from magic + spaces our resource handlers simply don't know about */ + } - info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev); - if (!info) { - release_mem_region(imacfb_fix.smem_start, size_total); - return -ENOMEM; - } - info->pseudo_palette = info->par; - info->par = NULL; + info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev); + if (!info) { + release_mem_region(imacfb_fix.smem_start, size_total); + return -ENOMEM; + } + info->pseudo_palette = info->par; + info->par = NULL; - info->screen_base = ioremap(imacfb_fix.smem_start, imacfb_fix.smem_len); - if (!info->screen_base) { - printk(KERN_ERR - "imacfb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", - imacfb_fix.smem_len, imacfb_fix.smem_start); - err = -EIO; - goto err; - } + info->screen_base = ioremap(imacfb_fix.smem_start, imacfb_fix.smem_len); + if (!info->screen_base) { + printk(KERN_ERR + "imacfb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", + imacfb_fix.smem_len, imacfb_fix.smem_start); + err = -EIO; + goto err; + } - printk(KERN_INFO "imacfb: framebuffer at 0x%lx, mapped to 0x%p, " - "using %dk, total %dk\n", - imacfb_fix.smem_start, info->screen_base, - size_remap/1024, size_total/1024); - printk(KERN_INFO "imacfb: mode is %dx%dx%d, linelength=%d, pages=%d\n", - imacfb_defined.xres, imacfb_defined.yres, imacfb_defined.bits_per_pixel, imacfb_fix.line_length, screen_info.pages); + printk(KERN_INFO "imacfb: framebuffer at 0x%lx, mapped to 0x%p, " + "using %dk, total %dk\n", + imacfb_fix.smem_start, info->screen_base, + size_remap/1024, size_total/1024); + printk(KERN_INFO "imacfb: mode is %dx%dx%d, linelength=%d, pages=%d\n", + imacfb_defined.xres, imacfb_defined.yres, imacfb_defined.bits_per_pixel, imacfb_fix.line_length, screen_info.pages); - imacfb_defined.xres_virtual = imacfb_defined.xres; - imacfb_defined.yres_virtual = imacfb_fix.smem_len / imacfb_fix.line_length; - printk(KERN_INFO "imacfb: scrolling: redraw\n"); - imacfb_defined.yres_virtual = imacfb_defined.yres; + imacfb_defined.xres_virtual = imacfb_defined.xres; + imacfb_defined.yres_virtual = imacfb_fix.smem_len / imacfb_fix.line_length; + printk(KERN_INFO "imacfb: scrolling: redraw\n"); + imacfb_defined.yres_virtual = imacfb_defined.yres; - /* some dummy values for timing to make fbset happy */ - imacfb_defined.pixclock = 10000000 / imacfb_defined.xres * 1000 / imacfb_defined.yres; - imacfb_defined.left_margin = (imacfb_defined.xres / 8) & 0xf8; - imacfb_defined.hsync_len = (imacfb_defined.xres / 8) & 0xf8; - - imacfb_defined.red.offset = screen_info.red_pos; - imacfb_defined.red.length = screen_info.red_size; - imacfb_defined.green.offset = screen_info.green_pos; - imacfb_defined.green.length = screen_info.green_size; - imacfb_defined.blue.offset = screen_info.blue_pos; - imacfb_defined.blue.length = screen_info.blue_size; - imacfb_defined.transp.offset = screen_info.rsvd_pos; - imacfb_defined.transp.length = screen_info.rsvd_size; + /* some dummy values for timing to make fbset happy */ + imacfb_defined.pixclock = 10000000 / imacfb_defined.xres * 1000 / imacfb_defined.yres; + imacfb_defined.left_margin = (imacfb_defined.xres / 8) & 0xf8; + imacfb_defined.hsync_len = (imacfb_defined.xres / 8) & 0xf8; + + imacfb_defined.red.offset = screen_info.red_pos; + imacfb_defined.red.length = screen_info.red_size; + imacfb_defined.green.offset = screen_info.green_pos; + imacfb_defined.green.length = screen_info.green_size; + imacfb_defined.blue.offset = screen_info.blue_pos; + imacfb_defined.blue.length = screen_info.blue_size; + imacfb_defined.transp.offset = screen_info.rsvd_pos; + imacfb_defined.transp.length = screen_info.rsvd_size; - if (imacfb_defined.bits_per_pixel <= 8) { - depth = imacfb_defined.green.length; - imacfb_defined.red.length = - imacfb_defined.green.length = - imacfb_defined.blue.length = - imacfb_defined.bits_per_pixel; - } + if (imacfb_defined.bits_per_pixel <= 8) { + depth = imacfb_defined.green.length; + imacfb_defined.red.length = + imacfb_defined.green.length = + imacfb_defined.blue.length = + imacfb_defined.bits_per_pixel; + } - printk(KERN_INFO "imacfb: %s: " - "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", - (imacfb_defined.bits_per_pixel > 8) ? - "Truecolor" : "Pseudocolor", - screen_info.rsvd_size, - screen_info.red_size, - screen_info.green_size, - screen_info.blue_size, - screen_info.rsvd_pos, - screen_info.red_pos, - screen_info.green_pos, - screen_info.blue_pos); + printk(KERN_INFO "imacfb: %s: " + "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", + (imacfb_defined.bits_per_pixel > 8) ? + "Truecolor" : "Pseudocolor", + screen_info.rsvd_size, + screen_info.red_size, + screen_info.green_size, + screen_info.blue_size, + screen_info.rsvd_pos, + screen_info.red_pos, + screen_info.green_pos, + screen_info.blue_pos); - imacfb_fix.ypanstep = 0; - imacfb_fix.ywrapstep = 0; + imacfb_fix.ypanstep = 0; + imacfb_fix.ywrapstep = 0; - /* request failure does not faze us, as vgacon probably has this - * region already (FIXME) */ - request_region(0x3c0, 32, "imacfb"); + /* request failure does not faze us, as vgacon probably has this + * region already (FIXME) */ + request_region(0x3c0, 32, "imacfb"); #ifdef CONFIG_MTRR - if (mtrr) { - unsigned int temp_size = size_total; - unsigned int type = 0; + if (mtrr) { + unsigned int temp_size = size_total; + unsigned int type = 0; - switch (mtrr) { - case 1: - type = MTRR_TYPE_UNCACHABLE; - break; - case 2: - type = MTRR_TYPE_WRBACK; - break; - case 3: - type = MTRR_TYPE_WRCOMB; - break; - case 4: - type = MTRR_TYPE_WRTHROUGH; - break; - default: - type = 0; - break; - } + switch (mtrr) { + case 1: + type = MTRR_TYPE_UNCACHABLE; + break; + case 2: + type = MTRR_TYPE_WRBACK; + break; + case 3: + type = MTRR_TYPE_WRCOMB; + break; + case 4: + type = MTRR_TYPE_WRTHROUGH; + break; + default: + type = 0; + break; + } - if (type) { - int rc; + if (type) { + int rc; - /* Find the largest power-of-two */ - while (temp_size & (temp_size - 1)) - temp_size &= (temp_size - 1); + /* Find the largest power-of-two */ + while (temp_size & (temp_size - 1)) + temp_size &= (temp_size - 1); - /* Try and find a power of two to add */ - do { - rc = mtrr_add(imacfb_fix.smem_start, temp_size, - type, 1); - temp_size >>= 1; - } while (temp_size >= PAGE_SIZE && rc == -EINVAL); - } - } + /* Try and find a power of two to add */ + do { + rc = mtrr_add(imacfb_fix.smem_start, temp_size, + type, 1); + temp_size >>= 1; + } while (temp_size >= PAGE_SIZE && rc == -EINVAL); + } + } #endif - - info->fbops = &imacfb_ops; - info->var = imacfb_defined; - info->fix = imacfb_fix; - info->flags = FBINFO_FLAG_DEFAULT; + + info->fbops = &imacfb_ops; + info->var = imacfb_defined; + info->fix = imacfb_fix; + info->flags = FBINFO_FLAG_DEFAULT; - if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { - err = -ENOMEM; - goto err; - } - if (register_framebuffer(info)<0) { - err = -EINVAL; - fb_dealloc_cmap(&info->cmap); - goto err; - } - printk(KERN_INFO "fb%d: %s frame buffer device\n", - info->node, info->fix.id); - return 0; + if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { + err = -ENOMEM; + goto err; + } + if (register_framebuffer(info)<0) { + err = -EINVAL; + fb_dealloc_cmap(&info->cmap); + goto err; + } + printk(KERN_INFO "fb%d: %s frame buffer device\n", + info->node, info->fix.id); + return 0; err: - framebuffer_release(info); - release_mem_region(imacfb_fix.smem_start, size_total); - return err; + framebuffer_release(info); + release_mem_region(imacfb_fix.smem_start, size_total); + return err; } static struct platform_driver imacfb_driver = { - .probe = imacfb_probe, - .driver = { - .name = "imacfb", - }, + .probe = imacfb_probe, + .driver = { + .name = "imacfb", + }, }; static struct platform_device imacfb_device = { - .name = "imacfb", + .name = "imacfb", }; static int __init imacfb_init(void) { - int ret; - char *option = NULL; + int ret; + char *option = NULL; - /* ignore error return of fb_get_options */ - fb_get_options("imacfb", &option); - imacfb_setup(option); - ret = platform_driver_register(&imacfb_driver); + /* ignore error return of fb_get_options */ + fb_get_options("imacfb", &option); + imacfb_setup(option); + ret = platform_driver_register(&imacfb_driver); - if (!ret) { - ret = platform_device_register(&imacfb_device); - if (ret) - platform_driver_unregister(&imacfb_driver); - } - return ret; + if (!ret) { + ret = platform_device_register(&imacfb_device); + if (ret) + platform_driver_unregister(&imacfb_driver); + } + return ret; } module_init(imacfb_init); diff --git a/mode/bds.py b/mode/bds.py index 27ab5f3..99e6abb 100644 --- a/mode/bds.py +++ b/mode/bds.py @@ -23,12 +23,14 @@ class BDSGrammar(Grammar): ] class BDS(mode2.Fundamental): - grammar = BDSGrammar + modename = 'BDS' + basenames = ['components.xml'] + grammar = BDSGrammar opentokens = ('delimiter',) - opentags = {'(': ')', '[': ']', '{': '}'} + opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) - closetags = {')': '(', ']': '[', '}': '{'} - colors = { + closetags = {')': '(', ']': '[', '}': '{'} + colors = { # comments 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), @@ -64,8 +66,6 @@ class BDS(mode2.Fundamental): self.add_action(BDSMakeInstall()) self.add_action(BDSCompileResources()) self.add_action(BDSRestart()) - def name(self): - return "BDS" class BDSMakeInstall(Method): def _execute(self, w, **vargs): diff --git a/mode/blame.py b/mode/blame.py index 541f299..e57b7ff 100644 --- a/mode/blame.py +++ b/mode/blame.py @@ -15,11 +15,10 @@ class BlameGrammar(Grammar): ] class Blame(mode2.Fundamental): + modename = 'Blame' grammar = BlameGrammar colors = { 'metadata.start': ('blue', 'default', 'bold'), 'metadata.username': ('cyan', 'default', 'bold'), 'metadata.end': ('green', 'default', 'bold'), } - def name(self): - return "Blame" diff --git a/mode/c.py b/mode/c.py index 0fcf6a4..63e5e87 100644 --- a/mode/c.py +++ b/mode/c.py @@ -176,13 +176,15 @@ class CTabber(tab2.StackTabber): return currlvl class C(mode2.Fundamental): - tabbercls = CTabber - grammar = CGrammar + modename = 'C' + extensions = ['.c'] + tabbercls = CTabber + grammar = CGrammar opentokens = ('delimiter',) - opentags = {'(': ')', '[': ']', '{': '}'} + opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) - closetags = {')': '(', ']': '[', '}': '{'} - colors = { + closetags = {')': '(', ']': '[', '}': '{'} + colors = { 'macrocomment.start': ('red', 'default'), 'macrocomment.null': ('red', 'default'), 'macrocomment.end': ('red', 'default'), @@ -240,8 +242,6 @@ class C(mode2.Fundamental): self.add_action_and_bindings(CMake(), ('C-c C-c',)) self.add_action_and_bindings(CSetMake(), ('C-c M-m',)) self.makecmd = "make" - def name(self): - return "C" class CSetMake(method.Method): '''Set the path(s) to find perl modules''' diff --git a/mode/console.py b/mode/console.py index 774931b..d77fe8c 100644 --- a/mode/console.py +++ b/mode/console.py @@ -14,6 +14,7 @@ class ConsoleGrammar(Grammar): PatternRule(r'bareword', r'[a-zA-Z_][a-zA-Z0-9_]*'), ] class Console(mode2.Fundamental): + modename = 'Console' grammar = ConsoleGrammar() colors = { 'mesg': ('blue', 'default'), @@ -26,5 +27,3 @@ class Console(mode2.Fundamental): 'string.null': ('green', 'default'), 'string.end': ('green', 'default'), } - def name(self): - return "Console" diff --git a/mode/consolemini.py b/mode/consolemini.py index 8f59d24..22dc529 100644 --- a/mode/consolemini.py +++ b/mode/consolemini.py @@ -3,7 +3,8 @@ import color, completer, method, mode2 from lex3 import Grammar, PatternRule from point2 import Point -class Console(mode2.Fundamental): +class ConsoleMini(mode2.Fundamental): + modename = 'ConsoleMini' def __init__(self, w): mode2.Fundamental.__init__(self, w) self.bindings = {} @@ -48,8 +49,6 @@ class Console(mode2.Fundamental): #self.add_action_and_bindings(ConsoleTab(), ('TAB',)) for c in string.letters + string.digits + string.punctuation: self.add_binding('insert-string-%s' % c, c) - def name(self): - return "Console" class ConsoleExec(method.Method): def _execute(self, w, **vargs): diff --git a/mode/css.py b/mode/css.py index 88ac356..9ba8b8a 100644 --- a/mode/css.py +++ b/mode/css.py @@ -42,8 +42,10 @@ class CSSGrammar(Grammar): ] class CSS(mode2.Fundamental): - grammar = CSSGrammar - colors = { + modename = 'CSS' + extensions = ['.css'] + grammar = CSSGrammar + colors = { 'comment': ('red', 'default'), 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), @@ -89,5 +91,3 @@ class CSS(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Javascript" diff --git a/mode/diff.py b/mode/diff.py index 4d5600f..dbe5234 100644 --- a/mode/diff.py +++ b/mode/diff.py @@ -12,6 +12,7 @@ class DiffGrammar(Grammar): ] class Diff(mode2.Fundamental): + modename = 'diff' grammar = DiffGrammar() colors = { 'left': ('red', 'default', 'bold'), @@ -24,8 +25,6 @@ class Diff(mode2.Fundamental): mode2.Fundamental.__init__(self, w) #self.add_action_and_bindings(DiffNextSection(), ('M-n', 'M-D_ARROW',)) #self.add_action_and_bindings(DiffPreviousSection(), ('M-p', 'M-U_ARROW',)) - def name(self): - return "Diff" class DiffNextSection(method.Method): re = re.compile("(?:^|(?<=\n))@@ [-+0-9a-z, ]* @@(?:$|\n)") diff --git a/mode/dir.py b/mode/dir.py index c07b6da..c8e34a1 100644 --- a/mode/dir.py +++ b/mode/dir.py @@ -36,6 +36,7 @@ class DirGrammar(Grammar): ] class Dir(mode2.Fundamental): + modename = 'Dir' grammar = DirGrammar() colors = { 'blk.start': ('cyan', 'default'), @@ -74,8 +75,6 @@ class Dir(mode2.Fundamental): self.add_action_and_bindings(Chgrp(), ('C-c g',)) self.add_action_and_bindings(TouchPath(), ('C-c t',)) self.add_action_and_bindings(RemovePath(), ('DELETE', 'BACKSPACE', 'C-d')) - def name(self): - return "Dir" class RefreshView(Method): def _execute(self, w, **vargs): diff --git a/mode/elisp.py b/mode/elisp.py index 04b7d87..8830654 100644 --- a/mode/elisp.py +++ b/mode/elisp.py @@ -29,13 +29,16 @@ class ELispTabber(tab2.StackTabber): pass class ELisp(mode2.Fundamental): + modename = 'ELisp' + basenames = ['.emacs'] + extensions = ['.el'] tabbercls = ELispTabber grammar = ELispGrammar opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} - colors = { + colors = { 'keyword': ('cyan', 'default'), 'reserved': ('blue', 'default'), 'symbol': ('magenta', 'default'), @@ -59,5 +62,3 @@ class ELisp(mode2.Fundamental): self.add_bindings('close-bracket', (']',)) ## add lisp-specific methods #self.add_action_and_bindings(LispCheckSyntax(), ('C-c s',)) - def name(self): - return "ELisp" diff --git a/mode/hex.py b/mode/hex.py index fbf5776..f397606 100644 --- a/mode/hex.py +++ b/mode/hex.py @@ -11,8 +11,9 @@ class HexGrammar(Grammar): ] class Hex(mode2.Fundamental): - grammar = HexGrammar - colors = { + modename = 'Hex' + grammar = HexGrammar + colors = { 'zero': ('magenta', 'default'), 'byte': ('white', 'default'), } @@ -30,9 +31,6 @@ class Hex(mode2.Fundamental): else: self.del_binding(c) - def name(self): - return "Hex" - class GotoWord(Method): '''Jump to the specified line number''' args = [Argument("wordno", type=type(0), prompt="Goto word: ")] diff --git a/mode/html.py b/mode/html.py index b996cc9..9b1abbf 100644 --- a/mode/html.py +++ b/mode/html.py @@ -15,8 +15,10 @@ class HTMLGrammar(Grammar): ] class HTML(mode2.Fundamental): - grammar = HTMLGrammar - colors = { + modename = 'HTML' + extensions = ['.html', '.htm', '.shtml', '.shtm', '.xhtml'] + grammar = HTMLGrammar + colors = { 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), 'comment.end': ('red', 'default'), @@ -39,14 +41,9 @@ class HTML(mode2.Fundamental): 'tag.string.end': ('green', 'default'), 'tag.end': ('default', 'default'), } - js = Javascript(None) - for name in js.colors: - colors['script.%s' % name] = js.colors[name] - del js + colors.update(Javascript.colors) def __init__(self, w): mode2.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "HTML" diff --git a/mode/java.py b/mode/java.py index 14b3de1..16a3419 100644 --- a/mode/java.py +++ b/mode/java.py @@ -154,13 +154,15 @@ class JavaTabber(CTabber): return currlvl class Java(mode2.Fundamental): - tabbercls = JavaTabber - grammar = JavaGrammar + modename = 'Java' + extensions = ['.java'] + tabbercls = JavaTabber + grammar = JavaGrammar opentokens = ('delimiter',) - opentags = {'(': ')', '[': ']', '{': '}'} + opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) - closetags = {')': '(', ']': '[', '}': '{'} - colors = { + closetags = {')': '(', ']': '[', '}': '{'} + colors = { 'comment': ('red', 'default'), 'comment.start': ('red', 'default'), 'comment.end': ('red', 'default'), @@ -190,5 +192,3 @@ class Java(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Java" diff --git a/mode/javascript.py b/mode/javascript.py index 23def08..caf99c0 100644 --- a/mode/javascript.py +++ b/mode/javascript.py @@ -53,13 +53,15 @@ class JavascriptTabber(tab2.StackTabber): return currlvl class Javascript(mode2.Fundamental): + modename = 'Javascript' + extensions = ['.js'] grammar = JavascriptGrammar tabbercls = JavascriptTabber opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} - colors = { + colors = { 'comment': ('red', 'default'), 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), @@ -93,5 +95,3 @@ class Javascript(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Javascript" diff --git a/mode/lisp.py b/mode/lisp.py index da4bb1b..7f4eccc 100644 --- a/mode/lisp.py +++ b/mode/lisp.py @@ -31,6 +31,7 @@ class LispTabber(tab2.StackTabber): return currlvl class Lisp(mode2.Fundamental): + modename = 'Lisp' tabwidth = 2 tabbercls = LispTabber grammar = LispGrammar @@ -51,5 +52,3 @@ class Lisp(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Lisp" diff --git a/mode/make.py b/mode/make.py index d4b1091..e1703e2 100644 --- a/mode/make.py +++ b/mode/make.py @@ -28,9 +28,11 @@ class MakeGrammar(Grammar): ] class Make(mode2.Fundamental): - grammar = MakeGrammar - savetabs = True - colors = { + modename = 'Make' + basenames = ['Makefile'] + grammar = MakeGrammar + savetabs = True + colors = { 'comment': ('red', 'default'), 'continuation': ('red', 'default'), @@ -48,5 +50,3 @@ class Make(mode2.Fundamental): 'string.end': ('green', 'default'), } colors.update(Sh.colors) - def name(self): - return "Make" diff --git a/mode/mini.py b/mode/mini.py index 7bdb7ac..9dda313 100644 --- a/mode/mini.py +++ b/mode/mini.py @@ -1,7 +1,7 @@ import method, mode2 class Mini(mode2.Fundamental): - '''This is the default mode''' + modename = 'Mini' def __init__(self, w): mode2.Fundamental.__init__(self, w) @@ -18,10 +18,6 @@ class Mini(mode2.Fundamental): # add some new actions for the minibuffer self.add_action_and_bindings(MiniCallback(), ('RETURN',)) self.add_action_and_bindings(MiniTabComplete(), ('TAB',)) - #self.add_action_and_bindings(MiniCancel(), ('C-]',)) - - def name(self): - return "Mini" class MiniCallback(method.Method): def execute(self, window, **vargs): diff --git a/mode/mutt.py b/mode/mutt.py index 6517921..b180e31 100644 --- a/mode/mutt.py +++ b/mode/mutt.py @@ -18,8 +18,9 @@ class MuttGrammar(Grammar): ] class Mutt(mode2.Fundamental): - grammar = MuttGrammar() - colors = { + modename = 'Mutt' + grammar = MuttGrammar() + colors = { 'header': ('green', 'default', 'bold'), 'email': ('cyan', 'default', 'bold'), 'url': ('cyan', 'default', 'bold'), @@ -38,8 +39,6 @@ class Mutt(mode2.Fundamental): self.add_action_and_bindings(mode.text.LearnWord(), ('C-c l',)) self.add_action_and_bindings(MuttWrapParagraph(), ('M-q',)) self.add_action_and_bindings(MuttInsertSpace(), ('SPACE',)) - def name(self): - return "Mutt" class MuttWrapLine(method.WrapLine): limit = 72 diff --git a/mode/nasm.py b/mode/nasm.py index 8021321..59cd7ff 100644 --- a/mode/nasm.py +++ b/mode/nasm.py @@ -27,8 +27,10 @@ class NasmGrammar(Grammar): class Nasm(mode2.Fundamental): - grammar = NasmGrammar - colors = { + modename = 'nasm' + extensions = ['.s'] + grammar = NasmGrammar + colors = { 'keyword': ('cyan', 'default', 'bold'), 'macros': ('blue', 'default', 'bold'), 'string.start': ('green', 'default'), @@ -39,7 +41,3 @@ class Nasm(mode2.Fundamental): 'instructions': ('magenta', 'default'), 'label': ('blue', 'default'), } - def __init__(self, w): - mode2.Fundamental.__init__(self, w) - def name(self): - return "Nasm" diff --git a/mode/ocaml.py b/mode/ocaml.py index 430e16f..02e3fc5 100644 --- a/mode/ocaml.py +++ b/mode/ocaml.py @@ -55,12 +55,14 @@ class OcamlGrammar(Grammar): ] class Ocaml(mode2.Fundamental): + modename = 'ocaml' + extensions = ['.mli', '.ml'] grammar = OcamlGrammar opentokens = ('delimiter',) opentags = {'(': ')'} closetokens = ('delimiter',) closetags = {')': '('} - colors = { + colors = { 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), 'comment.end': ('red', 'default'), @@ -90,5 +92,3 @@ class Ocaml(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Ocaml" diff --git a/mode/perl.py b/mode/perl.py index 4dd1e91..27665e3 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -195,13 +195,16 @@ class PerlTabber(tab2.StackTabber): return currlvl class Perl(mode2.Fundamental): + modename = 'Perl' + extensions = ['.pl', '.pm'] + detection = ['perl'] tabbercls = PerlTabber grammar = PerlGrammar opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} - colors = { + colors = { # comments 'comment': ('red', 'default'), 'endblock.start': ('red', 'default'), @@ -297,7 +300,6 @@ class Perl(mode2.Fundamental): 'translate.end': ('magenta', 'default'), 'translate.null': ('magenta', 'default'), } - def __init__(self, w): mode2.Fundamental.__init__(self, w) @@ -321,9 +323,6 @@ class Perl(mode2.Fundamental): self.functions = None self.perllib = 'lib' - def name(self): - return "Perl" - def build_function_map(self): b = self.window.buffer self.functions = {} diff --git a/mode/python.py b/mode/python.py index bf8a0db..82ab78d 100644 --- a/mode/python.py +++ b/mode/python.py @@ -10,6 +10,7 @@ class StringGrammar(Grammar): ] class RawStringGrammar(Grammar): rules = [ + PatternRule(r'escaped', r'\\\\'), PatternRule(r'escaped', r"\\'"), PatternRule(r'escaped', r'\\"'), ] @@ -176,13 +177,16 @@ class PythonTabber(tab2.StackTabber): return currlvl class Python(mode2.Fundamental): + modename = 'Python' + extensions = ['.py'] + detection = ['python'] tabbercls = PythonTabber grammar = PythonGrammar opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} - colors = { + colors = { 'keyword': ('cyan', 'default'), 'reserved': ('magenta', 'default'), 'builtin': ('cyan', 'default'), @@ -215,8 +219,6 @@ class Python(mode2.Fundamental): self.add_action_and_bindings(PythonDictCleanup(), ('C-c h',)) # highlighting self.pythonlib = "." - def name(self): - return "Python" class PythonSetLib(method.Method): '''Set the path(s) to find perl modules''' diff --git a/mode/replace.py b/mode/replace.py index a7a712c..02fa98d 100644 --- a/mode/replace.py +++ b/mode/replace.py @@ -4,7 +4,7 @@ import color, method, minibuffer, mode2, searchutil from point2 import Point class Replace(mode2.Fundamental): - '''This is the default mode''' + modename = 'Replace' def __init__(self, w): mode2.Fundamental.__init__(self, w) @@ -22,8 +22,6 @@ class Replace(mode2.Fundamental): w.set_error('%r was not found' % m.before) raise minibuffer.MiniBufferError _set_prompt(m) - def name(self): - return "Replace" class ReplaceOne(method.Method): def execute(self, w, **vargs): diff --git a/mode/rst.py b/mode/rst.py index 81ebeb1..feb566e 100644 --- a/mode/rst.py +++ b/mode/rst.py @@ -41,8 +41,10 @@ class RSTGrammar(Grammar): ] class RST(mode2.Fundamental): - grammar = RSTGrammar - colors = { + modename = 'RST' + extensions = ['.rst'] + grammar = RSTGrammar + colors = { 'title': ('blue', 'default'), 'title_over': ('blue', 'default'), 'title_under': ('blue', 'default'), @@ -73,5 +75,3 @@ class RST(mode2.Fundamental): 'bullet': ('magenta', 'default'), 'enumeration': ('magenta', 'default'), } - def name(self): - return "RST" diff --git a/mode/scheme.py b/mode/scheme.py index b92229a..2738006 100644 --- a/mode/scheme.py +++ b/mode/scheme.py @@ -26,6 +26,8 @@ class SchemeGrammar(Grammar): ] class Scheme(mode2.Fundamental): + modename = 'Scheme' + extensions = ['.scm'] tabwidth = 2 tabbercls = mode.lisp.LispTabber grammar = SchemeGrammar @@ -50,11 +52,6 @@ class Scheme(mode2.Fundamental): } def __init__(self, w): mode2.Fundamental.__init__(self, w) - # tag matching self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - ## add scheme-specific methods - #self.add_action_and_bindings(SchemeCheckSyntax(), ('C-c s',)) - def name(self): - return "Scheme" diff --git a/mode/search.py b/mode/search.py index cf5cce7..a72fb09 100644 --- a/mode/search.py +++ b/mode/search.py @@ -7,7 +7,7 @@ selected_color = 'magenta' unselected_color = 'yellow' class Search(mode2.Fundamental): - '''This is the default mode''' + modename = 'Search' def __init__(self, w): mode2.Fundamental.__init__(self, w) @@ -29,9 +29,6 @@ class Search(mode2.Fundamental): self.add_action_and_bindings(InsertSearchString(c), (c,)) self.add_action_and_bindings(InsertSearchString(' '), ('SPACE',)) - def name(self): - return "Search" - def _make_regex(w, s): try: if w.buffer.method.is_literal: diff --git a/mode/sh.py b/mode/sh.py index fc0b904..8479c62 100644 --- a/mode/sh.py +++ b/mode/sh.py @@ -23,7 +23,6 @@ class EvalGrammar(Grammar): class CaseGrammar(Grammar): rules = [ - #RegionRule(r'stanza', r'.+\)', Grammar, r';;'), RegionRule(r'stanza', r'.+\)', Grammar, r';;'), ] @@ -71,8 +70,9 @@ class ShGrammar(Grammar): PatternRule(r'eol', r'\n$'), ] -# hack to get some circular grammar refs +# hacks to get some circular grammar refs CaseGrammar.rules[0].pairs[0] = (ShGrammar, CaseGrammar.rules[0].pairs[0][1]) +#ShGrammar.rules[2].pairs[0] = (ShGrammar, ShGrammar.rules[0].pairs[0][1]) class ShTabber(tab2.StackTabber): def is_base(self, y): @@ -102,12 +102,16 @@ class ShTabber(tab2.StackTabber): return currlvl class Sh(mode2.Fundamental): + modename = 'sh' + paths = ['/etc/profile'] + basenames = ['.bashrc', '.bash_profile', '.profile'] + extensions = ['.bash', '.sh'] + detection = ['sh', 'bash'] grammar = ShGrammar tabbercls = ShTabber opentokens = ('delimiter', 'reserved', 'case.start') - opentags = {'(': ')', '[': ']', '{': '}', - 'do': 'done', 'then': 'fi', 'case': 'esac'} - closetokens = ('delimiter', 'reserved', 'case.end') + opentags = {'(': ')', '[': ']', '{': '}', 'do': 'done', 'then': 'fi', 'case': 'esac'} + closetokens = ('delimiter', 'reserved', 'case.end') closetags = {')': '(', ']': '[', '}': '{', 'done': 'do', 'fi': 'then', 'esac': 'case'} colors = { diff --git a/mode/sql.py b/mode/sql.py index c2965f1..6e2a231 100644 --- a/mode/sql.py +++ b/mode/sql.py @@ -93,13 +93,15 @@ class SqlTabber(tab2.StackTabber): return currlvl class Sql(mode2.Fundamental): + modename = 'Sql' + extensions = ['.sql'] grammar = SqlGrammar tabbercls = SqlTabber opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} - colors = { + colors = { 'comment': ('red', 'default'), 'operator': ('yellow', 'default'), 'attribute': ('magenta', 'default'), @@ -126,11 +128,8 @@ class Sql(mode2.Fundamental): 'function.definition.null': ('magenta', 'default'), 'function.definition.end': ('magenta', 'default'), } - def __init__(self, w): mode2.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Sql" diff --git a/mode/text.py b/mode/text.py index e08d427..0605ba0 100644 --- a/mode/text.py +++ b/mode/text.py @@ -35,8 +35,10 @@ class TextGrammar(Grammar): ] class Text(mode2.Fundamental): - grammar = TextGrammar - colors = { + modename = 'Text' + extensions=['.txt'] + grammar = TextGrammar + colors = { 'misspelled': ('red', 'default'), 'cont.start': ('default', 'default'), 'cont.end': ('default', 'default'), @@ -49,8 +51,6 @@ class Text(mode2.Fundamental): self.add_action_and_bindings(LearnWord(), ('C-c l',)) self.add_action_and_bindings(TextInsertSpace(), ('SPACE',)) self.add_action_and_bindings(method.WrapParagraph(), ('M-q',)) - def name(self): - return "Text" class TextInsertSpace(method.Method): limit = 80 diff --git a/mode/text2.py b/mode/text2.py index 29ab0df..ccaef2f 100644 --- a/mode/text2.py +++ b/mode/text2.py @@ -13,8 +13,10 @@ class Text2Grammar(Grammar): ] class Text2(mode.text.Text): - grammar = Text2Grammar - colors = { + modename = 'Text2' + grammar = Text2Grammar + extensions = ['.txt'] + colors = { 'email': ('cyan', 'default'), 'url': ('green', 'default'), 'misspelled': ('red', 'default'), @@ -24,5 +26,3 @@ class Text2(mode.text.Text): 'punct': ('default', 'default'), 'stuff': ('default', 'default'), } - def name(self): - return "Text2" diff --git a/mode/tt.py b/mode/tt.py index d283eaa..6def87e 100644 --- a/mode/tt.py +++ b/mode/tt.py @@ -29,8 +29,10 @@ class TemplateGrammar(Grammar): ] class Template(mode2.Fundamental): - grammar = TemplateGrammar - colors = { + modename = 'Template' + extensions = ['.tt'] + grammar = TemplateGrammar + colors = { 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), 'comment.end': ('red', 'default'), @@ -60,5 +62,3 @@ class Template(mode2.Fundamental): self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) - def name(self): - return "Template" diff --git a/mode/which.py b/mode/which.py index 9bdea3c..9f45f93 100644 --- a/mode/which.py +++ b/mode/which.py @@ -2,6 +2,7 @@ import color, method, mode2 from point2 import Point class Which(mode2.Fundamental): + modename = 'Which' def __init__(self, w): mode2.Fundamental.__init__(self, w) old_mode = w.buffer.method.old_window.mode @@ -24,8 +25,6 @@ class Which(mode2.Fundamental): err = "%s in mode '%s'" % (e, self.name()) self.window.application.set_error(err) self._end() - def name(self): - return "Which" def _end(self): self.window.application.close_mini_buffer() self.window.buffer.method.old_cursor = None diff --git a/mode/xml.py b/mode/xml.py index 18d5f1e..40e91f0 100644 --- a/mode/xml.py +++ b/mode/xml.py @@ -18,8 +18,10 @@ class XMLGrammar(Grammar): ] class XML(mode2.Fundamental): - grammar = XMLGrammar - colors = { + modename = 'XML' + extensions = ['.xml', '.xml.in'] + grammar = XMLGrammar + colors = { 'comment.start': ('red', 'default'), 'comment.null': ('red', 'default'), 'comment.end': ('red', 'default'), @@ -32,5 +34,3 @@ class XML(mode2.Fundamental): 'tag.string.end': ('green', 'default'), 'tag.end': ('default', 'default'), } - def name(self): - return "XML" diff --git a/mode2.py b/mode2.py index a361750..7a5b59b 100644 --- a/mode2.py +++ b/mode2.py @@ -32,6 +32,8 @@ class Handler(object): def add_binding(self, name, sequence): if self.window is None: return + elif not hasattr(self.window, 'application'): + raise Exception, "argh %r %r" % (self, self.window) elif name not in self.window.application.methods: raise Exception, "No action called %r found" % name else: @@ -72,6 +74,11 @@ class Handler(object): class Fundamental(Handler): '''This is the default mode''' + modename = "Fundamental" + paths = [] + basenames = [] + extensions = [] + detection = [] savetabs = False tabwidth = 4 tabbercls = None @@ -80,6 +87,13 @@ class Fundamental(Handler): tabber = None default_color = ('default', 'default',) colors = {} + + def install(cls, app): + app.setmode(cls.modename.lower(), cls, paths=cls.paths, + basenames=cls.basenames, extensions=cls.extensions, + detection=cls.detection) + install = classmethod(install) + def __init__(self, w): self.window = w @@ -185,7 +199,7 @@ class Fundamental(Handler): # get mode name def name(self): - return "Fundamental" + return self.modename # handle input tokens def handle_token(self, t):