Deletes count lines, starting at line with cursor. As lines are 
        deleted, lines displayed below cursor move up. Lines added to bottom of
        screen have spaces with same character attributes as last line moved 
        up.
767614
def _delete_line(self, count=1):
        
        self.display = self.display[:self.y] + \
                       self.display[self.y+1:]
        self.display.append([u" " * self.size[1]] * count)
        self.attributes = self.attributes[:self.y] + \
                       self.attributes[self.y+1:]
        last_attributes = self.attributes[-1]
        for _ in xrange(count):
            self.attributes.append(copy(last_attributes))
420281
def __move_line_or_selection(self, after_current_line=True):
        """"""
        cursor = self.textCursor()
        cursor.beginEditBlock()
        start_pos, end_pos = self.__save_selection()
        last_line = False

        # ------ Select text

        # Get selection start location
        cursor.setPosition(start_pos)
        cursor.movePosition(QTextCursor.StartOfBlock)
        start_pos = cursor.position()

        # Get selection end location
        cursor.setPosition(end_pos)
        if not cursor.atBlockStart() or end_pos == start_pos:
            cursor.movePosition(QTextCursor.EndOfBlock)
            cursor.movePosition(QTextCursor.NextBlock)
        end_pos = cursor.position()

        # Check if selection ends on the last line of the document
        if cursor.atEnd():
            if not cursor.atBlockStart() or end_pos == start_pos:
                last_line = True

        # ------ Stop if at document boundary

        cursor.setPosition(start_pos)
        if cursor.atStart() and not after_current_line:
            # Stop if selection is already at top of the file while moving up
            cursor.endEditBlock()
            self.setTextCursor(cursor)
            self.__restore_selection(start_pos, end_pos)
            return

        cursor.setPosition(end_pos, QTextCursor.KeepAnchor)
        if last_line and after_current_line:
            # Stop if selection is already at end of the file while moving down
            cursor.endEditBlock()
            self.setTextCursor(cursor)
            self.__restore_selection(start_pos, end_pos)
            return

        # ------ Move text

        sel_text = to_text_string(cursor.selectedText())
        cursor.removeSelectedText()


        if after_current_line:
            # Shift selection down
            text = to_text_string(cursor.block().text())
            sel_text = os.linesep + sel_text[0:-1]  # Move linesep at the start
            cursor.movePosition(QTextCursor.EndOfBlock)
            start_pos += len(text)+1
            end_pos += len(text)
            if not cursor.atEnd():
                end_pos += 1
        else:
            # Shift selection up
            if last_line:
                # Remove the last linesep and add it to the selected text
                cursor.deletePreviousChar()
                sel_text = sel_text + os.linesep
                cursor.movePosition(QTextCursor.StartOfBlock)
                end_pos += 1
            else:
                cursor.movePosition(QTextCursor.PreviousBlock)
            text = to_text_string(cursor.block().text())
            start_pos -= len(text)+1
            end_pos -= len(text)+1

        cursor.insertText(sel_text)

        cursor.endEditBlock()
        self.setTextCursor(cursor)
        self.__restore_selection(start_pos, end_pos)
790819
async def delete_pattern(self, pattern, count=None):
        
        cursor = '0'
        count_deleted = 0
        while cursor != 0:
            cursor, identities = await self.client.scan(
                cursor=cursor, match=pattern, count=count
            )
            count_deleted += await self.client.delete(*identities)
        return count_deleted
322893
def erase_start_of_line (self): # <ESC>[1K
        ''''''

        self.fill_region (self.cur_r, 1, self.cur_r, self.cur_c)
119676
private static int countNewLines(char[] ch, int start, int length) {
        int newLineCount = 0;
        // quite reliable, since only Commodore 8-bit machines, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
        // use only '\r'
        for (int i = start; i < length; i++) {
            newLineCount = newLineCount +  ((ch[i] == '\n') ? 1 : 0);
        }
        return newLineCount;
    }
126501
function countLines (str) {
  if (str) {
    let lines = str.match(/\n/g);
    if (lines) {
      return lines.length;
    }
  }
  return 0;
}
279276
def clean(self, line):
        
        # print ("-" + line + "-")
        if line == '':
            line = 'None'
        if self.is_lower:
            line = line.lower()
        if line == "user ":  # for slurm which has "user" and "user "
            line = "userid"
        for convert in self.change:
            line = line.replace(convert[0], convert[1])
        if self.is_strip:
            line = line.strip()
        return line.strip(' ')
827064
def select_line(self):
        
        self.cursor.movePosition(self.cursor.StartOfBlock)
        text = self.cursor.block().text()
        lindent = len(text) - len(text.lstrip())
        self.cursor.setPosition(self.cursor.block().position() + lindent)
        self.cursor.movePosition(self.cursor.EndOfBlock,
                                 self.cursor.KeepAnchor)
