al-compilation.el 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ;;; al-compilation.el --- Additional functionality for compilation buffers
  2. ;; Copyright © 2015-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;; This program is distributed in the hope that it will be useful,
  8. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. ;; GNU General Public License for more details.
  11. ;; You should have received a copy of the GNU General Public License
  12. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ;;; Code:
  14. (require 'cl-lib)
  15. (require 'notifications)
  16. (require 'al-sound)
  17. (require 'al-file)
  18. (defvar al/compilation-sound-success
  19. (al/file-if-exists
  20. "/usr/share/sounds/freedesktop/stereo/complete.oga")
  21. "Sound file for a successful compilation.")
  22. (defvar al/compilation-sound-error
  23. (al/file-if-exists
  24. "/usr/share/sounds/freedesktop/stereo/suspend-error.oga")
  25. "Sound file for a failed compilation.")
  26. ;; Idea from <https://gist.github.com/jwiegley/fd78e747f27a90cb67a2>.
  27. (defun al/compilation-notify (buffer reason)
  28. "Notify about the ended compilation in BUFFER.
  29. This function is intended to be used in
  30. `compilation-finish-functions'."
  31. (with-current-buffer buffer
  32. (unless (eq major-mode 'grep-mode)
  33. (cl-multiple-value-bind (sound urgency)
  34. ;; `compilation-start' calls `compilation-handle-exit' with
  35. ;; "finished" message if exit status is 0. Is there a better
  36. ;; way to get exit status?
  37. (if (string-match "\\`finished" reason)
  38. (list al/compilation-sound-success 'normal)
  39. (list al/compilation-sound-error 'critical))
  40. (and sound (al/play-sound sound))
  41. (notifications-notify
  42. :urgency urgency
  43. :title "Compilation finished"
  44. :body (format (concat "Buffer: %s\n"
  45. "Reason: %s")
  46. (buffer-name buffer) reason))))))
  47. (provide 'al-compilation)
  48. ;;; al-compilation.el ends here