Adding C-code plug-ins to Emacs?

Adding C-code plug-ins to Emacs?

Post by Bruno Danie » Mon, 21 Apr 1997 04:00:00



Hi

can I add new Emacs Primitives in C code to Emacs without recompiling
the whole Emacs program? - Probably not, because this would necessitate
dynamic linking and extension of the Emacs code, which is very easy in
Java, but difficult in C.

Maybe some time, Java will be fast enough so that we can reimplement
Emacs in Java. We would also have platform-independent threads then,
which would solve many of the problems of Emacs.  

Regards
  Bruno

------------------------------------------------------------------------

                   http://www.uni-karlsruhe.de/~ub68/

 
 
 

Adding C-code plug-ins to Emacs?

Post by Hrvoje Niksi » Mon, 21 Apr 1997 04:00:00



> can I add new Emacs Primitives in C code to Emacs without recompiling
> the whole Emacs program?

Not yet, but such an addition to Emacs is not inconceivable.

Quote:> Maybe some time, Java will be fast enough so that we can reimplement
> Emacs in Java. We would also have platform-independent threads then,
> which would solve many of the problems of Emacs.

And we would lose Lisp, or have to reimplement it in Java.  Which is
bad bad bad.  A much better strategy is to take an existing Lisp (or
Lispoid) implementation, and rewrite parts of Emacs in it.

Then we'd also have platform-independent threads, as well as a host of
other things provided by the Lisp systems.

--

--------------------------------+--------------------------------
The end of the world is coming...  SAVE YOUR BUFFERS!

 
 
 

Adding C-code plug-ins to Emacs?

Post by Erik Naggu » Mon, 21 Apr 1997 04:00:00


* Bruno Daniel
| can I add new Emacs Primitives in C code to Emacs without recompiling the
| whole Emacs program? - Probably not, because this would necessitate
| dynamic linking and extension of the Emacs code, which is very easy in
| Java, but difficult in C.

it is very easy in Java, but it is very easy in almost all Lisps, too.  we
have to understand that Emacs is a rudimentary Lisp in very many respects.
C is the implementation language for lots of good software, _not_ the
application language (why C is viewed as anything _but_ a low-level
implementation language beats me), and supporting dynamic linking is a
question of doing it right _once_ and then using the appropriate interface.
this is what Java has done.  what do you guys think Java implementations
are written in?

however, there is a problem: Emacs' C internals exhibit a lot of manually
maintained linkage, and this will need some extra care.  perhaps we should
even automate it better.

| Maybe some time, Java will be fast enough so that we can reimplement
| Emacs in Java.  We would also have platform-independent threads then,
| which would solve many of the problems of Emacs.

frankly, I don't understand this fascination with Java.  the language is
not particularly good, the implementations suck, and the hype is bordering
on war-time propaganda in intensity and attacks on the opposition.

Java has borrowed all of its _technical_ "winning points" from Lisps at
least a decade old.  why is it that this immature language that doesn't
even have reasonable stability or decent compilers is so popular?

and why, above all, do the Java cult members want to rewrite everything
into Java?  don't they realize that software is more than the language it
is written in?  (perhaps they don't, and perhaps that explains the move to
new languages?)  don't they understand that such a rewrite process would
take en _enormous_ effort to become as stable as what they rewrite?

the only interesting aspect of Java is its ability to*up peoples'
minds.  next, they'll convince the Java cult members that Hale Boop carries
Java 2.0 with it, and that mass suicide will reveal its glory to them.

#\Erik
--
I'm no longer young enough to know everything.

 
 
 

Adding C-code plug-ins to Emacs?

Post by Kai Grossjohan » Tue, 22 Apr 1997 04:00:00


Quote:>>>>> Bruno Daniel writes:

  Bruno> can I add new Emacs Primitives in C code to Emacs without
  Bruno> recompiling the whole Emacs program?

What is a "primitive"?  You can add everything you like to Emacs in
Lisp without having to recompile anything.  Which is much better than
doing it in C (or Java).

kai
--
because I couldn't think of a good beginning.

 
 
 

Adding C-code plug-ins to Emacs?

Post by Tom Legrad » Tue, 22 Apr 1997 04:00:00


  Maybe some time, Java will be fast enough so that we can
  reimplement
  Emacs in Java. We would also have platform-independent threads
  then,
  which would solve many of the problems of Emacs.

A nice thought, but Java is already splitting into platform-dependent
aspects.
The Windows people want PC things, the Mac people want Mac things, and
pretty soon Java is going to wind up being simply a framework for gluing
together a whole bunch of native code. Of course, people who care about
platform independence can use the JVM for that effect. Corel Office
Suite for Java seems to be doing that, but then, what does JVM have to
do with Java? Not much.

Tom Legrady

 
 
 

