Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. (require 'cl)
  2.  
  3. (defun async-shell-command-to-string (command callback)
  4. "Execute shell command COMMAND asynchronously in the
  5. background.
  6.  
  7. Return the temporary output buffer which command is writing to
  8. during execution.
  9.  
  10. When the command is finished, call CALLBACK with the resulting
  11. output as a string."
  12. (lexical-let
  13. ((output-buffer (generate-new-buffer " *temp*"))
  14. (callback-fun callback))
  15. (set-process-sentinel
  16. (start-process "Shell" output-buffer shell-file-name shell-command-switch command)
  17. (lambda (process signal)
  18. (when (memq (process-status process) '(exit signal))
  19. (with-current-buffer output-buffer
  20. (let ((output-string
  21. (buffer-substring-no-properties
  22. (point-min)
  23. (point-max))))
  24. (funcall callback-fun output-string)))
  25. (kill-buffer output-buffer))))
  26. output-buffer))
  27.  
  28. (provide 'async-shell-command-to-string)
  29.  
  30. (defun fr-wordreference-word-at-point ()
  31. "Looks up word in point using Wordreference."
  32. (interactive)
  33. (let* ((word (asciify-string (downcase (current-word t)))))
  34. (async-shell-command-to-string
  35. (concat "wr.sh " word)
  36. (lambda (s)
  37. (save-excursion
  38. (set-buffer (get-buffer-create "*wr*"))
  39. (erase-buffer)
  40. (insert s)
  41. (display-buffer "*wr*" t))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement