The function outshine-cycle (part of Outshine) calls the function indent-relative. I would like that instead, it called the function indent-for-tab-command.

To do this, I want to advise the function outshine-cycle. I imagine this could look like the following (which is not working):

(defun my-indent (orig-fun &rest args)
  (cl-flet ((indent-relative () (indent-for-tab-command)))))

(advice-add 'outshine-cycle :around #'my-indent)

Any ideas?

1 Answer 1

(defun YOUR/fn ()

(defun YOUR/insert ()
  (insert "233"))

(advice-add 'YOUR/fn :around
            (lambda (fn &rest args)
              (let ((old-def (symbol-function 'YOUR/insert)))
                      (fset 'YOUR/insert (lambda ()
                                           (insert "42")))
                      (apply fn args))
                  (fset 'YOUR/insert old-def)))))

;; => 42

Why doesn't your code work?

  1. You used advice-add incorrectly: you didn't call the original function from my-indent. Please see the manual for yourself.
  2. cl-flet "make local function definitions" (quoted from its docstring). macroexpand the cl-flet form then you will find it doesn't change the definition of function YOUR/insert at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.