unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Error with add-function and process-filter
@ 2024-03-11 10:20 hendeigr via Users list for the GNU Emacs text editor
  2024-03-11 13:21 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-03-11 18:06 ` tpeplt
  0 siblings, 2 replies; 6+ messages in thread
From: hendeigr via Users list for the GNU Emacs text editor @ 2024-03-11 10:20 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error with add-function and process-filter
  2024-03-11 10:20 Error with add-function and process-filter hendeigr via Users list for the GNU Emacs text editor
@ 2024-03-11 13:21 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-03-11 18:01   ` tpeplt
  2024-03-11 18:06 ` tpeplt
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-03-11 13:21 UTC (permalink / raw)
  To: help-gnu-emacs

> (add-function :before (process-filter h-proc) #'h/trace)
[...]
> However, am getting this error:
> Symbol’s value as variable is void: v

My crystal ball tells me you forgot to activate `lexical-binding`
because you didn't see the message that must have been emitted at some
point:

    Warning: Use of gv-ref probably requires lexical-binding

If you're using a new enough Emacs you can click on the orange "/d" in
your mode line to fix the problem.


        Stefan




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error with add-function and process-filter
  2024-03-11 13:21 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-03-11 18:01   ` tpeplt
  2024-03-11 18:21     ` hendeigr
  0 siblings, 1 reply; 6+ messages in thread
From: tpeplt @ 2024-03-11 18:01 UTC (permalink / raw)
  To: hendeigr; +Cc: Stefan Monnier, help-gnu-emacs


>> (add-function :before (process-filter h-proc) #'h/trace)
> [...]
>> However, am getting this error:
>> Symbol’s value as variable is void: v
>
> My crystal ball tells me you forgot to activate `lexical-binding`
> because you didn't see the message that must have been emitted at some
> point:
>
>     Warning: Use of gv-ref probably requires lexical-binding
>
> If you're using a new enough Emacs you can click on the orange "/d" in
> your mode line to fix the problem.
>
>

If you are not using a new enough version of Emacs, then add the
following line to the beginning (the very first line) of your Emacs Lisp
file:

;; -*- lexical-binding: t; -*-

   That is what clicking on the "/d" will do for you.

--



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error with add-function and process-filter
  2024-03-11 10:20 Error with add-function and process-filter hendeigr via Users list for the GNU Emacs text editor
  2024-03-11 13:21 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-03-11 18:06 ` tpeplt
  2024-03-11 20:29   ` hendeigr
  1 sibling, 1 reply; 6+ messages in thread
From: tpeplt @ 2024-03-11 18:06 UTC (permalink / raw)
  To: hendeigr via Users list for the GNU Emacs text editor; +Cc: hendeigr

hendeigr via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

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

1. When you are editing an Emacs Lisp file, then two details for you to
   note are that a) the major mode is Emacs Lisp (indicated by the text
   (Elisp... in the mode line) and b) the menu bar will include an
   "Emacs-Lisp" entry.  While you are new to Emacs Lisp, it will be
   helpful for you to use that menu item.  (If you spend a lot of time
   writing in Emacs Lisp, then you will eventually want to learn key
   sequences and command names that will enable you to execute commands
   more quickly.)

   Using the "Emacs-Lisp" menu, locate the "Byte-compile This File"
   entry.  When you click on this, then for the code that you provided, you
   will see the following warnings:

   In h/trace:
      Warning: Unused lexical argument `proc'

   In end of data:
     Warning: the function ‘term-send-raw-string’ is not known to be defined.
     Warning: the function ‘vterm’ is not known to be defined.

   (File name and line/columns numbers omitted.)  These warning messages
   may vary depending on your version of Emacs.

2. In addition to the byte-compiler, Emacs includes a lint utility that
   can be helpful for finding errors (although it can have problems
   understanding macros, but that mostly should not be a concern for new
   users).  To run the Emacs lint on your buffer’s contents follow the menu
   from Emacs-Lisp -> Linting -> Lint Buffer.