Adding C-code plug-ins to Emacs?

Post by Hrvoje Niksi » Tue, 22 Apr 1997 04:00:00



> >>>>> Bruno Daniel writes:

>   Bruno> can I add new Emacs Primitives in C code to Emacs without
>   Bruno> recompiling the whole Emacs program?

> What is a "primitive"?  You can add everything you like to Emacs in
> Lisp without having to recompile anything.

A "primitive" is a popular name for a routine that must be written in
C, because of a number of possible reasons.  Either it must access the
system resources that are accessible only through C on a given system,
or it must run fast enough to make the interpreter overhead
unacceptable, or it must extend the existing Emacs internals, which
are implemented in C themselves.  Three examples of routines that are
(and should be) written in C follow:

1) load-average, current-time, ...

The `load-average' function calls the `getloadavg' C function.  If
this functionality didn't exist, on most systems it would be
impossible to write a Lisp function to simulate `load-average' fully.

2) mapcar, format, ...

A function like `mapcar' could be well written in Lisp (it's trivial
to loop through a list and apply the function to CARs), but it is
written in C because of speed.  `mapcar' is considered a low-level
function, and it's good to have it in C, without the interpreter
overhead.

3) eq, car, ...

These functions must be written in C, because they are used to
implement the basic functionality of the Lisp interpreter, which is
itself written in C.

So, you cannot add "everything you like" to Emacs in Lisp.  There are
at least three cases when you must extend Emacs C base in order to
provide new Lisp functions, or improve the existing ones to get more
functionality.

For cases #1 and #2, dynamical loading might improve the usability of
Emacs significantly.  It's another question whether such a direction
is a good way to go.  Emacs developers seem to have chosen a different
(and IMHO better, in the long term) path.

P.S.
I *hate* the word "plug-in". :-)

--

--------------------------------+--------------------------------
You'll notice that perl is not itself written in Perl.
                                                 -- The Perl FAQ

 
 
 

Adding C-code plug-ins to Emacs?

Post by Hrvoje Niksi » Tue, 22 Apr 1997 04:00:00



> >>>>> Bruno Daniel writes:

>   Bruno> can I add new Emacs Primitives in C code to Emacs without
>   Bruno> recompiling the whole Emacs program?

> What is a "primitive"?  You can add everything you like to Emacs in
> Lisp without having to recompile anything.

A "primitive" is a popular name for a routine that must be written in
C, because of a number of possible reasons.  Either it must access the
system resources that are accessible only through C on a given OS, or
it must run fast enough to make the interpreter overhead unacceptable,
or it must extend the existing Emacs internals, which are implemented
in C themselves.  Three examples of routines that are (and should be)
written in C follow:

1) load-average, current-time, ...

The `load-average' function calls the `getloadavg' C function.  If
this functionality didn't exist, on most systems it would be
impossible to write a Lisp function to simulate `load-average' fully.

2) mapcar, format, ...

A function like `mapcar' could be well written in Lisp (it's trivial
to loop through a list and apply the function to CARs), but it is
written in C because of speed.  `mapcar' is considered a low-level
function, and it's good to have it in C, without the interpreter
overhead.

3) eq, car, ...

These functions must be written in C, because they are used to
implement the basic functionality of the Lisp interpreter, which is
itself written in C.

So, you cannot add "everything you like" to Emacs in Lisp.  There are
at least three cases when you must extend Emacs C base in order to
provide new Lisp functions, or improve the existing ones to get more
functionality.

For cases #1 and #2, dynamical loading might improve the usability of
Emacs significantly.  It's another question whether such a direction
is a good way to go.  Emacs developers seem to have chosen a different
(and IMHO better, in the long term) path.

P.S.
I *hate* the word "plug-in". :-)

--

--------------------------------+--------------------------------
You'll notice that perl is not itself written in Perl.
                                                 -- The Perl FAQ

 
 
 

Adding C-code plug-ins to Emacs?

Post by Jimser » Tue, 22 Apr 1997 04:00:00


I say I think therfore I am
To self recurse avoids a jam.
To say with a Lisp tis hard not to C
this discussion going to infinity!

(Cyrano d') Jimserac!

James (apologies to Rostand) Pannozzi

 
 
 

Adding C-code plug-ins to Emacs?

Post by YP » Tue, 22 Apr 1997 04:00:00



> 1) load-average, current-time, ...

> The `load-average' function calls the `getloadavg' C function.  If
> this functionality didn't exist, on most systems it would be
> impossible to write a Lisp function to simulate `load-average' fully.

Just to add a minor point: on my system 'load-average' is not
implemented, but here is how I can get the loads:

(defun db-get-load ()
  "Get the string of loads for the current host."
(let* ((b    (generate-new-buffer "*uptime*"))
       beg end res)
  (save-excursion
    (set-buffer b)
    (call-process "uptime" nil b nil)
    (goto-char (point-max))
    (skip-chars-backward "\n")
    (setq end (point))
    (skip-chars-backward "^:") (skip-chars-forward " \t")
    (setq beg (point))
    (setq res (buffer-substring beg end))
    (kill-buffer b))
  res))

Since I call it every two minutes it doesn't consume too much time.

 - YP

 
 
 

Adding C-code plug-ins to Emacs?

Post by YP » Tue, 22 Apr 1997 04:00:00



> What system do you use?  I have seen GNU Emacs print an (IMHO
> erroneous) message "load-average not implemented" when a non-root
> Solaris user is not allowed to run a successful `getloadavg'.

