* Function Defintion
@ 2003-02-28 19:47 Artist
2003-02-28 20:38 ` Barry Margolin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Artist @ 2003-02-28 19:47 UTC (permalink / raw)
Hi, How I can get the function definition via lisp code?
Lambda expression may be ok.
I know how to see it via find-function and I don't want to use macro.
Something like
(get-definition 'mark-whole-buffer)
should return
(defun mark-whole-buffer ()
"Put point at beginning and mark at end of buffer.
You probably should not use this function in Lisp programs;
it is usually a mistake for a Lisp function to use any subroutine
that uses or sets the mark."
(interactive)
(push-mark (point))
(push-mark (point-max) nil t)
(goto-char (point-min)))
Thanks You
[aritst]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function Defintion
2003-02-28 19:47 Function Defintion Artist
@ 2003-02-28 20:38 ` Barry Margolin
2003-02-28 20:38 ` Stefan Monnier
2003-03-01 4:15 ` D. Goel
2 siblings, 0 replies; 4+ messages in thread
From: Barry Margolin @ 2003-02-28 20:38 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1245 bytes --]
In article <de3ad953.0302281147.38ae9ded@posting.google.com>,
Artist <googleartist@yahoo.com> wrote:
>Hi, How I can get the function definition via lisp code?
> Lambda expression may be ok.
>
>I know how to see it via find-function and I don't want to use macro.
>
>Something like
>(get-definition 'mark-whole-buffer)
(symbol-function 'mark-whole-buffer)
>should return
>
>(defun mark-whole-buffer ()
> "Put point at beginning and mark at end of buffer.
>You probably should not use this function in Lisp programs;
>it is usually a mistake for a Lisp function to use any subroutine
>that uses or sets the mark."
> (interactive)
> (push-mark (point))
> (push-mark (point-max) nil t)
> (goto-char (point-min)))
You'll only get the lambda expression if the function is interpreted.
Since mark-whole-buffer is byte-compiled, you get a vector containing the
compiled version:
#[nil "À`!ÀdÁÂ#eb" [push-mark nil t] 4 1035873 nil]
If you want to see the source code, use M-. to find the source file.
--
Barry Margolin, barry.margolin@level3.com
Genuity Managed Services, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function Defintion
2003-02-28 19:47 Function Defintion Artist
2003-02-28 20:38 ` Barry Margolin
@ 2003-02-28 20:38 ` Stefan Monnier
2003-03-01 4:15 ` D. Goel
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2003-02-28 20:38 UTC (permalink / raw)
>>>>> "Artist" == Artist <googleartist@yahoo.com> writes:
> I know how to see it via find-function and I don't want to use macro.
I think find-function is the best way, despite what you seem to think.
The only other approach I can think of is `symbol-function', but
you won't necessarily get a readable result since it might have been
compiled.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Function Defintion
2003-02-28 19:47 Function Defintion Artist
2003-02-28 20:38 ` Barry Margolin
2003-02-28 20:38 ` Stefan Monnier
@ 2003-03-01 4:15 ` D. Goel
2 siblings, 0 replies; 4+ messages in thread
From: D. Goel @ 2003-03-01 4:15 UTC (permalink / raw)
> I know how to see it via find-function and I don't want to use macro.
find-function is not a macro. it is a function that takes you to the
code definition .
you indicate that you want your find-function to just return you the
definition as a string, a quick hack would be to just copy the string
from the found function. here's a hack i use for a similar need:
the hack below strips out the docs of the function found before
returning it as a string.. you can comment that out.. :)
(defun erbc-find-function-internal (&optional function nolimitp &rest nada)
(unless function
(error
"Syntax: (ff 'fucntion)"))
(if (stringp function) (setq function (read function)))
(cond
(let* ((fstrbare
(save-excursion
;; This has the problem that it is interactive.. asks to
;; reread file if has changed etc.
;;(find-function function)
(find-function-do-it function nil 'set-buffer)
(buffer-substring (point)
(save-excursion
(forward-sexp 1)
(point)))))
(fstr (erbutils-function-minus-doc fstrbare)))
(if (equal nolimitp 'nolimit)
fstr
(concat (format "%s characters.." (length
fstr))
fstr))))
(t "\n")))
(defun erbutils-function-minus-doc (fstr &rest ignore)
"fstr is the string containing the function"
(let* ((fdoc (if (stringp fstr) fstr (format "%s" fstr)))
newdoc)
(setq newdoc
(with-temp-buffer
(insert fdoc)
(goto-char (point-min))
(search-forward "(" nil t)
(forward-sexp 4)
(if (stringp (sexp-at-point))
;; this sets mark.. bad programming, i know..
(backward-kill-sexp 1))
(buffer-string)))
(erbutils-single-lines newdoc)))
(defun erbutils-single-lines (str)
"Eliminates all \n or lines comprising entirely of whitespace"
(mapconcat
'identity
(delete-if
(lambda (str)
(string-match "^[ \t]*$" str))
(split-string str
"\n"))
"\n"))
hth
DG http://gnufans.net/
--
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-03-01 4:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-28 19:47 Function Defintion Artist
2003-02-28 20:38 ` Barry Margolin
2003-02-28 20:38 ` Stefan Monnier
2003-03-01 4:15 ` D. Goel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).