From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: A way for interactive to modify a let-bound variable? Date: Fri, 12 Feb 2016 13:18:02 -0500 Message-ID: References: <84f4ec8a-8db7-490b-80d9-0b82788f6a26@default> <87a8n57ss1.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1455301153 16400 80.91.229.3 (12 Feb 2016 18:19:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 12 Feb 2016 18:19:13 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 12 19:19:07 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 1aUIJ8-0002eS-Nz for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Feb 2016 19:19:06 +0100 Original-Received: from localhost ([::1]:35171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUIJ7-0001xi-RD for geh-help-gnu-emacs@m.gmane.org; Fri, 12 Feb 2016 13:19:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUIIl-0001vW-W2 for help-gnu-emacs@gnu.org; Fri, 12 Feb 2016 13:18:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUIIk-0007oD-Om for help-gnu-emacs@gnu.org; Fri, 12 Feb 2016 13:18:43 -0500 Original-Received: from mail-ob0-x22a.google.com ([2607:f8b0:4003:c01::22a]:34732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUIIk-0007nw-Gu for help-gnu-emacs@gnu.org; Fri, 12 Feb 2016 13:18:42 -0500 Original-Received: by mail-ob0-x22a.google.com with SMTP id wb13so133667931obb.1 for ; Fri, 12 Feb 2016 10:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=ngUqw81y7m1mOdB5nV9DJFuMi2g/P1npI8Fe5Yfli64=; b=rUPP+L+eimtjNhMuXZW5qP+7qxkcIlZvmQGIRPkvHZvgU/58dTPp4rjj9kl31IAtp4 mm+4BJ/2ChT7iygDkkI4synynAaNPOdBqmQalnkMbDhD847eKq1g5G5F2WGTMm4JEYZs Txkt8lGJ04EiFIY5JEJgO6uNdNryE6xwQXdA/1t9ZBC9t+sk/F/31+FDzJ/cXtmyKFYT gGALNreeuE4Y8jKUtl16CIqHxD55I/RPyyioWjAtqjo2NiR/kUe7UCQn3pB48KwWn1tk HE04al6HzsKE/kkDxKR4XCi7sQhv8K5CiFhVM72c5ZaWjxbN3ItlvCQaEomtMJzI3gQ7 DB2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=ngUqw81y7m1mOdB5nV9DJFuMi2g/P1npI8Fe5Yfli64=; b=YjZ/Q+ys4sRoefGawbsx1aFmmLDeXNAAtWm0NTKiLnhSIqmNdw283EdnQjugz/kn8C TAmEddB0pqTqsblrHzomDWfxTfp22ya4H2VQW6nxx3GsDzOfyhNZONglIL+IxjbiD8// czzGPWqBTLY7CazmE4kXV3MEgbrjmkUOFNINjDHPrqSRbdIfPjgU6ORJioZRdEghe6Oj mmi7H/A2cP3QAyWVjTRpNgu36qMlm06st3nsiHiLv81+l9Q+n4R8Xd8S/ohYpS2Si2Y4 z/VclRKNQOGgE6zI6P9ouLDSAUXZZR7Dkm6vqMUdk8VCguV4HeR5koSbsmsURuxNWsv6 fQ6w== X-Gm-Message-State: AG10YOT14T+AjDNvoO6fX8xl0cq0MIFb9Z+iKDdBURJK+Xmz9uc8+umGqJzr5uvGVHPp5j4SDv2yqu5cuBrGrA== X-Received: by 10.60.135.98 with SMTP id pr2mr2500719oeb.65.1455301122001; Fri, 12 Feb 2016 10:18:42 -0800 (PST) Original-Received: by 10.202.201.73 with HTTP; Fri, 12 Feb 2016 10:18:02 -0800 (PST) In-Reply-To: <87a8n57ss1.fsf@web.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c01::22a X-Content-Filtered-By: Mailman/MimeDel 2.1.14 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:109144 Archived-At: This is the actual function I want to optimize (Reference: http://thread.gmane.org/gmane.emacs.help/109025/focus=109137 ). (defun modi/advice-region-or-whole (orig-fun &rest args) (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list (point-min) (point-max)))) (prog1 (apply orig-fun args) ; this defun NEEDS to return this form's value (when (and (called-interactively-p 'interactive) ; duplication of condition (not (use-region-p))) ; (message "Executed %s on the whole buffer." (propertize (symbol-name this-command) 'face 'font-lock-function-name-face))))) This is an :around advice function and it needs to return the (apply orig-fun args) value. > You can of course use `let' _inside_ `interactive' If I move the let form inside interactive, the let form needs to return the list required for interactive. Then how would I return the (apply ..) value? Eventually I want something like below that actually works: (defun modi/advice-region-or-whole (orig-fun &rest args) (let (msg) (interactive (if (use-region-p) (list (region-beginning) (region-end)) (setq msg (format "Executed %s on the whole buffer." (propertize (symbol-name this-command) 'face 'font-lock-function-name-face))) (list (point-min) (point-max)))) (prog1 (apply orig-fun args) (when msg (message msg)))))