help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help setting nadvice for indent-region


From: Kaushal Modi
Subject: Re: Help setting nadvice for indent-region
Date: Fri, 05 Feb 2016 23:58:14 +0000

Aha.. looks like the check_mark in callint.c is raising the error even
before the advice sets the args as the call_interactively's 'r' case is
activated. That's because indent-region has (interactive "r\nP").

So looks like I'll need to advice the whole interactive? What would be a
better solution?

On Fri, Feb 5, 2016 at 6:49 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:

> Hi,
>
> I'd like to advice indent-region so that if a region is not select, it
> indents between (point-min) and (point-max).
>
> So I have this:
>
> =====
>
> (defun adv/indent-region (args)
>   (when (not mark-active)
>     (setq args (list (point-min) (point-max))))
>   args)
> (advice-add 'indent-region :filter-args #'adv/indent-region)
>
> =====
>
> This usually works, unless I have just launched a fresh buffer in which
> there is no mark set.
>
> If I do M-: (mark) in that buffer, I get nil.
> In that case, if I call M-x indent-region (with no region selected), I get
> this error backtrace:
>
> Debugger entered--Lisp error: (error "The mark is not set now, so there is
> no region")
>   call-interactively(indent-region nil nil)
>   command-execute(indent-region)
>
> If it looks like the error is triggered by call-interactively even before
> the advice gets to do its thing.
>
> How can I resolve this using nadvice?
>
> Thanks.
>
> Kaushal Modi
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]