Changeset 1167

Show
Ignore:
Timestamp:
03/13/08 22:04:47 (8 months ago)
Author:
rob
Message:

Added backslashify command

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/plugins/text_transforms.py

    r1166 r1167  
    198198        """ 
    199199        return txt.encode('rot13') 
     200 
     201 
     202class Backslashify(LineOrRegionMutateAction): 
     203    """Escape the end of line character by adding backslashes. 
     204     
     205    Add backslashes to the end of every line (except the last one) in the 
     206    region so that the end-of-line character is escaped.  This is useful, for 
     207    instance, within C or C++ C{#define} blocks that contain multiple line 
     208    macros. 
     209    """ 
     210    alias = "backslashify" 
     211    name = "Backslashify" 
     212    default_menu = ("Transform", 610) 
     213 
     214    def isActionAvailable(self): 
     215        """The action is only available if a region has multiple lines.""" 
     216        (pos, end) = self.mode.GetSelection() 
     217        return self.mode.LineFromPosition(pos) < self.mode.LineFromPosition(end) - 1 
     218 
     219    def mutateLines(self, lines): 
     220        """Add backslashes to the end of all lines but the last 
     221        """ 
     222        out = [] 
     223        eol = " \\" + self.mode.getLinesep() 
     224        for line in lines[:-1]: 
     225            out.append(line.rstrip() + eol) 
     226        out.append(lines[-1]) 
     227        return out 
    200228 
    201229 
     
    242270 
    243271                Reindent, CommentRegion, UncommentRegion, 
    244                 FillParagraphOrRegion, 
     272                FillParagraphOrRegion, Backslashify, 
    245273 
    246274                Tabify, Untabify, CollapseBlankLines,