[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is there way to read function invoked and its parameters?
From: |
Yuri Khan |
Subject: |
Re: Is there way to read function invoked and its parameters? |
Date: |
Mon, 28 Dec 2020 02:11:12 +0700 |
On Mon, 28 Dec 2020 at 00:55, Jean Louis <bugs@gnu.support> wrote:
> Would this concept be possible in Emacs Lisp:
>
> (defun my-function (arg &optional arg-1 arg-2)
> (call-other-function (this-function-called parameters-to-this-function)))
>
> Then the other function would receive something like
>
> (my-function ARGUMENTS)
>
> Purpose of this is for `tabulated-list-mode' to know how to refresh
> it. As the mode could be called by plethora of various ways. It would
> be best if I could detect how function was called, with which
> parameters and record the fact so that by the key the same function
> may be called again.
Firstly, ‘tabulated-list-mode’ should probably never be “called” as
such. Instead, modes should be derived from it. (In OOP terms,
‘tabulated-list-mode’ should be treated as an abstract base class.)
‘tabulated-list-mode’ is derived from ‘special-mode’ which binds the
‘g’ key to ‘revert-buffer’. The behavior of ‘revert-buffer’ is
customized by setting ‘revert-buffer-function’ locally.
‘tabulated-list-mode’ sets ‘revert-buffer-function’ to
‘tabulated-list-revert’. The behavior of ‘tabulated-list-revert’ is
customized by adding to ‘tabulated-list-revert-hook’.
> Problem is not when there is one function or one report, I have
> dynamic reports and varieties of reports invoked by variety of
> functions and arguments.
>
> Or maybe there is other way of doing that?
>
> Should I just use local variables to remember the function and its
> arguments so that I may invoke it from the report page?
That is the way, I think.
Be aware that setting a major mode kills all local variables. So you
might want to structure your report mode and functions like this:
(defvar-local my-report--context …
"…documentation…")
(defun my-report--revert ()
"…documentation…"
(setq tabulated-list-entries …something computed from
my-report--context…))
(define-derived-mode my-report-mode tabulated-list-mode "…"
"…documentation…"
(add-hook 'tabulated-list-revert #'my-report--revert))
(defun my-report (…args…)
"…documentation…"
(with-current-buffer (…generate a buffer name…)
(my-report-mode)
(setq-local my-report--context …some context built from args…)
(revert-buffer)))
Re: Is there way to read function invoked and its parameters?,
Yuri Khan <=