From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Suppress user-prompting when calling commands in programs Date: Fri, 13 Jun 2014 08:29:58 -0700 (PDT) Message-ID: <7d140fb3-6b45-4e37-8109-0f794d907b09@default> References: <87r42skjd8.fsf@gmail.com> <83k38kx5y8.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1402673460 12823 80.91.229.3 (13 Jun 2014 15:31:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 13 Jun 2014 15:31:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 13 17:30:53 2014 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 1WvTRJ-00030d-Lg for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Jun 2014 17:30:49 +0200 Original-Received: from localhost ([::1]:59705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvTRJ-0006fb-58 for geh-help-gnu-emacs@m.gmane.org; Fri, 13 Jun 2014 11:30:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvTQj-0006de-BK for help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 11:30:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WvTQa-0000oc-1B for help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 11:30:13 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:30110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WvTQZ-0000hg-RW for help-gnu-emacs@gnu.org; Fri, 13 Jun 2014 11:30:03 -0400 Original-Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id s5DFU0HO030411 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Jun 2014 15:30:01 GMT Original-Received: from aserz7021.oracle.com (aserz7021.oracle.com [141.146.126.230]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5DFTxcN020065 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 13 Jun 2014 15:29:59 GMT Original-Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by aserz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id s5DFTxJU020388 for ; Fri, 13 Jun 2014 15:29:59 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.8 (707110) [OL 12.0.6691.5000 (x86)] X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:98211 Archived-At: > >> (defun foo (&optional arg) > >> (interactive "P") > >> (let ((bar (org-icompleting-read ...))))) > > Yuck! >=20 > Indeed, the prompting should normally take place in the `interactive' > spec, but the above is sadly pretty common. File a code bug / enhancement request for `foo'... > >> Assuming `foo' can't be changed - is there another way to bind `bar' > >> before calling `foo' in a program rather than advising `foo' (with the > >> aim to suppress any user-prompting at all during the execution of > >> `foo')? >=20 > Not really, no. Sure there is. If `bar' is a dynamic variable, at least. > And advising `foo' only won't help: you also need to > advise org-icompleting-read. > > > cl-flet org-icompleting-read to 'ignore? >=20 > Nope. That worked with `flet', but `cl-flet' is actually providing > Common-Lisp's `flet' which defines a lexically-scoped function. > Better use an advice here. It's pretty simple if `bar' is dynamic, not lexical - e.g., top-level (defvar bar 51 "Step up to the bar") ;; Unchangeable `foo' - just instantiating your "...", for a test: (defun foo (&optional arg) (interactive "P") (let ((bar (org-icompleting-read "Prompt: " '("a" "b" "c")))) (message "`foo' arg is %S. BAR is %S" arg bar))) Write a function that binds `bar' to whatever you want and provides whatever arg you want to `foo'. Temporarily redefine `org-icompleting-read' to just return your value of `bar'. Then restore `org-icompleting-read'. (defun toto (my-bar my-foo-arg) (let ((bar my-bar) (o-i-r (symbol-function 'org-icompleting-read))) (unwind-protect (progn (fset 'org-icompleting-read (lambda (&rest _) (symbol-value 'bar))) (foo my-foo-arg)) (fset 'org-icompleting-read o-i-r)))) =20 (toto 42 36) =3D=3D> `foo' arg is 36. BAR is 42 The original definition of `org-icompleting-read' is ignored (no prompting etc.), and `foo's binding of `bar' is overruled by `toto's binding of `bar'. None of this is pretty. But it's not complicated either. And yes, the `foo' code should be rewritten in one of the ways already suggested (file a bug).