MCPcopy Index your code
hub / github.com/python/cpython / format_paragraph_event

Method format_paragraph_event

Lib/idlelib/format.py:42–78  ·  view source on GitHub ↗

Formats paragraph to a max width specified in idleConf. If text is selected, format_paragraph_event will start breaking lines at the max width, starting from the beginning selection. If no text is selected, format_paragraph_event uses the current cursor location to

(self, event, limit=None)

Source from the content-addressed store, hash-verified

40 self.editwin = None
41
42 def format_paragraph_event(self, event, limit=None):
43 """Formats paragraph to a max width specified in idleConf.
44
45 If text is selected, format_paragraph_event will start breaking lines
46 at the max width, starting from the beginning selection.
47
48 If no text is selected, format_paragraph_event uses the current
49 cursor location to determine the paragraph (lines of text surrounded
50 by blank lines) and formats it.
51
52 The length limit parameter is for testing with a known value.
53 """
54 limit = self.max_width if limit is None else limit
55 text = self.editwin.text
56 first, last = self.editwin.get_selection_indices()
57 if first and last:
58 data = text.get(first, last)
59 comment_header = get_comment_header(data)
60 else:
61 first, last, comment_header, data = \
62 find_paragraph(text, text.index("insert"))
63 if comment_header:
64 newdata = reformat_comment(data, limit, comment_header)
65 else:
66 newdata = reformat_paragraph(data, limit)
67 text.tag_remove("sel", "1.0", "end")
68
69 if newdata != data:
70 text.mark_set("insert", first)
71 text.undo_block_start()
72 text.delete(first, last)
73 text.insert(first, newdata)
74 text.undo_block_stop()
75 else:
76 text.mark_set("insert", last)
77 text.see("insert")
78 return "break"
79
80
81FormatParagraph.reload()

Callers

nothing calls this directly

Calls 14

get_comment_headerFunction · 0.85
find_paragraphFunction · 0.85
reformat_commentFunction · 0.85
reformat_paragraphFunction · 0.85
get_selection_indicesMethod · 0.45
getMethod · 0.45
indexMethod · 0.45
tag_removeMethod · 0.45
mark_setMethod · 0.45
undo_block_startMethod · 0.45
deleteMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected