erc-input-fill.el 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ;;; erc-input-fill.el -- Hack to get fill mode to work correctly for ERC input
  2. ;;;
  3. ;;; Commentary:
  4. ;;; This is very Quick'n'Dirty, so please report =any= strange
  5. ;;; behavior, preferably via IRC to Adlai @ freenode
  6. ;;; Code:
  7. (require 'erc)
  8. (defvar erc-fill-wrapped-input-p nil
  9. "Keeps track of whether `auto-fill-mode' has wrapped the input text.
  10. Reset to NIL after a message is successfully sent.")
  11. (make-variable-buffer-local 'erc-wrapped-input-p)
  12. (setq normal-auto-fill-function
  13. (lambda ()
  14. (setq erc-fill-wrapped-input-p t)
  15. (do-auto-fill)))
  16. (defun erc-user-input ()
  17. "Return the input of the user in the current buffer.
  18. If `erc-wrapped-input-p' is true, strips all newlines."
  19. (let ((literal-input (buffer-substring-no-properties
  20. erc-input-marker
  21. (erc-end-of-input-line))))
  22. (if erc-fill-wrapped-input-p
  23. (replace-regexp-in-string "\n *" " " literal-input)
  24. literal-input)))
  25. (add-hook 'erc-mode-hook
  26. (lambda ()
  27. (set-fill-column erc-fill-column)
  28. (auto-fill-mode)))
  29. (add-hook 'erc-send-completed-hook
  30. (lambda (message)
  31. (declare (ignore message))
  32. (setq erc-fill-wrapped-input-p nil)))
  33. (provide 'erc-input-fill)
  34. ;;; erc-input-fill.el ends here