PCEF 0.1.1 documentation

Modes

«  Pre-configured editors   ::   Contents   ::   Panels  »

Modes

This page contains documentation about the available pcef modes.

HighlightLineMode

Contains the Current Line Highlighter mode.

class pcef.modes.clh.HighlightLineMode[source]

This mode highlights the current line.

Line color is defined by pcef.style.Style.activeLineColor

DESCRIPTION = 'Highlight the current line in the editor'

Mode description

IDENTIFIER = 'Highlight line'

Mode identifier

changeActiveLine()[source]

Updates the active line decoration

Code completion

class pcef.modes.code_completion.CodeCompletionMode[source]

This mode provides code completion to the CodeEdit widget.

The list of suggestion is supplied by a CodeCompletionModel.

Code completion may use more than one completion model. The suggestions list is then filled model per model by beginning by the highest priority as long as the number of suggestions is lower than pcef.modes.code_completion.CodeCompletion.minSuggestions. For example, a python editor will use a smart completion model with a high priority and use the DocumentWordsCompletion model as a fallback system when the smart model fails to provide enough suggestions.

The mode uses a QCompleter to provides display the list of suggestions.

Code completion is triggered using ctrl+space or when there is at least three characters in the word being typed.

DESCRIPTION = 'Provides code completion though completion models'

Mode description

IDENTIFIER = 'Code completion'

Mode identifier

caseSensitivity

The completion case sensitivity

static containsAny(txt, charsSet)[source]

Check whether ‘txt’ contains ANY of the chars in ‘charsSet’

install(editor)[source]

Setup the completer with the CodeEdit.

Parameters:editor – CodeEditorWidget instance
minSuggestions = None

Defines the min number of suggestions. This is used to know we should avoid using lower priority models.

nbTriggerChars = None

Number of chars needed to trigger the code completion

triggerKey = None

Trigger key (automatically associated with the control modifier)

class pcef.modes.code_completion.CompletionModel(words=None, priority=0)[source]

Base class for representing a completion model.

A completion model is a single list of suggestions associated with a priority.

This base class can be used directly with a static list of words.

priority = None

Model priority

update(source_code, line, col, filename, encoding)[source]

Non-static completion model should overrides this method to update their suggestion list.

This method is called by the completion mode whenever the completion prefix changed.

class pcef.modes.code_completion.DocumentWordsCompletionModel[source]

Provides suggestions based on the current document words.

static split(txt, seps)[source]

Splits a text in a meaningful list of words.

Parameters:
  • txt – Text to split
  • seps – List of words separators
Returns:

A set of words found in the document (excluding punctuations, numbers, ...)

update(source_code, line, col, filename, encoding)[source]

Updates the suggestion list.

Parameters:
  • source_code – document text
  • line – current line number (starting at 1)
  • col – current column number (starting at 0)
  • filename – the document filename if any
  • encoding – the document encoding if any
class pcef.modes.code_completion.Suggestion(txt, icon=None)[source]
Represent a suggestion in the completion list. A suggestion is made up of the following elements:
  • display: suggestion text (display role)
  • decoration: an optional decoration icon (decoration role)
decoration = None

QIcon used for the decoration role.

display = None

Displayed text.

Auto indent

Contains smart indent modes

class pcef.modes.indent.AutoIndentMode[source]

A basic auto indent mode that provides a basic auto indentation based on the previous line indentation.

This mode can be extended by overriding the _getIndent method.

DESCRIPTION = ' A basic auto indent mode that provides a basic auto indentation based on the previous\n line indentation.\n '

Mode description

IDENTIFIER = 'Auto indent'

Mode identifier

Right margin

Contains the right margin mode

class pcef.modes.margin.RightMarginMode[source]

Display the right margin

IDENTIFIER = 'Right margin'

Mode identifier

marginPos = None

Defines the margin position. 80 is the default

Syntax highlighting

This module contains Syntax Highlighting mode and the QSyntaxHighlighter based on pygments

class pcef.modes.sh.PygmentsBlockUserData(**kwds)[source]

Storage for the user data associated with each line.

class pcef.modes.sh.QPygmentsHighlighter(parent, lexer=None)[source]

Syntax highlighter that uses Pygments for parsing.

highlightBlock(text)[source]

Highlight a block of text

setLexerFromFilename(filename)[source]

Change the lexer based on the filename (actually only the extension is needed)

Parameters:filename – Filename or extension
set_style_sheet(stylesheet)[source]

Sets a CSS stylesheet. The classes in the stylesheet should correspond to those generated by:

pygmentize -S <style> -f html

Note that ‘set_style’ and ‘set_style_sheet’ completely override each other, i.e. they cannot be used in conjunction.

style

gets/sets the pygments style.

class pcef.modes.sh.SyntaxHighlighterMode[source]

This mode enable syntax highlighting (using the QPygmentsHighlighter)

DESCRIPTION = 'Apply syntax highlighting to the editor using '

Mode description

IDENTIFIER = 'Syntax highlighter'

Mode identifier

install(editor)[source]
setLexerFromFilename(fn='file.py')[source]

Change the highlighter lexer on the fly by supplying the filename to highlight

Note

Actually only the file extension is needed

Note

The default lexer is the Python lexer

Parameters:fn (str) – Filename or extension
pcef.modes.sh.get_tokens_unprocessed(self, text, stack=('root', ))[source]

Split text into (tokentype, text) pairs.

Monkeypatched to store the final stack on the object itself.

pcef.modes.sh.replace_pattern(tokens, new_pattern)[source]

Given a RegexLexer token dictionary ‘tokens’, replace all patterns that match the token specified in ‘new_pattern’ with ‘new_pattern’.

Zoom

This module contains the editor zoom mode

class pcef.modes.zoom.EditorZoomMode[source]

Zoom in/out mode. (the editor font is increased/decreased)

DESCRIPTION = 'Zoom the editor with ctrl+mouse wheel'

Mode description

IDENTIFIER = 'Editor zoom'

Mode identifier

«  Pre-configured editors   ::   Contents   ::   Panels  »