* function call location
@ 2018-05-22 7:25 akrl
2018-05-22 16:08 ` akrl
0 siblings, 1 reply; 3+ messages in thread
From: akrl @ 2018-05-22 7:25 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
How can I get the location of a function call in emacs lisp?
I would like to record (for a certain number of function I can
instrument) every function call and its location into the source.
Bests
akrl
--
akrl@sdf.org
SDF Public Access UNIX System - https://sdf.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: function call location
2018-05-22 7:25 function call location akrl
@ 2018-05-22 16:08 ` akrl
2018-05-22 21:28 ` akrl
0 siblings, 1 reply; 3+ messages in thread
From: akrl @ 2018-05-22 16:08 UTC (permalink / raw)
To: help-gnu-emacs
akrl <akrl@sdf.org> writes:
> Hi all,
> How can I get the location of a function call in emacs lisp?
> I would like to record (for a certain number of function I can
> instrument) every function call and its location into the source.
>
> Bests
>
> akrl
Hi,
just to be more clear, say we have:
(defun f1 ()
(message
(concat "f1 called at line " (int-to-string(line-number-at-pos)))))
(defun f2 ()
(message
(concat "f2 called at line "(int-to-string(line-number-at-pos)))))
(progn
(f1)
(f2))
As output I have:
f1 called at line 11
f2 called at line 11
But I would like to to get:
f1 called at line 10
f2 called at line 11
Bests
akrl
--
akrl@sdf.org
SDF Public Access UNIX System - https://sdf.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: function call location
2018-05-22 16:08 ` akrl
@ 2018-05-22 21:28 ` akrl
0 siblings, 0 replies; 3+ messages in thread
From: akrl @ 2018-05-22 21:28 UTC (permalink / raw)
To: help-gnu-emacs
For now the only solution I've found is to mimic how I would have done it in C.
So I instrument my functions like:
(defun f1 (line)
(message
(concat "f1 called at line " (int-to-string line))))
And I call it like:
(f1 __line__)
Instead of evaluating in the original buffer I use this expand-and-eval-buffer:
(defun expand-line-n ()
(progn
(goto-char 0)
(while (search-forward "__line__" nil t)
(replace-match (int-to-string (line-number-at-pos))))))
(defun expand-and-eval-buffer ()
(interactive)
(let ((orig-buffer (current-buffer)))
(with-temp-buffer
(insert-buffer-substring orig-buffer)
(expand-line-n)
(eval-buffer))))
I'm wondering if there's a better way in order to the preprocessor approach.
Bests
akrl
--
akrl@sdf.org
SDF Public Access UNIX System - https://sdf.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-05-22 21:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-22 7:25 function call location akrl
2018-05-22 16:08 ` akrl
2018-05-22 21:28 ` akrl
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).