From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Is there way to read function invoked and its parameters? Date: Mon, 28 Dec 2020 22:58:52 +0300 Message-ID: References: <9e5a8908-51c4-4abb-bdf2-b07fba13d651@default> <87blefjdp4.fsf@zoho.eu> <3fb924a1-794e-43f7-bdea-d95a383c448a@default> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3788"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 28 21:05:32 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktyln-0000rd-6X for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 21:05:31 +0100 Original-Received: from localhost ([::1]:48364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktylm-00045C-86 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 28 Dec 2020 15:05:30 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktykV-00044r-1d for help-gnu-emacs@gnu.org; Mon, 28 Dec 2020 15:04:11 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:57267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktykR-0000Lk-E7 for help-gnu-emacs@gnu.org; Mon, 28 Dec 2020 15:04:10 -0500 Original-Received: from localhost ([::ffff:41.210.155.200]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000003C8BB.000000005FEA3A34.000021BA; Mon, 28 Dec 2020 13:04:03 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <3fb924a1-794e-43f7-bdea-d95a383c448a@default> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:126879 Archived-At: * Drew Adams [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.