Class: EmacsRuby::Emacs

Inherits:
Object
  • Object
show all
Defined in:
lib/emacs-ruby/emacs.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEmacs

Returns a new instance of Emacs.



5
6
7
# File 'lib/emacs-ruby/emacs.rb', line 5

def initialize
  @emacs = 'emacs'
end

Instance Attribute Details

#emacsObject

Returns the value of attribute emacs.



3
4
5
# File 'lib/emacs-ruby/emacs.rb', line 3

def emacs
  @emacs
end

Instance Method Details

#batch(target: nil, load: nil, func: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/emacs-ruby/emacs.rb', line 21

def batch(target: nil, load: nil, func: nil)
  return unless func
  cmd = [@emacs]
  cmd << target if target
  cmd << '--batch'
  cmd += ['-l', load] if load
  cmd += ['-f', func] if func
  cmd << '--kill'
  `#{cmd.join ' '}`
end

#org_to_html(org_file, load: nil, func: 'org-html-export-to-html') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/emacs-ruby/emacs.rb', line 9

def org_to_html(org_file, load: nil, func: 'org-html-export-to-html')
  html = nil
  batch target: org_file, load: load, func: func
  html_file = org_file.sub(/.org$/, '.html')
  return html unless File.exist? html_file
  File.open(html_file) do |file|
    html = file.read
  end
  FileUtils.rm_rf html_file
  html
end