[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

help writing a slime contrib

Jim Newton

12/2/2015 9:54:00 AM

I've never written a slime contrib before. Can someone help me get started?

I already have a function written in Common Lisp.

From emacs, I'd like to do the following:

M-x my-command
1) emacs should prompt me for a lisp symbol, defaulting to the symbol at the point.
2) Call the lisp function with that symbol and a temporary file name. (which CL is allowed to create and write to)
3) If the lisp function returns true, then call the emacs-lisp function find-file with that file name
as argument.
4) Otherwise, if the CL function fails, I'd like a way to display a description to an emacs buffer.
I'm happy to print to stdout, or raise a condition, or return a structure, or print to a given stream
whatever the normal way of doing this is.

Also my CL code depends on :c2mop. Is that a problem?

Thanks if anyone can help me out.
5 Answers

Pascal J. Bourguignon

12/2/2015 3:35:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

> I've never written a slime contrib before. Can someone help me get started?
>
> I already have a function written in Common Lisp.
>
> From emacs, I'd like to do the following:
>
> M-x my-command
> 1) emacs should prompt me for a lisp symbol, defaulting to the symbol at the point.
> 2) Call the lisp function with that symbol and a temporary file name. (which CL is allowed to create and write to)
> 3) If the lisp function returns true, then call the emacs-lisp function find-file with that file name
> as argument.
> 4) Otherwise, if the CL function fails, I'd like a way to display a description to an emacs buffer.
> I'm happy to print to stdout, or raise a condition, or return a structure, or print to a given stream
> whatever the normal way of doing this is.
>
> Also my CL code depends on :c2mop. Is that a problem?
>
> Thanks if anyone can help me out.

The basic functionality would be given by this CL function:

(defun cl-user::call-with-file (function pathname)
(with-input-from-string (*standard-input* "")
(with-open-file (*standard-output* pathname
:direction :output
:if-does-not-exist :create
:if-exists :supersede)
(handler-case
(let ((*error-output* *standard-output*)
(*trace-output* *standard-output*)
(*terminal-io* (make-two-way-stream
*standard-input*
*standard-output*))
(*query-io* *terminal-io*)
(*debug-io* *terminal-io*))
(funcall function))
(error (err)
(format t "~2%ERROR: ~A~2%" err)
#+ccl (format t "~&~80,,,'-<~>~&~{~A~%~}~80,,,'-<~>~&"
(ccl::backtrace-as-list)))))))


and this emacs lisp command:

(defun call-lisp-function-with-temp-file (fname)
(interactive "SCL function to call: ")
(let ((temp-file (make-temp-file (format "/tmp/out-%d-%s-" (user-uid) fname)
nil ".txt")))
(slime-interactive-eval (format "(cl-user::call-with-file '%s %S)"
fname temp-file))
(find-file temp-file)))


I'll leave it up to you to improve the user interface (take the default
symbol from the point, complete with all the fbound symbols in the
image, deal with packages, and integrate the whole as a slime-contrib.


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Jim Newton

12/2/2015 3:58:00 PM

0


>
> (defun call-lisp-function-with-temp-file (fname)
> (interactive "SCL function to call: ")
> (let ((temp-file (make-temp-file (format "/tmp/out-%d-%s-" (user-uid) fname)
> nil ".txt")))
> (slime-interactive-eval (format "(cl-user::call-with-file '%s %S)"
> fname temp-file))
> (find-file temp-file)))
>
>
> I'll leave it up to you to improve the user interface (take the default
> symbol from the point, complete with all the fbound symbols in the
> image, deal with packages, and integrate the whole as a slime-contrib.
>

Thanks, but not exactly what I need. But perhaps it contains the thins I need.
I don't want to call the function at the point. Rather I want to call a particular
function, passing the symbol named at the point to that function, along with a tmp file name.

Here is what I've tried so far.

(defun class-graph (class-name)
(interactive "P")
(let ((class-name (or class-name
(slime-symbol-at-point)))
(file-name "/tmp/graph.png"))
(when (slime-eval `(class-graph:class-graph-for-slime ',class-name ,file-name))
(find-file file-name))))

But this has a problem I don't understand:
Sometimes class-name is a string containing the printed rep of a fully qualified symbol such as "xyzzy::name", and sometimes it is simply the symbol-name, without the package. "name"

How can I get the name of the symbol, with the package prefix.

Perhaps your suggestion of using slime-interactive-eval is the key to solving this problem?

Jim Newton

12/2/2015 4:24:00 PM

0


>
> (defun call-lisp-function-with-temp-file (fname)
> (interactive "SCL function to call: ")
> (let ((temp-file (make-temp-file (format "/tmp/out-%d-%s-" (user-uid) fname)
> nil ".txt")))
> (slime-interactive-eval (format "(cl-user::call-with-file '%s %S)"
> fname temp-file))
> (find-file temp-file)))
>

Hi Pascal, does slime-interactive-eval return before the lisp function finishes? I.e., is it perhaps evaluating in a different thread or something strange?

The strangness I'm seeing is that when file-file is called the file is either empty or does not exist, but when I check It is indeed populated.

Pascal J. Bourguignon

12/2/2015 4:33:00 PM

0

Jim Newton <jimka.issy@gmail.com> writes:

>>
>> (defun call-lisp-function-with-temp-file (fname)
>> (interactive "SCL function to call: ")
>> (let ((temp-file (make-temp-file (format "/tmp/out-%d-%s-" (user-uid) fname)
>> nil ".txt")))
>> (slime-interactive-eval (format "(cl-user::call-with-file '%s %S)"
>> fname temp-file))
>> (find-file temp-file)))
>>
>
> Hi Pascal, does slime-interactive-eval return before the lisp function
> finishes? I.e., is it perhaps evaluating in a different thread or
> something strange?
>
> The strangness I'm seeing is that when file-file is called the file is
> either empty or does not exist, but when I check It is indeed
> populated.

It's possible. There are other slime-eval* functions you could see if
one does what you want.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Jim Newton

12/2/2015 4:39:00 PM

0

Yes it seems that (slime-interactive-eval "(sleep 10)") returns immediately even though
lisp is still evaluating (sleep 10).

Do you think there is a way around this?

> Hi Pascal, does slime-interactive-eval return before the lisp function finishes? I.e., is it perhaps evaluating in a different thread or something strange?
>
> The strangness I'm seeing is that when file-file is called the file is either empty or does not exist, but when I check It is indeed populated.