help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

replacing a function with another one


From: lee
Subject: replacing a function with another one
Date: Sat, 08 Mar 2014 20:43:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi,

is there a way to replace a function with another one other than
re-defining the original function?

Using (defalias) doesn´t seem to work for this.


The background is that I need a modified version of
(hi-lock-set-file-patterns):  The hi-lock-mode has different variables
for highlighting patterns with which it distinguishes between patterns
loaded from the file the buffer is visiting and patterns added through
actions of the user.  These two variables, `hi-lock-file-patterns´ and
`hi-lock-interactive-patterns´, are independent of each other.

When I visit a file with highlighting-patterns, the patterns are read
and applied and *not* added to the `hi-lock-interactive-patterns´
variable.  Consequently, when writing the current patterns to the
buffer, only those patterns are written which have been "recently"
defined by actions of the user.

To add new patterns, I am using wrapper functions, because I want to use
particular faces for the highlighting without needing to type them in
all the time.  When a new pattern is added, the wrapper functions remove
all patterns that have already been written to the buffer.  Then they
use (hi-lock-write-interactive-patterns) to put them back.  That way, I
don´t need to worry whether patterns I added are saved or not.

Since (hi-lock-write-interactive-patterns) writes only the patterns from
the `hi-lock-interactive-patterns´ variable to the buffer, all patterns
that were already there are forgotten.

To avoid this, I have a modified version of (hi-lock-set-file-patterns).
This version assigns the patterns read from the buffer to
`hi-lock-interactive-patterns´ so that they aren´t forgotten anymore.

The only way I have found to make the hi-lock-mode --- without modifying
the mode itself --- use my modified version of
(hi-lock-set-file-patterns) is to re-define this function.


Is this a way in which we are /supposed/ to customise emacs?  Should I
rather make a copy of the whole hi-lock-mode and modify it as I like?
I´d rather not do that (though I might have to because I want a number
of other things as well) because the original may receive fixes and
updates which would become difficult to keep track of.


-- 
Knowledge is volatile and fluid.  Software is power.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]