From: NeilBrown Date: Fri, 2 Jun 2023 07:24:00 +0000 (+1000) Subject: python: change how modules are loaded into the interpreter X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=f16392ae3dd86cad8d703b0868b5f90feb4a4fa7;p=edlib.git python: change how modules are loaded into the interpreter Each edlib module is now a separate python module. They must all "import edlib" and can find the editor pane in "edlib.editor" They must also import any modules they use. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 00388857..f9703a51 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -18,7 +18,7 @@ the file. - [X] ncurses - don't block in nc_external_viewer - at least abort after 30 seconds, but preferrably switch to a mode which leaves everything else running. -- [ ] lang-python should put each module in a separate module +- [X] lang-python should put each module in a separate module Maybe PyImport_ExecCodeModuleEx() after reading and compile()ing the source file. Or set up path to find edlib modules. @@ -638,7 +638,7 @@ Module features ### lang-python - [ ] repeated alarm(10)/alarm(0) calls slow things down -- [ ] lang-python should put each module in a separate module +- [X] lang-python should put each module in a separate module Maybe PyImport_ExecCodeModuleEx() after reading and compile()ing the source file. Or set up path to find edlib modules. - [ ] array index should allow two args, second being a mark for diff --git a/lang-python.c b/lang-python.c index 2c91355c..70e5fe61 100644 --- a/lang-python.c +++ b/lang-python.c @@ -64,6 +64,7 @@ struct doc_ref { int o; }; +#include #include #include "core.h" #include "misc.h" @@ -334,32 +335,52 @@ out: DEF_CMD(python_load_module) { const char *name = ci->str; - FILE *fp; - PyObject *globals, *main_mod; - PyObject *Ed; - char buf [PATH_MAX]; + int fd; + long long size; + char *code; + char buf[PATH_MAX]; + char buf2[PATH_MAX]; + PyObject *builtins, *compile, *args, *bytecode; if (!name) return Enoarg; snprintf(buf, sizeof(buf), "%s/python/%s.py", module_dir, name); - fp = fopen(buf, "r"); - if (!fp) + fd = open(buf, O_RDONLY); + if (fd < 0) return Efail; + size = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + code = malloc(size+1); + if (!code) { + close(fd); + return Efail; + } + size = read(fd, code, size); + close(fd); + if (size <= 0) { + free(code); + return Efail; + } + code[size] = 0; LOG("Loading python module %s from %s", name, buf); - main_mod = PyImport_AddModule("__main__"); - if (main_mod == NULL) - return Einval; - globals = PyModule_GetDict(main_mod); - - Ed = Pane_Frompane(ci->home); - PyDict_SetItemString(globals, "editor", Ed); - PyDict_SetItemString(globals, "pane", Pane_Frompane(ci->focus)); - PyDict_SetItemString(globals, "edlib", EdlibModule); - PyRun_FileExFlags(fp, buf, Py_file_input, globals, globals, 0, NULL); - PyErr_LOG(); - Py_DECREF(Ed); - fclose(fp); + + builtins = PyEval_GetBuiltins(); + compile = PyDict_GetItemString(builtins, "compile"); + args = safe_cast Py_BuildValue("(sss)", code, buf, "exec"); + bytecode = PyObject_Call(compile, args, NULL); + Py_DECREF(args); + free(code); + if (bytecode == NULL) { + PyErr_LOG(); + return Efail; + } + + snprintf(buf2, sizeof(buf2), "edlib.%s", name); + + if (PyImport_ExecCodeModule(buf2, bytecode) == NULL) + PyErr_LOG(); + Py_DECREF(bytecode); return 1; } @@ -2891,19 +2912,12 @@ static PyMethodDef edlib_methods[] = { }; /* This must be visible when the module is loaded so it - * cannot be static. spares doesn't like variables that are + * cannot be static. sparse doesn't like variables that are * neither extern nor static. So mark it extern */ extern char *edlib_module_path; char *edlib_module_path; -static struct PyModuleDef edlib_mod = { - PyModuleDef_HEAD_INIT, - .m_name = "edlib", - .m_doc = "edlib - one more editor is never enough.", - .m_methods = edlib_methods, -}; - void edlib_init(struct pane *ed safe) { PyObject *m; @@ -2915,9 +2929,6 @@ void edlib_init(struct pane *ed safe) else module_dir = "."; - /* This cast is for sparse, which doesn't seem to cope with L".." - * FIXME - */ PyConfig_InitPythonConfig(&config); config.isolated = 1; PyConfig_SetBytesArgv(&config, 0, argv); @@ -2936,11 +2947,16 @@ void edlib_init(struct pane *ed safe) PyType_Ready(&CommType) < 0) return; - m = PyModule_Create(&edlib_mod); - - if (!m) + m = PyImport_AddModule("edlib"); + if (!m) { + PyErr_LOG(); return; + } + + PyModule_SetDocString(m , "edlib - one more editor is never enough"); + PyModule_AddFunctions(m, edlib_methods); + PyModule_AddObject(m, "editor", Pane_Frompane(ed)); PyModule_AddObject(m, "Pane", (PyObject *)&PaneType); PyModule_AddObject(m, "PaneIter", (PyObject *)&PaneIterType); PyModule_AddObject(m, "Mark", (PyObject *)&MarkType); @@ -2977,12 +2993,14 @@ void edlib_init(struct pane *ed safe) PyModule_AddIntMacro(m, MARK_POINT); PyModule_AddIntConstant(m, "WEOF", 0x3FFFFF); - call_comm("global-set-command", ed, &python_load_module, - 0, NULL, "global-load-modules:python"); Edlib_CommandFailed = PyErr_NewException("edlib.commandfailed", NULL, NULL); Py_INCREF(Edlib_CommandFailed); PyModule_AddObject(m, "commandfailed", Edlib_CommandFailed); + EdlibModule = m; ed_pane = ed; + + call_comm("global-set-command", ed, &python_load_module, + 0, NULL, "global-load-modules:python"); } diff --git a/python/config.py b/python/config.py index 5df740d0..eacacef7 100644 --- a/python/config.py +++ b/python/config.py @@ -7,6 +7,7 @@ # config module with a more abstract language one day. # But I want some simple configuration NOW +from edlib import editor import os def config_appeared(key, focus, **a): @@ -36,8 +37,6 @@ def config_appeared(key, focus, **a): " *#+|" # section head " *[0-9]*\\.)") # Numbered list - return edlib.Efallthrough - editor.call("global-set-command", "doc:appeared-config", config_appeared) # Some modules I want auto-loaded. diff --git a/python/display-pygtk.py b/python/display-pygtk.py index f33d5b5d..bc1d84b3 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -6,10 +6,12 @@ # receive mouse/keyboard events. # provides eventloop function using gtk.main. -import os +import edlib +import os, fcntl import gi import time import cairo +import subprocess gi.require_version('Gtk', '3.0') gi.require_version('PangoCairo', '1.0') @@ -97,8 +99,7 @@ class EdDisplay(edlib.Pane): def handle_new(self, key, focus, **a): "handle:Display:new" - global editor - newdisp = EdDisplay(editor, self['DISPLAY']) + newdisp = EdDisplay(edlib.editor, self['DISPLAY']) p = newdisp.call("editor:activate-display", ret='pane') if p: focus.call("doc:attach-view", p, 1) @@ -761,5 +762,5 @@ def new_display2(key, focus, **a): focus.call("doc:attach-view", p, 1); return 1 -editor.call("global-set-command", "attach-display-gtk", new_display) -editor.call("global-set-command", "interactive-cmd-gtkwindow", new_display2) +edlib.editor.call("global-set-command", "attach-display-gtk", new_display) +edlib.editor.call("global-set-command", "interactive-cmd-gtkwindow", new_display2) diff --git a/python/lib-abbrev.py b/python/lib-abbrev.py index 30da88db..0e7b87e1 100644 --- a/python/lib-abbrev.py +++ b/python/lib-abbrev.py @@ -14,6 +14,8 @@ # Anything else is passed to parent, and if that doesn't result # in a callback, we self-destruct +import edlib + class AbbrevPane(edlib.Pane): def __init__(self, focus): edlib.Pane.__init__(self, focus) @@ -244,4 +246,4 @@ def abbrev_attach(key, focus, comm2, **a): comm2("cb", p) return 1 -editor.call("global-set-command", "attach-abbrev", abbrev_attach) +edlib.editor.call("global-set-command", "attach-abbrev", abbrev_attach) diff --git a/python/lib-autospell.py b/python/lib-autospell.py index 37cae7ee..02310873 100644 --- a/python/lib-autospell.py +++ b/python/lib-autospell.py @@ -21,6 +21,8 @@ # choose_range(focus, viewnum, attr, start, end) - changes start and end to be # a contiguous unchecked section in the range +import edlib + def show_range(action, focus, viewnum, attr): edlib.LOG("range:", attr, action) f,l = focus.vmarks(viewnum) @@ -316,6 +318,6 @@ def autospell_activate(key, focus, comm2, **a): return 1 -editor.call("global-set-command", "attach-autospell", autospell_attach) -editor.call("global-set-command", "interactive-cmd-autospell", +edlib.editor.call("global-set-command", "attach-autospell", autospell_attach) +edlib.editor.call("global-set-command", "interactive-cmd-autospell", autospell_activate) diff --git a/python/lib-compose-email.py b/python/lib-compose-email.py index 654a17a3..4bc044b7 100644 --- a/python/lib-compose-email.py +++ b/python/lib-compose-email.py @@ -29,6 +29,10 @@ # The content of filename is url encoded # +import edlib + +import os +import subprocess import email.utils import email.message import email.policy @@ -37,6 +41,7 @@ import email.headerregistry import tempfile import mimetypes import urllib +import re from datetime import date def read_status(p, key, focus, **a): @@ -904,4 +909,4 @@ def compose_mode_attach(key, focus, comm2, **a): comm2("cb", p) return 1 -editor.call("global-set-command", "attach-compose-email", compose_mode_attach) +edlib.editor.call("global-set-command", "attach-compose-email", compose_mode_attach) diff --git a/python/lib-diff.py b/python/lib-diff.py index b88d3826..bd448792 100644 --- a/python/lib-diff.py +++ b/python/lib-diff.py @@ -7,6 +7,8 @@ # - colourizes + and - lines # - interprets ':Enter' to find the given line +import edlib + import os.path def djoin(dir, tail): @@ -332,6 +334,6 @@ def add_diff(key, focus, **a): focus.call("doc:append:view-default", ",diff") return 1 -editor.call("global-set-command", "attach-diff", diff_view_attach) -editor.call("global-set-command", "interactive-cmd-diff-mode", add_diff) -editor.call("global-load-module", "lib-wiggle") +edlib.editor.call("global-set-command", "attach-diff", diff_view_attach) +edlib.editor.call("global-set-command", "interactive-cmd-diff-mode", add_diff) +edlib.editor.call("global-load-module", "lib-wiggle") diff --git a/python/lib-doc-to-text.py b/python/lib-doc-to-text.py index c58ceaf5..4969a101 100644 --- a/python/lib-doc-to-text.py +++ b/python/lib-doc-to-text.py @@ -6,9 +6,11 @@ # converts it to text using lowriter. # Unfortunately lowriter only reads and writes a file, not a pipe.. +import edlib + import subprocess import tempfile -import os +import os, fcntl class doc_pane(edlib.Pane): def __init__(self, focus, path, newpath, delayed): @@ -137,5 +139,4 @@ def doc_to_text(key, home, focus, num, str1, comm2, **a): comm2("cb", doc) return 1 -if "editor" in globals(): - editor.call("global-set-command", "doc-to-text", doc_to_text) +edlib.editor.call("global-set-command", "doc-to-text", doc_to_text) diff --git a/python/lib-glibevents.py b/python/lib-glibevents.py index 233ad1b1..cd89b100 100644 --- a/python/lib-glibevents.py +++ b/python/lib-glibevents.py @@ -4,6 +4,8 @@ # edlib module for getting events from GLib +import edlib + import signal import gi import os @@ -216,4 +218,4 @@ def register_events(key, focus, comm2, **a): events_activate(focus) return 1 -editor.call("global-set-command", "attach-glibevents", register_events) +edlib.editor.call("global-set-command", "attach-glibevents", register_events) diff --git a/python/lib-html-to-text.py b/python/lib-html-to-text.py index 5ba5725a..baf06410 100644 --- a/python/lib-html-to-text.py +++ b/python/lib-html-to-text.py @@ -6,6 +6,8 @@ # converts it from html to markdown, and creates a text pane with the # markdown text. +import edlib + import html2text def html_to_text(key, home, focus, comm2, **a): @@ -38,5 +40,4 @@ def html_to_text(key, home, focus, comm2, **a): comm2("cb", doc) return 1 -if "editor" in globals(): - editor.call("global-set-command", "html-to-text", html_to_text) +edlib.editor.call("global-set-command", "html-to-text", html_to_text) diff --git a/python/lib-html-w3m.py b/python/lib-html-w3m.py index 0ad08728..1d074f37 100644 --- a/python/lib-html-w3m.py +++ b/python/lib-html-w3m.py @@ -10,6 +10,9 @@ # applied the changes to the text as render attributes. # +import edlib + +import os, fcntl import subprocess def get_attr(tagl, tag, attr): @@ -559,5 +562,4 @@ def map_entities(str): return ret + str -if "editor" in globals(): - editor.call("global-set-command", "html-to-text-w3m", html_to_w3m) +edlib.editor.call("global-set-command", "html-to-text-w3m", html_to_w3m) diff --git a/python/lib-ical-to-text.py b/python/lib-ical-to-text.py index 6d8d1bed..abc1f9dd 100644 --- a/python/lib-ical-to-text.py +++ b/python/lib-ical-to-text.py @@ -6,6 +6,9 @@ # converts it from ical to simple text, and creates a text pane with # that text. +import edlib + +import time import icalendar def ical_to_text(key, home, focus, comm2, **a): @@ -53,5 +56,4 @@ def ical_to_text(key, home, focus, comm2, **a): comm2("cb", doc) return 1 -if "editor" in globals(): - editor.call("global-set-command", "ical-to-text", ical_to_text) +edlib.editor.call("global-set-command", "ical-to-text", ical_to_text) diff --git a/python/lib-macro.py b/python/lib-macro.py index 9fd46b44..fb288211 100644 --- a/python/lib-macro.py +++ b/python/lib-macro.py @@ -16,6 +16,8 @@ # Other functionality is available simply through global commands. # +import edlib + docname = "*Macro History*" # A macro is a list of keystroke separated by commas @@ -133,7 +135,7 @@ def name_macro(key, focus, num, str, **a): num = 1 focus.call("history:get-last", num, docname, str) -editor.call("global-set-command", "macro:capture", start_capture) -editor.call("global-set-command", "macro:finished", end_capture) -editor.call("global-set-command", "macro:replay", play_macro) -editor.call("global-set-command", "macro:name", name_macro) +edlib.editor.call("global-set-command", "macro:capture", start_capture) +edlib.editor.call("global-set-command", "macro:finished", end_capture) +edlib.editor.call("global-set-command", "macro:replay", play_macro) +edlib.editor.call("global-set-command", "macro:name", name_macro) diff --git a/python/lib-make.py b/python/lib-make.py index a891c45f..e09ef681 100644 --- a/python/lib-make.py +++ b/python/lib-make.py @@ -3,6 +3,8 @@ # May be distributed under terms of GPLv2 - see file:COPYING # +import edlib + import os, fcntl, signal class MakePane(edlib.Pane): @@ -932,9 +934,9 @@ def next_match(key, focus, num, str1, num2, **a): return 1 -editor.call("global-set-command", "attach-makecmd", make_attach) -editor.call("global-set-command", "attach-make-viewer", make_view_attach) -editor.call("global-set-command", "interactive-cmd-make", make_request) -editor.call("global-set-command", "interactive-cmd-grep", make_request) -editor.call("global-set-command", "interactive-cmd-git-grep", make_request) -editor.call("global-set-command", "interactive-cmd-next-match", next_match) +edlib.editor.call("global-set-command", "attach-makecmd", make_attach) +edlib.editor.call("global-set-command", "attach-make-viewer", make_view_attach) +edlib.editor.call("global-set-command", "interactive-cmd-make", make_request) +edlib.editor.call("global-set-command", "interactive-cmd-grep", make_request) +edlib.editor.call("global-set-command", "interactive-cmd-git-grep", make_request) +edlib.editor.call("global-set-command", "interactive-cmd-next-match", next_match) diff --git a/python/lib-mergeview.py b/python/lib-mergeview.py index 97991bc8..01518445 100644 --- a/python/lib-mergeview.py +++ b/python/lib-mergeview.py @@ -12,6 +12,8 @@ # If cursor is not on any, it is moved forward to the next one. # +import edlib + class MergePane(edlib.Pane): def __init__(self, focus): edlib.Pane.__init__(self, focus) @@ -197,6 +199,6 @@ def add_merge(key, focus, mark, **a): p.call("K:A-m", focus, mark) return 1 -editor.call("global-set-command", "attach-merge", merge_view_attach) -editor.call("global-set-command", "interactive-cmd-merge-mode", add_merge) -editor.call("global-load-module", "lib-wiggle") +edlib.editor.call("global-set-command", "attach-merge", merge_view_attach) +edlib.editor.call("global-set-command", "interactive-cmd-merge-mode", add_merge) +edlib.editor.call("global-load-module", "lib-wiggle") diff --git a/python/lib-pdf-to-text.py b/python/lib-pdf-to-text.py index c3040ab5..4efbbf13 100644 --- a/python/lib-pdf-to-text.py +++ b/python/lib-pdf-to-text.py @@ -6,6 +6,9 @@ # converts it from pdf to text, and creates a text doc with the # text. +import edlib + +import os, fcntl import subprocess class pdf_pane(edlib.Pane): @@ -128,5 +131,4 @@ def pdf_to_text(key, home, focus, num, comm2, **a): comm2("cb", doc) return 1 -if "editor" in globals(): - editor.call("global-set-command", "pdf-to-text", pdf_to_text) +edlib.editor.call("global-set-command", "pdf-to-text", pdf_to_text) diff --git a/python/lib-server.py b/python/lib-server.py index 500f6d81..5b3c93bb 100755 --- a/python/lib-server.py +++ b/python/lib-server.py @@ -12,19 +12,21 @@ else: sockpath = "/tmp/edlib-neilb" try: + import edlib + class ServerPane(edlib.Pane): # This pane receives requests on a socket and # forwards them to the editor. When a notification # arrives, it is sent back to the client def __init__(self, sock): - edlib.Pane.__init__(self, editor) + edlib.Pane.__init__(self, edlib.editor) self.sock = sock self.term = None self.disp = None self.doc = None self.want_close = False self.lineno = None - editor.call("event:read", sock.fileno(), + edlib.editor.call("event:read", sock.fileno(), self.read) def read(self, key, **a): @@ -66,7 +68,7 @@ try: path = msg[5:].decode("utf-8",'ignore') try: # 8==reload - d = editor.call("doc:open", -1, 8, path, ret='pane') + d = edlib.editor.call("doc:open", -1, 8, path, ret='pane') except edlib.commandfailed: d = None if not d: @@ -108,7 +110,7 @@ try: return 1 if msg[:21] == b"doc:request:doc:done:": path = msg[21:].decode("utf-8", 'ignore') - d = editor.call("doc:open", -1, path, ret='pane') + d = edlib.editor.call("doc:open", -1, path, ret='pane') if not d: self.sock.send(b"FAIL") return 1 @@ -128,7 +130,7 @@ try: self.sock.send(b"OK") return 1 if cmd == 'x11window' and not self.term: - p = editor.call("interactive-cmd-x11window", + p = edlib.editor.call("interactive-cmd-x11window", arg, env['XAUTHORITY'], ret='pane') if p: for v in env: @@ -140,7 +142,7 @@ try: return 1 if cmd == 'term' and not self.term: path = arg - p = editor + p = edlib.editor p = p.call("attach-display-ncurses", path, env['TERM'], ret='pane') for v in env: @@ -394,7 +396,7 @@ else: if key != "key": focus.call("Message", "Server restarted") return 1 - server_rebind("key", editor) - editor.call("global-set-command", "lib-server:done", server_done) - editor.call("global-set-command", "interactive-cmd-server-start", + server_rebind("key", edlib.editor) + edlib.editor.call("global-set-command", "lib-server:done", server_done) + edlib.editor.call("global-set-command", "interactive-cmd-server-start", server_rebind) diff --git a/python/lib-shellcmd.py b/python/lib-shellcmd.py index 28c65979..4e415b27 100644 --- a/python/lib-shellcmd.py +++ b/python/lib-shellcmd.py @@ -3,6 +3,8 @@ # May be distributed under terms of GPLv2 - see file:COPYING # +import edlib + import subprocess, os, fcntl, signal class ShellPane(edlib.Pane): @@ -260,5 +262,5 @@ def shell_view_attach(key, focus, comm2, **a): comm2("callback", p) return 1 -editor.call("global-set-command", "attach-shellcmd", shell_attach) -editor.call("global-set-command", "attach-shell-viewer", shell_view_attach) +edlib.editor.call("global-set-command", "attach-shellcmd", shell_attach) +edlib.editor.call("global-set-command", "attach-shell-viewer", shell_view_attach) diff --git a/python/lib-textfill.py b/python/lib-textfill.py index d9da65f9..f673450e 100644 --- a/python/lib-textfill.py +++ b/python/lib-textfill.py @@ -23,6 +23,8 @@ # is then chosen as the maximal set of non-alphanumerics non-quote # characters. +import edlib + import re def span(line, chars): @@ -353,6 +355,6 @@ def fill_mode_activate(key, focus, comm2, **a): focus.call("doc:append:view-default", ",textfill") return 1 -editor.call("global-set-command", "attach-textfill", fill_mode_attach) -editor.call("global-set-command", "interactive-cmd-fill-mode", +edlib.editor.call("global-set-command", "attach-textfill", fill_mode_attach) +edlib.editor.call("global-set-command", "interactive-cmd-fill-mode", fill_mode_activate) diff --git a/python/module-notmuch.py b/python/module-notmuch.py index db178651..60086c92 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -28,10 +28,12 @@ # "query.misc-list" is a subset of current-list for which query:current should not # be assumed. +import edlib + from subprocess import Popen, PIPE, DEVNULL, TimeoutExpired import re -import os -import os.path +import tempfile +import os, fcntl import json import time import mimetypes @@ -608,10 +610,9 @@ class notmuch_main(edlib.Doc): comm2("callback", focus, "%d" % self.searches.maxlen) return 1 if str.startswith('config:'): - p = subprocess.Popen(['/usr/bin/notmuch', 'config', 'get', str[7:]], - close_fds = True, - stderr = subprocess.PIPE, - stdout = subprocess.PIPE) + p = Popen(['/usr/bin/notmuch', 'config', 'get', str[7:]], + close_fds = True, + stderr = PIPE, stdout = PIPE) out,err = p.communicate() p.wait() if out: @@ -3728,14 +3729,13 @@ def notmuch_search(key, focus, **a): p.call("doc:char-s") return 1 -if "editor" in globals(): - editor.call("global-set-command", "attach-doc-notmuch", notmuch_doc) - editor.call("global-set-command", "attach-render-notmuch:master-view", - render_master_view_attach) - editor.call("global-set-command", "attach-render-notmuch:threads", - render_query_attach) - editor.call("global-set-command", "attach-render-notmuch:message", - render_message_attach) - editor.call("global-set-command", "interactive-cmd-nm", notmuch_mode) - editor.call("global-set-command", "interactive-cmd-nmc", notmuch_compose) - editor.call("global-set-command", "interactive-cmd-nms", notmuch_search) +edlib.editor.call("global-set-command", "attach-doc-notmuch", notmuch_doc) +edlib.editor.call("global-set-command", "attach-render-notmuch:master-view", + render_master_view_attach) +edlib.editor.call("global-set-command", "attach-render-notmuch:threads", + render_query_attach) +edlib.editor.call("global-set-command", "attach-render-notmuch:message", + render_message_attach) +edlib.editor.call("global-set-command", "interactive-cmd-nm", notmuch_mode) +edlib.editor.call("global-set-command", "interactive-cmd-nmc", notmuch_compose) +edlib.editor.call("global-set-command", "interactive-cmd-nms", notmuch_search) diff --git a/python/render-c-mode.py b/python/render-c-mode.py index eefa5f05..27feea27 100644 --- a/python/render-c-mode.py +++ b/python/render-c-mode.py @@ -2,6 +2,8 @@ # Copyright Neil Brown (c)2018-2023 # May be distributed under terms of GPLv2 - see file:COPYING +import edlib + def textwidth(line, w=0): for c in line: if c == '\t': @@ -1063,8 +1065,8 @@ def attach_indent(key, focus, **a): CModePane(focus) return 1 -editor.call("global-set-command", "doc:appeared-c-mode", c_mode_appeared) -editor.call("global-set-command", "doc:appeared-py-mode", py_mode_appeared) -editor.call("global-set-command", "attach-c-mode", c_mode_attach) -editor.call("global-set-command", "attach-py-mode", py_mode_attach) -editor.call("global-set-command", "interactive-cmd-indent", attach_indent) +edlib.editor.call("global-set-command", "doc:appeared-c-mode", c_mode_appeared) +edlib.editor.call("global-set-command", "doc:appeared-py-mode", py_mode_appeared) +edlib.editor.call("global-set-command", "attach-c-mode", c_mode_attach) +edlib.editor.call("global-set-command", "attach-py-mode", py_mode_attach) +edlib.editor.call("global-set-command", "interactive-cmd-indent", attach_indent) diff --git a/python/render-calc.py b/python/render-calc.py index cd70f9b0..7fbaef43 100644 --- a/python/render-calc.py +++ b/python/render-calc.py @@ -6,6 +6,8 @@ # starting '>' # +import edlib + class CalcView(edlib.Pane): def __init__(self, focus): edlib.Pane.__init__(self, focus) @@ -172,7 +174,7 @@ def calc_appeared(key, focus, **a): focus["view-default"] = "view-calc" return edlib.Efallthrough -editor.call("global-set-command", "attach-view-calc", calc_view_attach) -editor.call("global-load-module", "lib-calc") -editor.call("global-set-command", "interactive-cmd-calc", add_calc) -editor.call("global-set-command", "doc:appeared-calc", calc_appeared) +edlib.editor.call("global-set-command", "attach-view-calc", calc_view_attach) +edlib.editor.call("global-load-module", "lib-calc") +edlib.editor.call("global-set-command", "interactive-cmd-calc", add_calc) +edlib.editor.call("global-set-command", "doc:appeared-calc", calc_appeared) diff --git a/python/render-present.py b/python/render-present.py index 252ac662..83a7b70c 100644 --- a/python/render-present.py +++ b/python/render-present.py @@ -60,6 +60,7 @@ default_attrs = "normal 10 family:sans fg:black bg:white left:5 space-after:1 sp # When change happens, type changed to 'unknown' which triggers self.mark_lines() to # reparse some of the page. +import edlib import re import os @@ -773,6 +774,6 @@ def markdown_appeared(key, focus, **a): focus["view-default"] = vd return edlib.Efallthrough -editor.call("global-set-command", "attach-markdown-present", markdown_attach) -editor.call("global-set-command", "attach-present", present_attach) -editor.call("global-set-command", "doc:appeared-present", markdown_appeared) +edlib.editor.call("global-set-command", "attach-markdown-present", markdown_attach) +edlib.editor.call("global-set-command", "attach-present", present_attach) +edlib.editor.call("global-set-command", "doc:appeared-present", markdown_appeared)