Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

el-get-notify.el 5.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
;;; el-get --- Manage the external elisp bits and pieces you depend upon
;;
;; Copyright (C) 2010-2011 Dimitri Fontaine
;;
;; Author: Dimitri Fontaine <dim@tapoueh.org>
;; URL: http://www.emacswiki.org/emacs/el-get
;; GIT: https://github.com/dimitri/el-get
;; Licence: WTFPL, grab your copy here: http://sam.zoy.org/wtfpl/
;;
;; This file is NOT part of GNU Emacs.
;;
;; Install
;;     Please see the README.asciidoc file from the same distribution

(require 'el-get-core)
(require 'help-mode)     ; byte-compiling needs to know about xref-type buttons

;; we support notifications on darwin too, thanks to growlnotify
19
(defcustom el-get-growl-notify-path "/usr/local/bin/growlnotify"
20 21 22 23
  "Absolute path of the growlnotify tool"
  :group 'el-get
  :type 'file)

24
(define-obsolete-variable-alias 'el-get-growl-notify 'el-get-growl-notify-path "4.0")
25 26 27 28

;; notify user with emacs notifications API (new in 24)
;;
(when (and (eq system-type 'darwin)
29
	   (file-executable-p el-get-growl-notify-path))
30 31 32 33
  (defun el-get-growl (title message)
    "Send a message to growl, that implements notifications for darwin"
    (let* ((name  "*growl*")
	   (proc
34
	    (start-process name name el-get-growl-notify-path title "-a" "Emacs")))
35 36 37
      (process-send-string proc (concat message "\n"))
      (process-send-eof proc))))

38
(defcustom el-get-notify-type 'both
39 40 41 42 43 44 45 46 47 48
  "Type of notification to use for changes in package statuses

Choices are `graphical', `message', or `both'. Note that if
graphical notification is impossible, `message' will be used as a
fallback."
  :group 'el-get
  :type '(choice (const :tag "Graphical notifications" graphical)
                 (const :tag "Minibuffer message" message)
                 (const :tag "Graphical & Minibuffer" both)))

49 50 51 52 53 54 55 56
;;
;; Notification support is either the internal one provided by Emacs 24, or
;; the external growl one as defined above, or the one provided by the
;; add-on found on http://www.emacswiki.org/emacs/notify.el (there's a
;; recipe) for older Emacs versions users
;;
(defun el-get-notify (title message)
  "Notify the user using either the dbus based API or the `growl' one"
57 58 59 60 61 62 63 64
  (when (not (eq el-get-notify-type 'message))
    (if (fboundp 'dbus-register-signal)
        ;; avoid a bug in Emacs 24.0 under darwin
        (require 'notifications nil t)
      ;; else try notify.el, there's a recipe for it
      (unless (fboundp 'notify)
        (when (featurep 'notify)
          (require 'notify)))))
65

66
  (condition-case nil
67 68 69 70 71 72 73 74 75 76 77 78 79 80
      (progn
        (cond
         ;; Message only
         ((equal el-get-notify-type 'message) (error "Use `message' instead"))
         ;; Graphical notification
         ((fboundp 'notifications-notify) (notifications-notify :title title
                                                                :body message))
         ((fboundp 'notify)               (notify title message))
         ((fboundp 'el-get-growl)         (el-get-growl title message))
         ;; Fallback
         (t                               (error "Fallback to `message'")))
        ;; Handle "both"
        (when (equal el-get-notify-type 'both)
          (error "Fallback to `message' even though graphical notification succeeded")))
81
    ;; when notification function errored out, degrade gracefully to `message'
82
    (error (message "%s: %s" title message))))
83

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
(defun el-get-post-install-notification (package)
  "Notify the PACKAGE has been installed."
  (el-get-notify (format "%s installed" package)
		 "This package has been installed successfully by el-get."))
(add-hook 'el-get-post-install-hooks 'el-get-post-install-notification)

(defun el-get-post-update-notification (package)
  "Notify the PACKAGE has been updated."
  (el-get-notify (format "%s updated" package)
		 "This package has been updated successfully by el-get."))
(add-hook 'el-get-post-update-hooks 'el-get-post-update-notification)

(defun el-get-post-remove-notification (package)
  "Notify the PACKAGE has been removed."
  (el-get-notify (format "%s removed" package)
		 "This package has been removed successfully by el-get."))
(add-hook 'el-get-post-remove-hooks 'el-get-post-remove-notification)

(defun el-get-post-error-notification (package info)
  "Notify the PACKAGE has failed to install."
  (el-get-notify (format "%s failed to install" package)
		 (format "%s" info)))
(add-hook 'el-get-post-error-hooks 'el-get-post-error-notification)

;;
;; Emacs `message' notifications
;;
(defun el-get-post-init-message (package)
  "After PACKAGE init is done, just message about it"
  (el-get-verbose-message "el-get initialized package %s" package))
(add-hook 'el-get-post-init-hooks 'el-get-post-init-message)

(defun el-get-post-update-message (package)
  "After PACKAGE update is done, message about it"
  (el-get-verbose-message "el-get updated package %s" package))
(add-hook 'el-get-post-update-hooks 'el-get-post-update-message)

(defun el-get-post-remove-message (package)
  "After PACKAGE remove is done, message about it"
  (el-get-verbose-message "el-get removed package %s" package))
(add-hook 'el-get-post-remove-hooks 'el-get-post-remove-message)

(defun el-get-post-error-message (package info)
  "After PACKAGE fails to install, just message about it"
  (el-get-verbose-message "el-get failed to initialize package %s" package))
(add-hook 'el-get-post-error-hooks 'el-get-post-error-message)

(provide 'el-get-notify)