Si se echa un vistazo a la documentación de add-hook
(o Ch f complemento gancho RET) , verá que una posible solución es hacer que el enlace sea local para los modos principales que desee. Esto es un poco más complicado que vderyagin de answer, y se ve así:
(add-hook 'org-mode-hook
(lambda()
(add-hook 'after-save-hook 'a-test-save-hook nil 'make-it-local)))
El 'make-it-local
es la bandera (puede ser cualquier cosa que no es nil
) que le dice add-hook
añadir el gancho sólo en el búfer en uso. Con lo anterior, solo obtendrá el a-test-save-hook
agregado en org-mode
.
Esto es bueno si desea usar a-test-save-hook
en más de un modo.
La documentación para add-hook
es:
add-hook is a compiled Lisp function in `subr.el'.
(add-hook HOOK FUNCTION &optional APPEND LOCAL)
Add to the value of HOOK the function FUNCTION.
FUNCTION is not added if already present.
FUNCTION is added (if necessary) at the beginning of the hook list
unless the optional argument APPEND is non-nil, in which case
FUNCTION is added at the end.
The optional fourth argument, LOCAL, if non-nil, says to modify
the hook's buffer-local value rather than its default value.
This makes the hook buffer-local if needed, and it makes t a member
of the buffer-local value. That acts as a flag to run the hook
functions in the default value as well as in the local value.
HOOK should be a symbol, and FUNCTION may be any valid function. If
HOOK is void, it is first set to nil. If HOOK's value is a single
function, it is changed to a list of functions.
¿no se supone que se cita a esa lambda? – kindahero
@kindahero, '(lambda() ...)' se evalúa a sí mismo de todos modos, por lo que cotizar no hace la diferencia. –
Gracias, esta es la información que estaba buscando. Volveremos a bucear en los documentos. –