1112424
def _line_start_indexes(self):
        
        # Cache, because this is often reused. (If it is used, it's often used
        # many times. And this has to be fast for editing big documents!)
        if self._cache.line_indexes is None:
            # Create list of line lengths.
            line_lengths = map(len, self.lines)

            # Calculate cumulative sums.
            indexes = [0]
            append = indexes.append
            pos = 0

            for line_length in line_lengths:
                pos += line_length + 1
                append(pos)

            # Remove the last item. (This is not a new line.)
            if len(indexes) > 1:
                indexes.pop()

            self._cache.line_indexes = indexes

        return self._cache.line_indexes
7030
def _highlight_line_udiff(self, line, next):
        
        start = 0
        limit = min(len(line['line']), len(next['line']))
        while start < limit and line['line'][start] == next['line'][start]:
            start += 1
        end = -1
        limit -= start
        while -end <= limit and line['line'][end] == next['line'][end]:
            end -= 1
        end += 1
        if start or end:
            def do(l):
                last = end + len(l['line'])
                if l['action'] == 'add':
                    tag = 'ins'
                else:
                    tag = 'del'
                l['line'] = '%s<%s>%s</%s>%s' % (
                    l['line'][:start],
                    tag,
                    l['line'][start:last],
                    tag,
                    l['line'][last:]
                )
            do(line)
            do(next)
821932
def unindent(buffer, from_row, to_row, count=1):
    
    current_row = buffer.document.cursor_position_row
    line_range = range(from_row, to_row)

    def transform(text):
        remove = '    ' * count
        if text.startswith(remove):
            return text[len(remove):]
        else:
            return text.lstrip()

    # Apply transformation.
    new_text = buffer.transform_lines(line_range, transform)
    buffer.document = Document(
        new_text,
        Document(new_text).translate_row_col_to_index(current_row, 0))

    # Go to the start of the line.
    buffer.cursor_position += buffer.document.get_start_of_line_position(after_whitespace=True)
1363682
public void moveToEndOfLine() {
        String currentLine = getContent(getLine());
        LinkedList<String> toDisplayLines = toDisplayLines(currentLine);
        int remainingLines = getColumn() / terminal.getWidth() + 1;
        for (int r = 0; r < remainingLines; r++) {
            toDisplayLines.removeFirst();
        }
        frameColumn = currentLine.length();
        delegate.moveToEndOfLine();
        for (int l = 0; l < toDisplayLines.size(); l++) {
            frameLine++;
            frameColumn -= terminal.getWidth();
            if (frameLine >= terminal.getHeight() - getFooterSize()) {
                frameLine = terminal.getHeight() - getHeaderSize() - getFooterSize();
                scrollUp(1);
                console.out().print(ansi().cursor(frameLine + getHeaderSize(), 1));
                displayText(toDisplayLines.get(l));
                console.out().print(ansi().cursor(frameLine + getHeaderSize(), getColumn()));
            }
        }
        console.out().print(ansi().cursor(frameLine + getHeaderSize(), frameColumn));
    }
559992
def move_lines(self, direction=QTextCursor.Up):
        

        cursor = self.textCursor()
        if (direction == QTextCursor.Up and cursor.block() == cursor.document().firstBlock()) or \
                (direction == QTextCursor.Down and cursor.block() == cursor.document().lastBlock()):
            return False

        self.__select_text_under_cursor_blocks(cursor)
        text = cursor.selectedText()
        cursor.removeSelectedText()
        cursor.deleteChar()

        cursor.setPosition(cursor.block().next().position() if direction == QTextCursor.Down else
                           cursor.block().previous().position())
        if cursor.position() == cursor.document().firstBlock().position() and direction == QTextCursor.Down:
            cursor.movePosition(QTextCursor.End)
            cursor.insertText(QChar(QChar.ParagraphSeparator))

        start_position = cursor.position()
        cursor.insertText(text)
        end_position = cursor.position()
        not cursor.atEnd() and cursor.insertText(QChar(QChar.ParagraphSeparator))

        cursor.setPosition(start_position, QTextCursor.MoveAnchor)
        cursor.setPosition(end_position, QTextCursor.KeepAnchor)
        self.setTextCursor(cursor)

        return True
370559
private void moveCursorToNextLine() {
        cursorPosition = cursorPosition.withColumn(0).withRelativeRow(1);
        if(cursorPosition.getRow() >= currentTextBuffer.getLineCount()) {
            currentTextBuffer.newLine();
        }
        trimBufferBacklog();
        correctCursor();
    }
161223
def delete_before_cursor(self, count=1):
        
        assert count >= 0
        deleted = ''

        if self.cursor_position > 0:
            deleted = self.text[self.cursor_position - count:self.cursor_position]

            new_text = self.text[:self.cursor_position - count] + self.text[self.cursor_position:]
            new_cursor_position = self.cursor_position - len(deleted)

            # Set new Document atomically.
            self.document = Document(new_text, new_cursor_position)

        return deleted
1306642
def cursor_down(self, count=None):
        
        _top, bottom = self.margins or Margins(0, self.lines - 1)
        self.cursor.y = min(self.cursor.y + (count or 1), bottom)
212293
def clear(self, scope = 'screen'):
        """"""
        if scope == 'line':
            self.clear('beginning of line')
            self.clear('end of line')
        else: self.stream.write(self._get_cap('clear '+scope))
        self.flush()