2015-06-26 18 views
3

我已經每當改變緩衝手動,test-func獲取調用使用此代碼的emacs - 後變函數緩衝器改性之後不執行

(defun test-func() 
    (message "foo")) 

(add-hook 'after-change-functions 'test-func nil t) 

現在添加了一個函數來after-change-functions列表。但是,當我編程修改緩衝區使用insert,緩衝區的內容正在更新,但test-func沒有被調用。

任何指針如何激活test-func每次緩衝區更新?

更新:

我想轉換markdown to html和服務上的瀏覽器,這樣,每當用戶鍵入一些降價,HTML會自動更新。

這裏是調用message後原執行test-func

(defun impatient-markup-update (&rest args) 
    "Update html buffer if markup buffer updates." 
    (save-buffer impatient-markup-buffer) 
    (with-current-buffer (get-buffer impatient-markup-html-buffer) 
    (erase-buffer) 
    (insert (shell-command-to-string 
      (format "%s %s" impatient-markup-pandoc impatient-markup-buffer))))) 
+0

你怎麼知道它沒有被調用?如果你在'message'後面使用'sleep-for'或者在'test-func'中調用'insert'來插入'@@@@@@@@@@@@',會發生什麼? – Drew

+0

@德魯,因爲我沒有看到副作用。我不想使用'sleep-for',因爲我立即需要副作用。我實際上在'test-func'中調用'insert',但它不起作用。 – ChillarAnand

+0

也許,https://github.com/skeeto/impatient-mode有幫助嗎? – Tobias

回答

2

使用sleep-for的,作爲一個測試,看看你是否看到消息呢。

after-change-functions不一定會在您期望的緩衝區中運行您的掛鉤。正如文檔所述:

*執行after-change-functions時執行的緩衝區更改不會調用任何更改前或更改後的功能。這是因爲inhibit-modification-hooks暫時設置爲非零。

檢查該鉤子上還有其他什麼,等等,IOW,做一點調試。

+0

'(let((inhibit-modification-hooks nil)) (my-custom-function))'解決了問題 – ChillarAnand