Subject: 24.3.50; add-function problem

From: Gerard Brunick <[email-masked]>
Date: Tue, 18 Jun 2013 21:27:17 -0700

There seems to be a problem with add-function:

1. emacs -Q
2. M-x run-python
3. Eval "(comint-redirect-send-command-to-process "print 'test'" "test" 
"*Python*" t)" and observe that there are no errors.
4. Copy the text of comint-redirect-send-command-to-process from 
comint.el to the scratch buffer, and eval-defun it.
5. Now eval "(comint-redirect-send-command-to-process "print 'test'" 
"test" "*Python*" t)" again and suddenly I get:

Debugger entered--Lisp error: (void-variable v)
   (process-filter v)
   (lambda nil (process-filter v))()
   advice--add-function(:around ((lambda nil (process-filter v)) lambda 
(gv--val) (set-process-filter v gv--val)) comint-redirect-filter nil)
   (save-current-buffer (set-buffer process-buffer) (and 
comint-redirect-perform-sanity-check (save-excursion (goto-char 
(point-max)) (or (re-search-backward comint-prompt-regexp nil t) (error 
"No prompt found or `comint-prompt-regexp' not set properly")))) 
(comint-redirect-setup output-buffer (current-buffer) 
comint-prompt-regexp echo) (advice--add-function :around (let* ((v 
proc)) (cons (function (lambda nil (process-filter v))) (function 
(lambda (gv--val) (set-process-filter v gv--val))))) (function 
comint-redirect-filter) nil) (process-send-string (current-buffer) 
(concat command "\n")) (or no-display (display-buffer (get-buffer-create 
(if (listp output-buffer) (car output-buffer) output-buffer)))))
   (let* ((process-buffer (if (processp process) (process-buffer 
process) process)) (proc (get-buffer-process process-buffer))) 
(save-current-buffer (set-buffer process-buffer) (and 
comint-redirect-perform-sanity-check (save-excursion (goto-char 
(point-max)) (or (re-search-backward comint-prompt-regexp nil t) (error 
"No prompt found or `comint-prompt-regexp' not set properly")))) 
(comint-redirect-setup output-buffer (current-buffer) 
comint-prompt-regexp echo) (advice--add-function :around (let* ((v 
proc)) (cons (function (lambda nil (process-filter v))) (function 
(lambda (gv--val) (set-process-filter v gv--val))))) (function 
comint-redirect-filter) nil) (process-send-string (current-buffer) 
(concat command "\n")) (or no-display (display-buffer (get-buffer-create 
(if (listp output-buffer) (car output-buffer) output-buffer))))))
   comint-redirect-send-command-to-process("print 'test'" "test" 
"*Python*" t)
   eval((comint-redirect-send-command-to-process "print 'test'" "test" 
"*Python*" t) nil)
   eval-last-sexp-1(nil)
   eval-last-sexp(nil)
   call-interactively(eval-last-sexp nil nil)
   command-execute(eval-last-sexp)

If I omit step 4 and eval-defun the code right in comint.el, I don't see 
this behaviour.  I assume that the emacs notices nothing has changed and 
ignores the eval-defun.  This is somehow related to the compile-time 
macro expansion in add-function.

Other configuration info follows:

In GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2)
  of 2013-06-11 on papaya, modified by Debian
  (emacs-snapshot package, version 2:20130611-1~ppa1~precise1)
Windowing system distributor `The X.Org Foundation', version 11.0.11103000
System Description:    Ubuntu 12.04.2 LTS

Configured using:
  `configure --build x86_64-linux-gnu --host x86_64-linux-gnu
  --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib
  --localstatedir=/var --infodir=/usr/share/info --mandir=/usr/share/man
  --with-pop=yes
  --enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/24.3.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3.50/site-lisp:/usr/share/emacs/site-lisp
  --without-compress-info --with-crt-dir=/usr/lib/x86_64-linux-gnu/
  --with-x=yes --with-x-toolkit=gtk3 --with-imagemagick=yes
  CFLAGS='-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2'
  CPPFLAGS='-D_FORTIFY_SOURCE=2' LDFLAGS='-g -Wl,--as-needed
  -znocombreloc''

Important settings:
   value of $LANG: en_US.UTF-8
   locale-coding-system: utf-8-unix
   default enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
   eldoc-mode: t
   tooltip-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent input:
<left> <left> <left> <left> <right> i <S-backspace>
* <right> <right> <right> <right> <right> <right> *
C-e C-x e C-x C-e q <left> <left> <left> <left> <left>
<left> <left> <left> <left> <left> <left> <left> C-x
o C-x b <up> <up> <up> <down> <down> <down> <up> C-k
<tab> q <escape> <escape> C-g <up> <down> C-x o h C-h
C-h q <backspace> <backspace> P C-e C-x C-e <left>
<right> <right> <right> <right> <down> C-x o <up> <down>
C-x b <return> <down> <left> <up> <S-down> <S-down>
<S-down> <S-down> <S-down> <up> <down> C-M-. <escape>
<escape> <escape> <escape> <up> C-u <up> <down> C-S-x
<up> C-M-x C-x o C-x e C-x C-e <up> <down> C-x C-e
C-x o C-x b <return> <up> <up> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-down> <S-down> <S-down> <S-down> <S-down> <S-down>
<S-up> <S-up> M-w <help-echo> C-x o <help-echo> <return>
<return> C-v C-y k <backspace> <up> <up> <up> <up>
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up>
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up>
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <up>
<up> <up> <up> <up> <up> <up> <up> <up> <up> <up> <down>
<down> <down> <down> <down> <down> <down> <down> <up>
<up> <up> <down> <return> C-M-x <up> <up> <up> <up>
<left> C-x e C-x C-e <help-echo> q <help-echo> C-x
o <help-echo> <up> C-x 0 <help-echo> M-x <help-echo>
b u g - r e <tab> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
p o <tab> <help-echo> <backspace> <backspace> <backspace>
<tab> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
<backspace> <backspace> <backspace> <backspace> <backspace>
r e p o r <tab> <return>

Recent messages:
kmacro-call-macro: No kbd macro has been defined
#<window 0x11a1ab0 on test> [2 times]
Mark set
Saved text from "(defun comint-redirect-send-command-to-p"
scroll-up-command: End of buffer
Mark set
comint-redirect-send-command-to-process
kmacro-call-macro: No kbd macro has been defined
Entering debugger...
Back to top level.

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils gv etags nadvice kmacro debug eldoc jka-compr
find-func help-mode help-fns compile python rx easymenu comint ring
ansi-color time-date tooltip ediff-hook vc-hooks lisp-float-type mwheel
x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Cheers,
Gerard