From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Help setting nadvice for indent-region Date: Mon, 08 Feb 2016 01:03:01 +0100 Message-ID: <87si145aru.fsf@debian.uxu> References: <87a8ne2k6v.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1454889817 17020 80.91.229.3 (8 Feb 2016 00:03:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Feb 2016 00:03:37 +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 01:03:27 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 1aSZId-0005BO-34 for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Feb 2016 01:03:27 +0100 Original-Received: from localhost ([::1]:39344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSZIc-0001Fx-Cq for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Feb 2016 19:03:26 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSZIR-0001Fd-Ty for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 19:03:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSZIO-00056l-N5 for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 19:03:15 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:52330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSZIO-00056g-FY for help-gnu-emacs@gnu.org; Sun, 07 Feb 2016 19:03:12 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1aSZIN-0004lR-64 for help-gnu-emacs@gnu.org; Mon, 08 Feb 2016 01:03:11 +0100 Original-Received: from nl106-137-227.student.uu.se ([130.243.137.227]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Feb 2016 01:03:11 +0100 Original-Received: from embe8573 by nl106-137-227.student.uu.se with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Feb 2016 01:03:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 48 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: nl106-137-227.student.uu.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:0edmyDveCOundrhy5aWsdrhC8i4= 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.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:109041 Archived-At: John Mastro writes: > 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. 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) ))) It it also more natural and "human-ish" to read without all the computer lingo (`funcall' etc.). Anyway, another interesting difference, where I'm not sure what is the best way, is `mark-active', then (mark) and (point) vs. (use-region-p), then (region-beginning) and (region-help) What does "the book" say on this? -- underground experts united http://user.it.uu.se/~embe8573