Once you have resolved any byte-compiler problems, then if your problem
still persists you should send a sufficiently complete segment of code
that allows readers to byte-compile the code and reproduce the problem.

--



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error with add-function and process-filter
  2024-03-11 18:01   ` tpeplt
@ 2024-03-11 18:21     ` hendeigr
  0 siblings, 0 replies; 6+ messages in thread
From: hendeigr @ 2024-03-11 18:21 UTC (permalink / raw)
  To: tpeplt; +Cc: Stefan Monnier, help-gnu-emacs






Sent with Proton Mail secure email.

On Monday, 11 March 2024 at 18:01, tpeplt <tpeplt@gmail.com> wrote:

> > > (add-function :before (process-filter h-proc) #'h/trace)
> > > [...]
> > > However, am getting this error:
> > > Symbol’s value as variable is void: v
> > 
> > My crystal ball tells me you forgot to activate `lexical-binding`
> > because you didn't see the message that must have been emitted at some
> > point:
> > 
> > Warning: Use of gv-ref probably requires lexical-binding
> > 
> > If you're using a new enough Emacs you can click on the orange "/d" in
> > your mode line to fix the problem.
> 
> 
> If you are not using a new enough version of Emacs, then add the
> following line to the beginning (the very first line) of your Emacs Lisp
> file:
> 
> ;; -- lexical-binding: t; --
> 
> That is what clicking on the "/d" will do for you.
> 
> --

That's got it! Thank you both for your prompt responses. Now its time for me to learn more about dynamic binding vs lexical binding!

Thanks again,

James



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Error with add-function and process-filter
  2024-03-11 18:06 ` tpeplt
@ 2024-03-11 20:29   ` hendeigr
  0 siblings, 0 replies; 6+ messages in thread
From: hendeigr @ 2024-03-11 20:29 UTC (permalink / raw)
  To: tpeplt; +Cc: hendeigr via Users list for the GNU Emacs text editor






Sent with Proton Mail secure email.

On Monday, 11 March 2024 at 18:06, tpeplt <tpeplt@gmail.com> wrote:

> hendeigr via Users list for the GNU Emacs text editor
> help-gnu-emacs@gnu.org writes:
> 
> > 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)))
> 
> 
> 1. When you are editing an Emacs Lisp file, then two details for you to
> note are that a) the major mode is Emacs Lisp (indicated by the text
> (Elisp... in the mode line) and b) the menu bar will include an
> "Emacs-Lisp" entry. While you are new to Emacs Lisp, it will be
> helpful for you to use that menu item. (If you spend a lot of time
> writing in Emacs Lisp, then you will eventually want to learn key
> sequences and command names that will enable you to execute commands
> more quickly.)
> 
> Using the "Emacs-Lisp" menu, locate the "Byte-compile This File"
> entry. When you click on this, then for the code that you provided, you
> will see the following warnings:
> 
> In h/trace:
> Warning: Unused lexical argument `proc'
> 
> In end of data:
> Warning: the function ‘term-send-raw-string’ is not known to be defined.
> Warning: the function ‘vterm’ is not known to be defined.
> 
> (File name and line/columns numbers omitted.) These warning messages
> may vary depending on your version of Emacs.
> 
> 2. In addition to the byte-compiler, Emacs includes a lint utility that
> can be helpful for finding errors (although it can have problems
> understanding macros, but that mostly should not be a concern for new
> users). To run the Emacs lint on your buffer’s contents follow the menu
> from Emacs-Lisp -> Linting -> Lint Buffer.
> 
> 
> Once you have resolved any byte-compiler problems, then if your problem
> still persists you should send a sufficiently complete segment of code
> that allows readers to byte-compile the code and reproduce the problem.
> 
> --

Thank you - this is great advice! I usually have the menu bar hidden but realize now that this is a mistake while I am learning elisp - I have been missing out on a lot of helpful functionality. Really appreciate the steer.

Thanks again,

James



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-11 20:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 10:20 Error with add-function and process-filter hendeigr via Users list for the GNU Emacs text editor
2024-03-11 13:21 ` 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

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