| | 200 | |
| | 201 | |
| | 202 | class 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 |