Emacs is *already* scriptable with python

23 views
Skip to first unread message

Edward K. Ream

unread,
Aug 3, 2019, 9:45:23 AM8/3/19
to leo-editor
In another thread I said, "it doesn't seem likely that emacs will ever be scriptable with python.  Unless some hero steps up Leo in emacs will remain a tantalizing possibility, just out of reach."

Happily I was forgetting pymacs and Leo's bridge.  In effect, Leo's support for pymacs already makes emacs scriptable using python!  To repeat the example:

; Step 1: load leoPymacs if it has not already been loaded.
(setq reload nil)
(if (or reload (not (boundp 'leoPymacs)))
    (setq leoPymacs (pymacs-load "leoPymacs" "leo-"))
    (message "leoPymacs already loaded")
)

; Step 2: compute the path to leo/test/ut.leo using a Leo script.
(setq script
    "g.app.scriptResult = g.os_path_abspath(
        g.os_path_join(g.app.loadDir,'..','test','ut.leo'))"
)
(setq fileName (leo-run-script nil script))

; Step 3: execute a script in ut.leo.
(setq c (leo-open fileName))
(setq script "print 'c',c.shortFileName() ,'current:',c.p.h")
(leo-run-script c script)

Folks, this is a big deal.  An emacs champion could easily:

1. Add any desired (python) functions to leoPymacs.py.
2. Add any desired (elisp) hooks to emacs, especially org mode.

The way appears open to embed Leonine support into emacs.

Edward
Reply all
Reply to author
Forward
0 new messages