From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: How to advice save-buffers-kill-terminal? Date: Thu, 14 Apr 2016 09:30:45 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1460646225 18307 80.91.229.3 (14 Apr 2016 15:03:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Apr 2016 15:03:45 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Apr 14 17:03:37 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aqinw-0005MK-S7 for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Apr 2016 17:03:36 +0200 Original-Received: from localhost ([::1]:40929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqinw-0008CP-Dt for geh-help-gnu-emacs@m.gmane.org; Thu, 14 Apr 2016 11:03:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqhMV-0005b5-Sd for help-gnu-emacs@gnu.org; Thu, 14 Apr 2016 09:31:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aqhMS-0006CY-NA for help-gnu-emacs@gnu.org; Thu, 14 Apr 2016 09:31:11 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:45206) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aqhMS-0006Bh-5X for help-gnu-emacs@gnu.org; Thu, 14 Apr 2016 09:31:08 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aqhMN-0006KL-NV for help-gnu-emacs@gnu.org; Thu, 14 Apr 2016 15:31:03 +0200 Original-Received: from 45.72.141.36 ([45.72.141.36]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 14 Apr 2016 15:30:58 +0200 Original-Received: from monnier by 45.72.141.36 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 14 Apr 2016 15:30:58 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 49 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 45.72.141.36 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) Cancel-Lock: sha1:XbZHhzuWrcyb6IpB+Vod1Tw/pR4= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:109765 Archived-At: > (advice-add 'save-buffers-kill-terminal :around > #'(lambda (oldfunc &rest r) > (cl-flet ((yes-or-no-p (msg) > (message "test:%S" msg))) > (apply oldfunc r)))) > The yes-or-no-p in cl-flet doesn't affect the calling of yes-or-no-p inside > save-buffers-kill-terminal. Indeed. `cl-flet` is documented as being lexical, which means that it only affects calls to `yes-or-no-p` made *syntactically within* (as opposed to: *during the execution of*) the `cl-flet`. > After a quick look, I found the suspicious *- lexical-binding:t -*- in > files.el. That's actually unrelated: `lexical-binding` affects the scoping of variables, whereas your case depends on the scoping of functions. > Any possibility to modify that yes-or-no-p inside > save-buffers-kill-terminal? Of course. You could use (defvar my-skip-yes-or-no-p nil) (advice-add 'yes-or-no-p :around (lambda (orig-fun &rest args) (if my-skip-yes-or-no-p (apply #'message "test:%S" args) (apply orig-fun args)))) (advice-add 'save-buffers-kill-terminal :around #'(lambda (oldfunc &rest r) (let ((my-skip-yes-or-no-p t)) (apply oldfunc r)))) or (advice-add 'save-buffers-kill-terminal :around #'(lambda (oldfunc &rest r) (cl-letf (((symbol-function 'yes-or-no-p) (lambda (msg) (message "test:%S" msg)))) (apply oldfunc r)))) The second is more concise, but I the like the first better, because C-h f yes-or-no-p RET will then tell you honestly about the fact that it's sometimes overridden. Stefan