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: Mon, 8 Feb 2016 12:03:12 -0800 Message-ID: References: <87a8ne2k6v.fsf@web.de> <87si145aru.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1454961832 22184 80.91.229.3 (8 Feb 2016 20:03:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Feb 2016 20:03:52 +0000 (UTC) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 08 21:03:52 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 1aSs2J-0002M2-Ly for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Feb 2016 21:03:51 +0100 Original-Received: from localhost ([::1]:48371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSs2I-0006DW-WF for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Feb 2016 15:03:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42075) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSs22-0006Al-3R for help-gnu-emacs@gnu.org; Mon, 08 Feb 2016 15:03:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSs21-0005UA-26 for help-gnu-emacs@gnu.org; Mon, 08 Feb 2016 15:03:34 -0500 Original-Received: from mail-yk0-x22c.google.com ([2607:f8b0:4002:c07::22c]:34187) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSs20-0005U2-Ty for help-gnu-emacs@gnu.org; Mon, 08 Feb 2016 15:03:32 -0500 Original-Received: by mail-yk0-x22c.google.com with SMTP id u9so91700074ykd.1 for ; Mon, 08 Feb 2016 12:03:32 -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 :content-type; bh=1vICFUS51KqPJkaQ9v6Lj9YkC0u2M9Yt1jhyRk7hGmM=; b=KKt+xIvdj1MznmuQCGYvawS61994i26w2yEEYIkGRbK/bsA+5WGqUUGN89I2tYyvKz Oj46yAQpwlTMpyLt7pg+i1R0vWWSVzykwOL1ljBfLErA7lCM+f1c7aGUvwKUFvzq5GAB pYSqTBz4i5xSrfkUswi7z6munV+fBCWJ7XOuHZFY0+fKQzCZYWN9xQC4R+bwyBkMgCom Uc10s2FBwkILLFCV/0vv0MpkhGFOTFsIoOzI7J7CIlQg7R7D5omljWzSI+djKd+65hyC N4YvaM5vg08X7+jSOS9d245n9XOSAEGaAzF98D+/5InHenBpHZe0mgWAKUOKrb9/M2cs 7f7A== 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:content-type; bh=1vICFUS51KqPJkaQ9v6Lj9YkC0u2M9Yt1jhyRk7hGmM=; b=Ay7WXEaJEv/XH1zG/vY4ZpnQkNHhb5YQvSaxl3n1RWS+xsvGGAHL4h0424ULLQvv3h LtaaC0qsJc+RT5TEWHZk8ShdSXj/Polvg8z6+NrkjMualtEJ5klojn01io5rbo0tHfon oNgbIe6DqF5r8Y0KvUskweOwZjMM3n3Ya49zrr4DXoWI12oWHRdAQwUZ5kyeiSxJRjyV A6An8Ec6OUKtb5TDb6G5wBDd8VN0j7OVQlkM/HC/POie39ch+cU1oXRkUOwP3WcrCq/c Tfrb8YGYlu7AYxpdvEjIOKxCDMhTo8mI1Ma51DIGBKhCyr98kumgZTymf/QH3cLWlC5J i45w== X-Gm-Message-State: AG10YOQmANNmyRCjlOFmyjL0jbBhaJ80OGhWx5OEM4w1DSHIkinqjUMgUe09zIjrV/37uy0wQ2de3KA6/lOmDA== X-Received: by 10.37.14.132 with SMTP id 126mr15988679ybo.69.1454961812293; Mon, 08 Feb 2016 12:03:32 -0800 (PST) Original-Received: by 10.37.230.79 with HTTP; Mon, 8 Feb 2016 12:03:12 -0800 (PST) In-Reply-To: <87si145aru.fsf@debian.uxu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c07::22c 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:109061 Archived-At: Emanuel Berg wrote: > Macros and advices are absolutely at the next level > compared to stapling defuns as another bricklayer, but > just because it is more advanced doesn't make it > better - it depends. > >> (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)) > > OK, if this is "simpler", I'd say my DWIM groyne is > simpler still: > > (defun indent-region-dwim () > (interactive) > (if mark-active > (indent-region (mark) (point)) > (indent-region (point-min) (point-max) ))) I don't have strong feelings about this one way or the other, but the points I would make in defense of advice are: - It's "just" function composition, nothing scary - Your solution requires you to define a new `dwim' function every time you want overload a function like this, whereas with advice you can simply add it to the list of functions to be adviced (assuming it will be adviced in the same way). > It it also more natural and "human-ish" to read > without all the computer lingo (`funcall' etc.). Avoid funcall because it has a fun-y (haha) name? This part I can't get behind at all. -- john