Log in

lively.el 0.1 - Luke's Weblog [entries|archive|friends|userinfo]
Luke Gorrie

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

lively.el 0.1 [Apr. 20th, 2009|11:50 pm]
Luke Gorrie
Long time no Emacs hack!
;;; lively.el version 0.1 --- interactively updating text
;;; Copyright 2009 Luke Gorrie <luke@bup.co.nz>
;;; Go to the end of any of the following lines and run `M-x lively'
;;;   Current time:      (current-time-string)
;;;   Last command:      last-command
;;;   Open buffers:      (length (buffer-list))
;;;   Unix processes:    (lively-shell-command "ps -a | wc -l")
;;; then the code will be replaced by its formatted result -- and
;;; periodically updated. You can create little dashboards.
;;; Use `M-x lively-stop' to restore order.
;;; Based on the Squeak hack by Scott Wallace.

(require 'cl)

(defvar lively-overlays nil "List of all overlays representing lively text.")
(defvar lively-timer    nil "Idle timer for updating lively text.")
(defvar lively-interval 0.25 "Idle time before lively text update in seconds.")

(defun lively ()
  "Make the expression before point lively."
  (lively-region (save-excursion (backward-sexp) (point)) (point)))

(defun lively-region (start end)
  "Make the region lively."
  (interactive "r")
  (when (null lively-timer)
  (push (make-overlay start end) lively-overlays))

(defun lively-update ()
  "Update the display of all visible lively text."
  (dolist (o lively-overlays)
    (when (get-buffer-window (overlay-buffer o))
      (condition-case err
          (lively-update-overlay o)
        (error (message "Error in lively expression: %S" err)
               (lively-delete-overlay o))))))

(defun lively-delete-overlay (o)
  (delete-overlay o)
  (setq lively-overlays (remove o lively-overlays)))

(defun lively-update-overlay (o)
  "Evaluate the lively code for O and update its display text."
  (with-current-buffer (overlay-buffer o)
    (let ((expr (buffer-substring (overlay-start o) (overlay-end o))))
      (overlay-put o 'display (format "%s" (eval (read expr)))))))

(defun lively-init-timer ()
  "Setup background timer to update lively text."
  (setq lively-timer (run-with-timer 0 lively-interval 'lively-update)))

(defun lively-stop ()
  "Remove all lively regions in Emacs."
  (when lively-timer (cancel-timer lively-timer))
  (setq lively-timer nil)
  (mapc 'delete-overlay lively-overlays)
  (setq lively-overlays nil))

;;; Nice to have:

(defun lively-shell-command (command)
  "Execute COMMAND and return the output, sans trailing newline."
  (let ((result (shell-command-to-string command)))
    (substring result 0 (1- (length result)))))

[User Picture]From: darius
2009-04-20 05:53 pm (UTC)

I just tried a quick hack to have it leave the expressions editable. Since I don't really know Elisp I'm sure it could be lots better:

--- lively.el	2009-04-20 10:52:14.000000000 -0700
+++ livelier.el	2009-04-20 10:51:05.000000000 -0700
@@ -29,7 +29,7 @@
   (interactive "r")
   (when (null lively-timer)
-  (push (make-overlay start end) lively-overlays))
+  (push (make-overlay (- end 1) end) lively-overlays))
 (defun lively-update ()
   "Update the display of all visible lively text."
@@ -39,7 +39,8 @@
       (condition-case err
           (lively-update-overlay o)
         (error (message "Error in lively expression: %S" err)
-               (lively-delete-overlay o))))))
+               ;(lively-delete-overlay o))))))
+               )))))
 (defun lively-delete-overlay (o)
   (delete-overlay o)
@@ -48,8 +49,13 @@
 (defun lively-update-overlay (o)
   "Evaluate the lively code for O and update its display text."
   (with-current-buffer (overlay-buffer o)
-    (let ((expr (buffer-substring (overlay-start o) (overlay-end o))))
-      (overlay-put o 'display (format "%s" (eval (read expr)))))))
+    (save-excursion
+      (goto-char (overlay-end o))
+      (let ((expr (buffer-substring (progn (backward-sexp) (point))
+                                    (overlay-end o))))
+        (overlay-put o 'display (format "%s => %s" 
+                                        (buffer-substring (overlay-start o) (overlay-end o))
+                                        (eval (read expr))))))))
 (defun lively-init-timer ()
   "Setup background timer to update lively text."
(Reply) (Thread)
[User Picture]From: lukego
2009-04-20 08:34 pm (UTC)
Cool :-) now we just need to remember to keep an eye out for uses. :-)
(Reply) (Parent) (Thread)
From: node
2009-04-20 06:46 pm (UTC)
Searching for 'lively Scott Wallace' isn't working! Where can I find out more about his code?
(Reply) (Thread)
[User Picture]From: lukego
2009-04-20 08:28 pm (UTC)
I don't think it's published. It's a Squeak menu item "watch it". You select some Smalltalk code, say "watch it", and you get a GUI text widget (UpdatingStringMorph) that displays the result -- and gets updated every half a second. I'm sure he won't mind my sharing the code and he's scott.wallace@squeakland.org if this isn't enough.
'From Moshi of 3 March 2007 [latest update: #899] on 21 April 2009 at 6:26:46 am'!

!PluggableTextMorph methodsFor: '*green' stamp: 'sw 9/15/2004 23:11'!
	"Launch a tool that will reevaluate the string that comprises the
receiver's current selection every half second, and update a readout of
the result"

	| result watcher title readout |
	textMorph editor lineSelectAndEmptyCheck: [^ self].
	self handleEdit:
		[result _ textMorph editor compileSelectionAsBlock.
		((result isKindOf: FakeClassPool) or: [result == #failedDoit])
			ifTrue: [^ self flash]].
	title _ FillInTheBlank request: 'Title for this watcher: ' translated initialAnswer: textMorph editor selection.
	title isEmptyOrNil ifTrue: [^ self].
	title _ StringMorph contents: title.
	title color: Color blue.
	readout _ (UpdatingStringMorph on: result selector: #value)
			stepTime: 500;
			maximumWidth: nil;
			color: Color red;
			growable: true.
	watcher _ RectangleMorph new
		layoutPolicy: TableLayout new;
		layoutInset: 3;
		listDirection: #topToBottom;
		hResizing: #shrinkWrap;
		vResizing: #shrinkWrap;
		addMorphBack: title;
		addMorphBack: readout;
		color: (Color r: 0.677 g: 1.0 b: 0.806);
		borderColor: Color black;
	watcher openInHand! !

I only called it Lively to be confusing. :-)

Edited at 2009-04-20 08:29 pm (UTC)
(Reply) (Parent) (Thread)
From: (Anonymous)
2011-01-14 02:35 pm (UTC)

In stitches inflatable rental software?

During my most recent voyage toward Denver I stumbled over Leroy while on this lane. He told me, he was free to buy an original Software program here this Notebook Store close to the area. Ok, what a coincidence, I was just now in this area to proceed in the direction of this identical shop, but intended for a diverse cause. We decided that we depart together, therefore we both may present suggestion to one another.
Nowadays I once in a blue moon buy Software in a shop. I have a preference getting in our Internet since more or less at all times there appears to be the benefit to look into a presentation or even take a crack at it over a limited while or and limited features. I cannot perform that inside the superstore! My acquaintance opposed this, telling me he knows precisely what he desires. He experienced previously on his associates device as a consequence it is the greatest he really ever encountered up till now!
Here in USA nevertheless it is safe to buy [url=http://www.accuevent.com]inflatable rental software[/url] in the Web. It comes with the complete assistance you require. For sure it appears to be awsome, when you offer individuals enjoyment and this so much wanted relaxation, when you run a firm that certainly is interconnected to Parties, Events and Celebration, but even this sort of earning funds nevertheless needs to get money (smirk at this time). So keep it together and remain positive you have a decent program to deal with every one of your ventures and keeps you updated!
In my opinion, Millard Campos it is the most vital piece of gear you does have!
Until the end of time experience, what has been unsurpassed!!
(Reply) (Thread)
From: (Anonymous)
2011-01-26 07:03 am (UTC)

dog12 dog clothes wholesale gb

Family dogs inherited a complex dog clothes wholesale common hierarchy and behaviors from their wolf ancestors. Dogs are compact animals with a complex stiffen of behaviors cognate dog clothes wholesale to determining each dog's rank in the collective hierarchy, and they evidence several postures and other means of nonverbal communication that disclose their states of mind. dog clothes wholesale These elegant forms of societal cognition and communication may account for their trainability, playfulness, and faculty to disposed into possibly manlike households dog clothes wholesale and public situations, and these attributes sire earned dogs a unparalleled relationship with humans in spite of being potentially precarious apex predators. http://www.lovelonglong.com Would like to unsubscribe from this business, please send your URL to the E-mail: unsubscribe@1yingxiao.com to unsubscribe
(Reply) (Thread)