unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: hendeigr via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: Error with add-function and process-filter
Date: Mon, 11 Mar 2024 10:20:14 +0000	[thread overview]
Message-ID: <P_iJn_mWIxbC4ZsLTlf6YVxXunk5S5HBVHvBD0Go-t9cCMjm86CxmEwnA02YRM13xYdUe7x2jPvAMlN0Axa3Wr7uXDStHH-KZbDTmno3kCs=@protonmail.com> (raw)

Hi -

(Apologies if this is a dup - my first attempt seemed to disappear so after 24 hours, I have resent).

I'm new to elisp and am trying to use add-function/remove-function to add/remove a custom process filter (in order to automate some commands in vterm). I thought I followed the example here: https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html

(defun h/trace (proc string)
(message (format "tracing: %s" string)))

(defun h/test ()
(interactive)
(set-buffer (vterm))
(let* ((h-proc (get-buffer-process (current-buffer))))
(message (format "%s" (process-filter h-proc)))
(add-function :before (process-filter h-proc) #'h/trace)
(term-send-raw-string "ssh whatami@doingwrong.here")
(remove-function (process-filter h-proc) #'h/trace)
) )

However, am getting this error:
Symbol’s value as variable is void: v

When I debug, it seems the process value is not being passed down correctly. What am I doing wrong, please?

Debugger entered--returning value: (lambda nil (process-filter v))
#'(lambda nil (process-filter v))
* (cons #'(lambda nil (process-filter v)) #'(lambda (gv--val) (set-process-filter v gv--val)))
* (let* ((v h-proc)) (cons #'(lambda nil (process-filter v)) #'(lambda (gv--val) (set-process-filter v gv--val))))
* (advice--add-function :before (let* ((v h-proc)) (cons #'(lambda nil (process-filter v)) #'(lambda (gv--val) (set-process-filter v gv--val)))) #'h/trace nil)
(let* ((h-proc (get-buffer-process (current-buffer)))) (message (format "%s" (process-filter h-proc))) (debug) (advice--add-function :before (let* ((v h-proc)) (cons #'(lambda nil (process-filter v)) #'(lambda (gv--val) (set-process-filter v gv--val)))) #'h/trace nil) (term-send-raw-string "ssh whatami@doingwrong.here") (let* ((v h-proc) (new (advice--remove-function (process-filter v) #'h/trace))) (if (eq new (process-filter v)) nil (set-process-filter v new))))
h/test()
funcall-interactively(h/test)
command-execute(h/test record)
Thanks,

James

Sent with [Proton Mail](https://proton.me/) secure email.

             reply	other threads:[~2024-03-11 10:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11 10:20 hendeigr via Users list for the GNU Emacs text editor [this message]
2024-03-11 13:21 ` Error with add-function and process-filter Stefan Monnier via Users list for the GNU Emacs text editor
2024-03-11 18:01   ` tpeplt
2024-03-11 18:21     ` hendeigr
2024-03-11 18:06 ` tpeplt
2024-03-11 20:29   ` hendeigr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='P_iJn_mWIxbC4ZsLTlf6YVxXunk5S5HBVHvBD0Go-t9cCMjm86CxmEwnA02YRM13xYdUe7x2jPvAMlN0Axa3Wr7uXDStHH-KZbDTmno3kCs=@protonmail.com' \
    --to=help-gnu-emacs@gnu.org \
    --cc=hendeigr@protonmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).