help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is Emacs becoming Word?


From: Greg Novak
Subject: Re: Is Emacs becoming Word?
Date: Thu, 31 Mar 2005 12:52:08 -0800
User-agent: Mutt/1.4.1i

* Thomas A. Horsley <tom.horsley@att.net> wrote:
>>I think it probably wouldn't be too ungodly hard to write a
>>`what-just-happened' function (but I'm not sure).  
> I don't know about that. Certainly the lisp interpreter should know
> what function slots it has been executing through. Seems like it would
> be primarily a job of adding a gazillion entry "recently called functions"
> array together with some AI for filtering which functions in the
> array are important to describe "what just happened" 
> ...

Hmm.  I was thinking of something considerably simpler.  It would be
incumbent upon the programmer to identify things that the user might
find confusing.  At the end of this mail I've included very simple
code that defines a new major mode to do what I was imagining. 

I'm relatively new to elisp, so don't laugh too hard.  I'd appreciate
comments on the code if anyone has them to offer, but it'd probably be
best to send them directly to me rather than to the whole list.

I also took a shot at implementing the "last-function" command by
advising eval, apply, and/or funcall.  Advising funcall didn't seem to
do much that was interesting.  Advising eval worked, but I only got
the top level form.  Ie, giving eval before-advice to print its
arguments to a buffer before evaluating them, then evaluating 
(+ (* 1 2) (* 3 4))
Results in the buffer containing this:
 (+ (* 1 2) (* 3 4))
not this (as I might have hoped):
 (+ (* 1 2) (* 3 4))
 (* 1 2)
 (* 3 4)

Looking through the code for eval, it looks like it calls eval
recursively on each argument, so I'd expect the latter behavior. 
However, it doesn't seem to be getting the advice on the subsequent
calls.

Finally, it seems that ad-activate calls apply, so trying to advise
apply doesn't work so well... the max recursion depth is exceeded, in
spite of fiddling with flags to try to get it to stop the recursion.

Also, should this discussion be moved to emacs-devel at this point?
I've left it here to preserve continuity in the mailing list archive.

Greg

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; The "what just happened" stuff:
(defvar just-happened nil) ; list of recent interesting functions

(defun docstring (f)
  "Return the docstring of a function"
  (caddr (symbol-function f)))

(defun this-just-happened (f)
  "Record an interesting event by consing the function's docstring
  into just-happened"
  (setq just-happened (cons (docstring f) just-happened)))

(defun what-just-happened ()
  "Pop a buffer with a list of recent intersting events along with 
   information about how to turn the features off, etc.  The list is
   ordered so that the most recent event is last."
  (interactive)
  (pop-to-buffer "*What Just Happened*")
  (erase-buffer)
  (mapc (lambda (x) (insert (concat "*** " x "\n"))) 
        (reverse just-happened)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; An odd editing mode that substitutes "star" for "*" and 
; "dollar" for "$".

; if non-nil, substitute "star" for "*"
(defvar write-out-mode-star-substitution t)
; if non-nil, substitute "dollar" for "$"
(defvar write-out-mode-dollar-substitution t)

(define-derived-mode odd-mode
  text-mode "odd"
  "Major mode for odd editing.
          \\{odd-mode-map}"
  (setq case-fold-search nil))

(defun write-out-star ()
  "Substitute \"star\" for \"*\".  To turn this behavior off, put 
  (setq write-out-mode-star-substitution nil) in your .emacs file"
  (interactive)
  (if (not write-out-mode-star-substitution)
      (insert "*")
    (this-just-happened 'write-out-star)
    (insert "star")))

(defun write-out-dollar ()
  "Substitute \"dollar\" for \"$\".  To turn this behavior off, put 
  (setq write-out-mode-dollar-substitution nil) in your .emacs file"
  (interactive)
  (if (not write-out-mode-dollar-substitution)
      (insert "*")
    (this-just-happened 'write-out-dollar)
    (insert "dollar")))

(define-key odd-mode-map "*" 'write-out-star)
(define-key odd-mode-map "$" 'write-out-dollar)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]