unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>, help-gnu-emacs@gnu.org
Subject: Re: Help setting nadvice for indent-region
Date: Thu, 11 Feb 2016 20:15:37 +0000	[thread overview]
Message-ID: <CAFyQvY1pCPtpicPBRmwbdGLKu2NQeV7cg-=9T+hLtiVwkQiT6g@mail.gmail.com> (raw)
In-Reply-To: <87vb5vys7n.fsf@web.de>

> I tried it, and can't reproduce what you describe.  How did you try it
(recipe)?

You are right. I am not able to recreate that. I was actually getting
confused because of this:

(defun modi/advice-region-or-whole (&rest args)
  "Advice function that applies the ORIG-FN function to the whole buffer if
a region is not selected."
  (interactive (if (use-region-p) ; when region is selected
                   (list (region-beginning) (region-end))
                 (list (point-min) (point-max))))
  (message "Args: %S use-region-p: %S" args (use-region-p))
  (when (not (use-region-p))
    (message "Executing %s on the whole buffer."
             (propertize (symbol-name this-command)
                         'face
                         'font-lock-function-name-face)))
  nil)

Of course when I did C-M-x, (use-region-p) was nil and so it printed:
"Executing eval-defun on the whole buffer."

Things became clear after I added this debug statement:

 (message "Args: %S use-region-p: %S" args (use-region-p))

In any case, I will be going the right way of advising this as Stefan and
you advised. Now I only need to figure out how not to print that message
when doing eval-defun.


> The around advice function should return the value you want the advised function
to return.

Thank you! So with a let-bound variable 'ret', I can have something like

(setq ret (apply orig-fn args))

and return 'ret' at the end of the :around advice function definition.
Right?


  reply	other threads:[~2016-02-11 20:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-05 23:49 Help setting nadvice for indent-region Kaushal Modi
2016-02-05 23:58 ` Kaushal Modi
2016-02-06  0:00   ` Kaushal Modi
2016-02-06  0:30   ` Emanuel Berg
2016-02-06  3:31     ` Kaushal Modi
2016-02-06 10:43 ` Michael Heerdegen
2016-02-07  3:12   ` Kaushal Modi
2016-02-07 17:46     ` Kaushal Modi
2016-02-07 18:51       ` John Mastro
2016-02-08  0:03         ` Emanuel Berg
2016-02-08  4:22           ` Kaushal Modi
2016-02-08 17:05             ` Eli Zaretskii
2016-02-08 17:27               ` Kaushal Modi
2016-02-09  3:07             ` Emanuel Berg
2016-02-08 20:03           ` John Mastro
2016-02-08 23:13             ` Emanuel Berg
2016-02-11 14:02         ` Stefan Monnier
2016-02-11 17:36           ` Kaushal Modi
2016-02-11 18:10             ` Michael Heerdegen
2016-02-11 18:47               ` Kaushal Modi
2016-02-11 18:56                 ` Kaushal Modi
2016-02-11 19:14                   ` Michael Heerdegen
2016-02-11 20:15                     ` Kaushal Modi [this message]
2016-02-11 20:38                       ` Kaushal Modi
2016-02-12 14:09                         ` Michael Heerdegen
2016-02-12 14:21                           ` Michael Heerdegen
2016-02-12 16:02                             ` Kaushal Modi
2016-02-12 19:04                               ` Michael Heerdegen
2016-02-12 13:57                       ` Michael Heerdegen
2016-02-11 19:03                 ` Michael Heerdegen
2016-02-07 23:48       ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFyQvY1pCPtpicPBRmwbdGLKu2NQeV7cg-=9T+hLtiVwkQiT6g@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).