help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there way to read function invoked and its parameters?


From: Jean Louis
Subject: Re: Is there way to read function invoked and its parameters?
Date: Mon, 28 Dec 2020 10:07:20 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Yuri Khan <yuri.v.khan@gmail.com> [2020-12-27 22:11]:
> 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.)

Alright, I am doing it that way.

> ‘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’.

Good information, that is what I have to use.

> 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))

The principle for refreshing or reverting is there, that is
right. Only that it is very inconvenient especially if there is large
number of functions.

In the above example I would rather like to pass some dynamically
defined function to add-hook then making many revert functions for
each report.

I am now thinking to employ something like this concept:

(defun my-report (arg1 arg2 arg3)
  (cl-flet my-report--revert ()
           (my-report arg1 arg2 arg3))
  (invoke-other-function 'my-report--revert))

Then other function can set up hooks by using that function. Does
this sound alright to you?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]