How to wait for an event in the Emacs Lisp function?

I'm trying to write a simple function: send a request to the w3m browser, and then find a specific place on the web page:

(defun w3m-define-word (word)
  (interactive "sDefine: ")
  (progn (w3m-search "Dictionary" word)
         (set-window-start nil (search-forward "Search Results"))))

It is not so that it w3m-searchdoes not wait for the page to reload and set-window-startis executed on the older page. The page then reloads and places the cursor at the beginning of the buffer.

(sleep-for ..)between w3m-searchand set-window-starthelps, but since the loading time is arbitrary, it is not very convenient.

How can I rewrite this function so that it will wait for the buffer to reload, and then the rest?

+5
source share
2 answers

elisp hooks. , w3m . , hook , , .

, C-h v w3m-display-hook RET - , . .

+7

, - , :

(defun w3m-goto-on-load (url)
  "Go to a position after page has been loaded."
  (cond
    ((string-match "domain" url)
      (progn
        (set-window-start nil (search-forward "Search" nil t) nil)))
    (t nil)))
(add-hook 'w3m-display-hook 'w3m-goto-on-load)

"domain" - URL- , "Search" - . , search-forward re-search-forward, .

+1

All Articles