[comp.emacs] I have a question, and Re: hooks in Gnumacs

gaynor@topaz.rutgers.edu (Silver) (09/21/87)

First, the question.  I wrote a fun little yatzee game in GNU Emacs
Lisp.  I would like to post it, but still leave the option open to FSF
to include it their distribution (under their license) if they want.
In fact, I would like to put it under a license similar to GNU's.  If
you know what kind of stuff I should put in the license to slap on it,
would you please mail me?  I'll summarize if there's sufficient
response.

Regarding hooks in Gnumacs, aglew@ccvaxa.UUCP writes:
> Instead of every package using a slightly different name for its pre
> and post hooks, have no hooks at all, but let the user be able to
> add them dynamically, in a standard way.

This is a reasonable idea.  Remember that this editor implements a
language especially well-suited to dynamically modifying functions.
It is trivial to add forms to be evaluated at the beginning and end of
functions.  Practical example:

;; Make fundamental-mode (post-)evaluate the hook
;; fundamental-mode-hook.
(fset 'fundamental-mode
      (append (symbol-function 'fundamental-mode)
	      '((run-hooks 'fundamental-mode-hook))))

Other stuff is not quite as trivial, but is still not overly
difficult.  Practical example:

;; Enclose the body of the function foo in a save-excursion, leaving a
;; leading call to interactive in place.
(let (pre-body ;; The list BEFORE the body to be enclosed, which is
 	       ;; later rplacd'ed.
      (fn-def (symbol-function 'foo)))
  (setq pre-body (cdr fn-def))
  ;; If the first thing in the body is (interactive ...), skip over
  ;; it.
  (if (cdr prebody)
      (if (listp (car (cdr pre-body)))
	  (if (equal (car (car (cdr pre-body))) 'interactive)
	      (setq pre-body (cdr pre-body)))))
  ;; The replacement.
  (rplacd pre-body
	  (cons (cons 'save-excursion (cdr pre-body))
		nil)))

Enjoy,
Silver.

LOOKING FOR ENTRY-LEVELISH C/LISP PROGRAMMING, SOFTWARE ENGINEERING
Andy Gaynor   201-545-0458   81 Hassart St, New Brunswick, NJ 08901
  gaynor@topaz.rutgers.edu   ...!rutgers!topaz.rutgers.edu!gaynor
     "There is no Editor but Emacs, and Lisp is its Prophet."