From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: Help setting nadvice for indent-region Date: Sun, 7 Feb 2016 10:51:29 -0800 Message-ID: References: <87a8ne2k6v.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1454871127 31269 80.91.229.3 (7 Feb 2016 18:52:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Feb 2016 18:52:07 +0000 (UTC) Cc: Michael Heerdegen , Kaushal Modi To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 07 19:52:04 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 1aSURI-0007sq-1T for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Feb 2016 19:52:04 +0100 Original-Received: from localhost ([::1]:37214 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSURH-0002io-F4 for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Feb 2016 13:52:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57955) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSUR5-0002iL-T1 for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 13:51:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSUR5-0000sM-1v for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 13:51:51 -0500 Original-Received: from mail-yw0-x230.google.com ([2607:f8b0:4002:c05::230]:32997) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSUR4-0000sI-Tl for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 13:51:50 -0500 Original-Received: by mail-yw0-x230.google.com with SMTP id u200so9854141ywf.0 for ; Sun, 07 Feb 2016 10:51:49 -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:content-transfer-encoding; bh=q0rwHLCKJRzmBOU/bLvsnmeHWF5gelGJIeX6WNLKJfc=; b=NnPbcHe2tvU3L0gJ6do8eaxloAJ4lxhYKgrvhvn3er0n9h19BRM5Sg4vLt80kSN7Pw gwK7YVaEfGA9DaO4VDV1AUOjF2ARogfFOald3Kro6Br3kZmtaCsg/m17mWAxTa0lDdmg scJS9cRIkFKEVtY7KXNdKNKwv64L8ih+ZI3ghm7sRwYMPCd7DLnSJY/hSNx2EeXo6b3n 8QdGfMtYJFCmRRSrrpHmpdPN0Uo/UzBlcyQMmUOSJYmvCzT2WJd58ve7BJPx5eLDzFTv 4WT2JEUIJD5CuQxTuU/eztybfAGTyBCfLqsDgV8WtTR8zn184fNzJ1Fmdy98fZCyKQU7 T/aQ== 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:content-transfer-encoding; bh=q0rwHLCKJRzmBOU/bLvsnmeHWF5gelGJIeX6WNLKJfc=; b=buNQDF5pdkJExRkTapeAkjEe7Xqj6t0UMw9+kfDCN0y1wrnBXiKj3UvdcMopbR0/QI D1G6N3igx95BgBWCZeF+rOBWP8pbeIz6bCOG+q7uH+a+HvodnKFTo0e4C2dXFO1kLF5e KjrfulM2jp5oausI9RfRfjRbxnIZEoZsexVjOZzRzrPZuD0/uN/sdfF4PTHpTNKj0/H6 74IX/hXpZ1EdNWefRHO/sjZQbumkq8XtnjWXkN2C58ANVN/n2wQWOAOG+a1cWRtj+KmH +1bpP304yGe2AudlN5zyUGsWVcIb5wSv325Z/lpvHVfVXU0k85sF+jTl7/qMm3J4aDDY Oopw== X-Gm-Message-State: AG10YOQe3rP/MqPdkNb6Sw1nG5ZFbttsDoNc3W9ZeqcCA/Jpotbkr283RVPesDmbX+ASmydWcF/Cl963sbPM9g== X-Received: by 10.129.93.4 with SMTP id r4mr11888669ywb.60.1454871109126; Sun, 07 Feb 2016 10:51:49 -0800 (PST) Original-Received: by 10.37.230.79 with HTTP; Sun, 7 Feb 2016 10:51:29 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::230 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:109039 Archived-At: Kaushal Modi wrote: > For the sake of completeness, this is how I actually needed to implement > this advice in my config: > https://github.com/kaushalmodi/.emacs.d/blob/1f9daf3587863de8561fc34e0baf= da80be389dbf/setup-files/setup-editing.el#L686-L731 > > I am open to comments and criticism. > > Thanks! My preference is for something a bit simpler, which avoids the use of macros. Macros can be awesome, but IMO they don't contribute much here. The downside to my solution is that it doesn't print the "Executed... on the whole buffer" message, since the advice function never sees the symbol that names the adviced function. It has access to =E2=80=98orig=E2= =80=99, of course, but that may be something that wouldn't print well (e.g. a compiled Lisp function). However, I don't see that as critical. (defvar modi/region-or-whole-fns '(indent-region eval-region)) (defun modi/region-or-whole-advice (orig &rest _) (interactive) (if (use-region-p) (funcall orig (region-beginning) (region-end)) (funcall orig (point-min) (point-max)))) (dolist (fn modi/region-or-whole-fns) (advice-add fn :around #'modi/region-or-whole-advice)) --=20 john