From: Karol Hosiawa
Subject: Function hook
Date: 
Message-ID: <20070706160243.ecd24eb3.hosiawak@gmail.com>
In Elisp:

I want to create an alias for Emacs' c-guess-basic-syntax function,
something like this:

(defalias 'c-old-guess-basic-syntax 'c-guess-basic-syntax)

(defun c-guess-basic-syntax ()
   (some logic here)
   (c-old-guess-basic-syntax))

So, I want to create a hook for c-guess-basic-syntax that runs before
the original function and then calls the original function. I don't want
to modify the original function code to add this hook.

The above doesn't work because c-old-guess-basic-syntax doesn't
actually hold a reference to the original c-guess-basic-syntax but to
my newly created one.

How to achieve the above in elisp ?

-- 
Karol Hosiawa
From: Tassilo Horn
Subject: Re: Function hook
Date: 
Message-ID: <87myy9bkhl.fsf@baldur.tsdh.de>
Karol Hosiawa <········@gmail.com> writes:

Hi Karol,

> So, I want to create a hook for c-guess-basic-syntax that runs before
> the original function and then calls the original function. I don't
> want to modify the original function code to add this hook.

Use an advice:

(defadvice c-guess-basic-syntax (before karols-cool-advice)
  "I run before `c-guess-basic-syntax' runs."
  (message "Hey, I'm a piece of advice."))

Bye,
Tassilo
-- 
Fighting patents one by one  will never eliminate the danger of software
patents,  any  more than  swatting  mosquitoes  will eliminate  malaria.
(Richard M. Stallman)