<jupyter_start><jupyter_text>The ``Ace`` widget allows embedding a code editor based on [Ace](https://ace.c9.io/).Only a small subset of Ace functionality is currently enabled: - **syntax highlighting** for several languages - **themes** - basic **completion** support via `ctrl+space` (using only static analysis of the code) - **annotations** - **readonly** mode Parameters:For layout and styling related parameters see the [customization user guide](../../user_guide/Customization.ipynb).* **``annotations``** (list): list of annotations. An annotation is a dict with the following keys:    - `'row'`: row in the editor of the annotation    - `'column'`: column of the annotation    - `'text'`: text displayed when hovering over the annotation    - `'type'`: type of annotation and the icon displayed {`warning` | `error`}* **``filename``** (str): If filename is provided the file extension will be used to determine the language* **``language``** (str): A string declaring which language to use for code syntax highlighting (default: 'text')* **``print_margin``** (boolean): Whether to show a print margin in the editor* **``theme``** (str): theme of the editor (default: 'chrome')* **``readonly``** (boolean): Whether the editor should be opened in read-only mode* **``value``** (str): A string with (initial) code to set in the editor___ To construct an `Ace` widget we must define it explicitly using `pn.widgets.Ace`. We can add some text as initial code.Code inserted in the editor is automatically reflected in the `value`.<jupyter_code>py_code = """import sys"""
editor = pn.widgets.Ace(value=py_code, sizing_mode='stretch_both', language='python', height=300)
editor<jupyter_output><empty_output><jupyter_text>we can add some code in it<jupyter_code>editor.value += """
import Math

x = Math.cos(x)**2 + Math.cos(y)**2
"""<jupyter_output><empty_output><jupyter_text>We can change language and theme of the editor<jupyter_code>html_code = r"""<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`</title>
    </head>
    <body>
        <h1>Title1</h1>
        <h2>Title2</h2>
        <p>Paragraph</p>
    </body>
</html>
"""
editor.language = "html"
editor.theme = "monokai"
editor.value = html_code<jupyter_output><empty_output><jupyter_text>We can add some annotations to the editor<jupyter_code>editor.annotations= [dict(row=1, column=0, text='an error', type='error'),
                     dict(row=2, column=0, text='a warning', type='warning')]<jupyter_output><empty_output><jupyter_text>If we want just to display editor content but not edit it we can set the `readonly` property to `True`<jupyter_code>#editor.readonly = True<jupyter_output><empty_output><jupyter_text>If instead of setting the language explicitly we want to set the filename and automatically detect the language based on the file extension we can do that too:<jupyter_code>editor.filename = 'test.html'<jupyter_output><empty_output><jupyter_text>Including the Ace editor in a parameterized classYou can view the Ace widget as part of a `param.Parameterized` class:<jupyter_code>class AceTest(param.Parameterized):
    editor = param.String('Hello World')
    
    def view(self):
        """ Map the string to appear as an Ace editor. """
        return pn.Param(
            self.param,
            widgets=dict(
                editor=dict(
                    type=pn.widgets.Ace,
                    language='python',
                )
            )
        )
    
ace = AceTest()
ace.view()<jupyter_output><empty_output><jupyter_text>ControlsThe `Ace` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:<jupyter_code>widget = pn.widgets.Ace(name='Ace', value=py_code, sizing_mode='stretch_both', height=300)

pn.Row(widget.controls(jslink=True), widget)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1315328832208052, 'fraction_numerical': 0.005001250312578144, 'mean_word_length': 4.4274084124830395, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '211363', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1173, 'n_words': 392, 'path': 'examples/reference/widgets/Ace.ipynb', 'repo_name': 'andriyor/panel', 'size': '3999'}