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 22:58:52 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Drew Adams <drew.adams@oracle.com> [2020-12-28 19:41]:
> > > > Reading quickly, so perhaps not understanding the request.
> > > > But I'm guessing that advice is what you're looking for.
> 
> Still not reading this thread carefully, but I
> still have the impression that, for what you want
> to do, you can use _advice_.
> 
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html
> 
> When a function gets called you can do anything,
> including introspect the current context,
> reporting on it, and reinvoking the called arg
> (with the same or different args).  Pretty much
> anything.

   A more advanced example would be to trace the calls to the process
filter of a process PROC:

     (defun my-tracing-function (proc string)
       (message "Proc %S received %S" proc string))

     (add-function :before (process-filter PROC) #'my-tracing-function)

Maybe you mean similar to that above.

The `process-filer' would be called multiple times by multiple other
functions in the same time and it would mean that I need somehow to
invoke `add-function' dynamically so that each new buffer receives the
"updating function".

This function here is mostly the final function that shall receive
information how to update the entries when entries are edited,
modified, it should invoke new SQL query to fetch fresh entries.
 
(defun rcd-db-report (title entries format table sort-key)
  (let* ((title (generate-new-buffer-name (concat "RCD Database: " title))))
    (let* ((buffer title)
           (buffer (get-buffer-create buffer))
           (mode-map (rcd-db-table-mode-map table)))
      ;; (message "Keymap: %s" table)
      (switch-to-buffer-other-window buffer)
      (delete-other-windows)
      (setq tabulated-list-format format)
      (setq tabulated-list-entries entries)
      (setq rcd-db-edited-table table)
      (rcd-db-list-mode) ;; TODO if I move it from this line, weird things 
happen
      (use-local-map mode-map) ;; TODO if I move it from this line, weird 
things happen
      (tabulated-list-init-header)
      (setq tabulated-list-padding 1))
      (setq tabulated-list-sort-key sort-key)
      ;;(tabulated-list-init-header)
      (tabulated-list-print t)))

Then there is plethora of other functions that are hoping over
`rcd-db-sql-report-two' (but i could remove hops) and invoking the
above function.

(defun cf-tabulated-accounts-list ()
  (interactive)
  (let* ((sql "SELECT accounts_id, accounts_name FROM accounts"))
    (rcd-db-sql-report-two "Accounts" sql [("ID" 5 t) ("Account" 80 t)] 
"accounts" nil)))

(defun cf-tabulated-accounts-without-country ()
  (interactive)
  (let* ((sql "SELECT accounts_id, accounts_name FROM accounts WHERE 
accounts_billingcountry IS NULL"))
    (rcd-db-sql-report-two "Accounts" sql [("ID" 5 t) ("Account" 80 t)] 
"accounts" nil)))

(defun cf-tabulated-account (id)
  (let* ((sql (format "SELECT accounts_id, accounts_name FROM accounts WHERE 
accounts_id = %s" id)))
    (rcd-db-sql-report-two "Accounts" sql [("ID" 5 t) ("Account" 80 t)] 
"accounts" nil)))

Let us say there is invoked function `(cf-tabulated-account 2)' then
one solution that I can think of is to pass it as in the arguments,
maybe making a macro out of it.

(defun cf-tabulated-account (id)
  (let* ((sql (format "SELECT accounts_id, accounts_name FROM accounts WHERE 
accounts_id = %s" id)))
    (rcd-db-sql-report-two "Accounts" sql [("ID" 5 t) ("Account" 80 t)] 
"accounts" nil `'(cf-tabulated-account ,id))))

Then it would arrive to first function to be invoked to refresh the entries.

Just thinking how to do it right. It requires a lot of changes to many various 
functions.





reply via email to

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