Files

Guard::Notifier::Emacs

Send a notification to Emacs with emacsclient (www.emacswiki.org/emacs/EmacsClient).

@example Add the `:emacs` notifier to your `Guardfile`

notification :emacs

Constants

DEFAULTS

Public Class Methods

available?(opts = {}) click to toggle source
# File lib/guard/notifiers/emacs.rb, line 21
def self.available?(opts = {})
  super
  result = `#{ opts.fetch(:client, DEFAULTS[:client]) } --eval '1' 2> #{DEV_NULL} || echo 'N/A'`

  !%(N/A 'N/A').include?(result.chomp!)
end

Public Instance Methods

emacs_color(type, options = {}) click to toggle source

Get the Emacs color for the notification type. You can configure your own color by overwrite the defaults.

@param [String] type the notification type @param [Hash] options aditional notification options @option options [String] success the color to use for success notifications (default is 'ForestGreen') @option options [String] failed the color to use for failure notifications (default is 'Firebrick') @option options [String] pending the color to use for pending notifications @option options [String] default the default color to use (default is 'Black') @return [String] the name of the emacs color

# File lib/guard/notifiers/emacs.rb, line 75
def emacs_color(type, options = {})
  default = options.fetch(:default, DEFAULTS[:default])
  options.fetch(type.to_sym, default)
end
notify(message, opts = {}) click to toggle source

Shows a system notification.

@param [String] type the notification type. Either 'success',

'pending', 'failed' or 'notify'

@param [String] title the notification title @param [String] message the notification message body @param [String] image the path to the notification image @param [Hash] opts additional notification library options @option opts [String] success the color to use for success

notifications (default is 'ForestGreen')

@option opts [String] failed the color to use for failure

notifications (default is 'Firebrick')

@option opts [String] pending the color to use for pending

notifications

@option opts [String] default the default color to use (default is

'Black')

@option opts [String] client the client to use for notification

(default is 'emacsclient')

@option opts [String, Integer] priority specify an int or named key

(default is 0)
# File lib/guard/notifiers/emacs.rb, line 49
def notify(message, opts = {})
  normalize_standard_options!(opts)

  opts      = DEFAULTS.merge(opts)
  color     = emacs_color(opts[:type], opts)
  fontcolor = emacs_color(:fontcolor, opts)
  elisp =           (set-face-attribute 'mode-line nil               :background "#{color}"               :foreground "#{fontcolor}").gsub(/\s+/, ' ').strip

  _run_cmd(opts[:client], '--eval', elisp)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.