window的buffer change hook

给window的buffer change hook一直是个问题:没有这个hook。我记得之前看过有人用post-command-hook和idle timer做这个事。今天发现了一个自带的hook可以作这个:window-scroll-functions

This variable holds a list of functions that Emacs should call before redisplaying a window with scrolling. Displaying a different buffer in the window also runs these functions.

1赞

但还是不够精确,并不想scroll也触发这个hook,只想switch buffer触发

可以在hook里加判断嘛

请问在使用 org-publish 时,只导出修改过的文件,跳过未修改的文件用的是什么hook?

用的不是hook吧,大概是buffer-modified-p

1赞

哦哦,谢谢。

试试 EMACS27 的 window-buffer-change-functions

  1. 比如:

    (add-hook 'window-buffer-change-functions
              (lambda (window)
                (message "%s is active" (current-buffer))
                )
              nil
              t ; buffer-locally
              )
    
  2. 文档:

    Documentation: Functions called during redisplay when window buffers have changed. The value should be a list of functions that take one argument.

    Functions specified buffer-locally are called for each window showing the corresponding buffer if and only if that window has been added or changed its buffer since the last redisplay. In this case the window is passed as argument.

    Functions specified by the default value are called for each frame if at least one window on that frame has been added, deleted or changed its buffer since the last redisplay. In this case the frame is passed as argument.

1赞

多谢多谢!居然不叫xxx-hook,这咋找得到

xxx-functions 变量名通常用来表示在这里被注册的钩子函数会被带参数调用

这个hook是要来干嘛的?