Let's consider a minimal example, I take
org-narrow-to-subtree as a compiled function, under the hood it calls
narrow-to-region, I add simple advice to it:
(defun bark (START END) (message "Bark!")) (advice-add 'narrow-to-region :before #'bark)
If I call
narrow-to-region interactively, the advice obviously works, but if I call
org-narrow-to-subtree which in its turn calls
(narrow-to-region), it behaves as if there was no advice.
If re-eval the function definition (the same source as the original, only defining it again instead of using the compiled version):
(defun org-narrow-to-subtree () "Narrow buffer to the current subtree." (interactive) (save-excursion (save-match-data (org-with-limited-levels (narrow-to-region (progn (org-back-to-heading t) (point)) (progn (org-end-of-subtree t t) (when (and (org-at-heading-p) (not (eobp))) (backward-char 1)) (point)))))))
org-narrow-to-subtree again, the advice gets called normally.
- Why is that?
- How do I solve my problem then? How do I add an advice?