0

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?

Drew
  • 75,699
  • 9
  • 109
  • 225
scaramouche
  • 1,772
  • 10
  • 24

1 Answers1

1
(defun YOUR/fn ()
  (YOUR/insert))

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

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

(YOUR/fn)
;; => 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.
shynur
  • 4,065
  • 1
  • 3
  • 23