Well, maybe that's my case, because I am using Solaris. Unfortunately
I don't seem to be able to check the privileges, because I don't know
where to look for this function. Is there a "standard" directory where
these compiled functions are supposed to reside (apart from
emacs/bin/)?
 
 
 

Adding C-code plug-ins to Emacs?

Post by Hrvoje Niksi » Wed, 23 Apr 1997 04:00:00



> Just to add a minor point: on my system 'load-average' is not
> implemented,

[...]

What system do you use?  I have seen GNU Emacs print an (IMHO
erroneous) message "load-average not implemented" when a non-root
Solaris user is not allowed to run a successful `getloadavg'.

--

--------------------------------+--------------------------------
"Psychos _do not_ explode when sunlight hits them."

 
 
 

Adding C-code plug-ins to Emacs?

Post by Hrvoje Niksi » Wed, 23 Apr 1997 04:00:00



> Well, maybe that's my case, because I am using Solaris.

It certainly is.  However, you are not out of luck, as it happens to
be possible to implement `getloadavg' for non-root users (no, you
needn't be sgid kmem either) on Solaris, through the kstat() call.
XEmacs 20 uses that facility to obtain the average load on Solaris,
and I've seen other GNU utilities, like GNU libit implement it in a
yet cleaner way.

I think it would be wise for Emacs developers to copy getloadavg.c
from GNU libit (which is still in alpha, if I remember correctly), or
another source that implements the function correctly on Solaris.
Failing that, at least the error message should be made more precise.

Quote:> Unfortunately I don't seem to be able to check the privileges,
> because I don't know where to look for this function. Is there a
> "standard" directory where these compiled functions are supposed to
> reside (apart from emacs/bin/)?

What do you mean by "compiled functions"?  The builtin functions are a
part of the Emacs executable, and byte-compiled Lisp functions are
normally stored in .elc files.

--

--------------------------------+--------------------------------
"Psychos _do not_ explode when sunlight hits them."

 
 
 

Adding C-code plug-ins to Emacs?

Post by Erik Naggu » Wed, 23 Apr 1997 04:00:00


* Bruno Daniel
| By the way, it was the father of Emacs - James Gosling - who invented the
| Java programming language!

James Gosling added Lisp as the extension language to Emacs.  that was his
contribution.  he did not invent Emacs.  his version was called "Gosling
Emacs" for a reason.

it's funny how lesser people so often twist history to suit their wishes
instead of respect history and make better, yet harder, wishes.

#\Erik
--
Bastard Sex Therapist from Hell: "Read the F*cking Manual!"

 
 
 

Adding C-code plug-ins to Emacs?

Post by Kyle Jon » Wed, 23 Apr 1997 04:00:00



 > * Bruno Daniel
 > | By the way, it was the father of Emacs - James Gosling - who invented the
 > | Java programming language!
 >
 > James Gosling added Lisp as the extension language to Emacs.  that was his
 > contribution.  he did not invent Emacs.  his version was called "Gosling
 > Emacs" for a reason.
 >
 > it's funny how lesser people so often twist history to suit their wishes
 > instead of respect history and make better, yet harder, wishes.

aw, for God's sake!  You're jumping to quite a conclusion here.
Maybe Gosmacs was the first Emacs that Bruno used, and he was
impressed with it and made an honest mistake!

 
 
 

Adding C-code plug-ins to Emacs?

Post by Bruno Danie » Thu, 24 Apr 1997 04:00:00


Hi


Quote:> Maybe some time, Java will be fast enough so that we can reimplement
> Emacs in Java. We would also have platform-independent threads then,
> which would solve many of the problems of Emacs.  

I don't want to replace Lisp by Java (I'm not THAT heretical :))),
but wouldn't it be nice to implement the Emacs Primitives in Java and
offer them in a kind of Java class library? This library could then
be dynamically linked into self-written Java-programs.

Cheers
  Bruno

By the way, it was the father of Emacs - James Gosling - who invented the
Java programming language!

------------------------------------------------------------------------

                   http://www.uni-karlsruhe.de/~ub68/