Permalink
Browse files

Merge pull request #406 from aspiers/emacs-nil-fix

Avoid spurious 'nil' output from emacs notifier
  • Loading branch information...
2 parents 0ef4ba8 + 64abf12 commit 9825dd22bbb9a0be4d390887a3359fdeaf6b2628 @rymai rymai committed Mar 17, 2013
Showing with 18 additions and 7 deletions.
  1. +12 −1 lib/guard/notifiers/emacs.rb
  2. +6 −6 spec/guard/notifiers/emacs_spec.rb
@@ -52,7 +52,12 @@ def notify(type, title, message, image, options = { })
options = DEFAULTS.merge options
color = emacs_color type, options
fontcolor = emacs_color :fontcolor, options
- system(%(#{ options[:client] } --eval "(set-face-attribute 'mode-line nil :background \\"#{ color }\\" :foreground \\"#{ fontcolor }\\")"))
+ elisp = <<-EOF.gsub(/\s+/, ' ').strip
+ (set-face-attribute 'mode-line nil
+ :background "#{color}"
+ :foreground "#{fontcolor}")
+ EOF
+ run_cmd [ options[:client], '--eval', elisp ]
end
# Get the Emacs color for the notification type.
@@ -70,6 +75,12 @@ def emacs_color(type, options = {})
default = options[:default] || DEFAULTS[:default]
options.fetch(type.to_sym, default)
end
+
+ private
+
+ def run_cmd(args)
+ IO.popen(args).readlines
+ end
end
end
end
@@ -5,9 +5,9 @@
describe '.notify' do
context 'when no color options are specified' do
it 'should set modeline color to the default color using emacsclient' do
- subject.should_receive(:system).with do |command|
+ subject.should_receive(:run_cmd).with do |command|
command.should include("emacsclient")
- command.should include("(set-face-attribute 'mode-line nil :background \\\"ForestGreen\\\" :foreground \\\"White\\\")")
+ command.should include(%{(set-face-attribute 'mode-line nil :background "ForestGreen" :foreground "White")})
end
subject.notify('success', 'any title', 'any message', 'any image', { })
@@ -18,9 +18,9 @@
let(:options) { {:success => 'Orange'} }
it 'should set modeline color to the specified color using emacsclient' do
- subject.should_receive(:system).with do |command|
+ subject.should_receive(:run_cmd).with do |command|
command.should include("emacsclient")
- command.should include("(set-face-attribute 'mode-line nil :background \\\"Orange\\\" :foreground \\\"White\\\")")
+ command.should include(%{(set-face-attribute 'mode-line nil :background "Orange" :foreground "White")})
end
subject.notify('success', 'any title', 'any message', 'any image', options)
@@ -31,9 +31,9 @@
let(:options) { {:pending => 'Yellow'} }
it 'should set modeline color to the specified color using emacsclient' do
- subject.should_receive(:system).with do |command|
+ subject.should_receive(:run_cmd).with do |command|
command.should include("emacsclient")
- command.should include("(set-face-attribute 'mode-line nil :background \\\"Yellow\\\" :foreground \\\"White\\\")")
+ command.should include(%{(set-face-attribute 'mode-line nil :background "Yellow" :foreground "White")})
end
subject.notify('pending', 'any title', 'any message', 'any image', options)

0 comments on commit 9825dd2

Please sign in to comment.