Could Emacs be rewritten in Python?
Martin v. Löwis
martin at v.loewis.de
Sun Apr 6 13:40:51 EDT 2003
pobrien at orbtech.com (Patrick K. O'Brien) writes:
> Are there translators out there? I looked and couldn't find any.
Parsing S-Expressions is fairly trivial - they are designed to be
readily parsable. For a full translator, you need to define the
language mapping first, i.e. how do you want to represent atoms,
function names, etc.
> That's pretty much the approach I planned to take, after I got some of
> the more basic pieces in place. For example, file handling. If you
> try to save a file and another process has modified it, Emacs warns
> you. Where is that kind of code kept in Emacs? Is it in elisp, or
> part of the core Emacs written in C?
It very much depends on the precise problem you are looking at: Some
is elisp, some is C, and the boundaries are weak - just as they are in
Python.
For this specific problem, if you do C-x C-s, it invokes
save-buffer. C-h f tells you that this is in "files". Looking at the
code in files.el reveals that it eventually calls basic-save-buffer;
you could trace this this further down.
Alternatively, you look at the error message "has changed since
visited or saved". You grep through the emacs source, and find
that it is in files.el, in basic-save-buffer:
(or (verify-visited-file-modtime (current-buffer))
(not (file-exists-p buffer-file-name))
(yes-or-no-p
(format "%s has changed since visited or saved. Save anyway? "
(file-name-nondirectory buffer-file-name)))
(error "Save not confirmed"))
So the message certainly comes from elisp; the test is
verify-visited-file-modtime. C-h f shows it is a builtin function;
a grep reveals it is in fileio.c, which (essentially) reads
if (stat (SDATA (filename), &st) < 0)
{
/* If the file doesn't exist now and didn't exist before,
we say that it isn't modified, provided the error is a tame one. */
if (errno == ENOENT || errno == EACCES || errno == ENOTDIR)
st.st_mtime = -1;
else
st.st_mtime = 0;
}
if (st.st_mtime == b->modtime
/* If both are positive, accept them if they are off by one second. */
|| (st.st_mtime > 0 && b->modtime > 0
&& (st.st_mtime == b->modtime + 1
|| st.st_mtime == b->modtime - 1)))
return Qt;
return Qnil;
This is, of course, all off-topic for comp.lang.python.
> Is there a document anywhere that gives an overview of the design of
> Emacs that would answer these kinds of questions?
No, because the decision to implement something in C or elisp is not a
design decision - you can elevate functions from C to lisp
(introducing deeper primitives) or move functions form lisp to C at
will, without changing the design.
Regards,
Martin
More information about the Python-list
mailing list