Module: CmdTools::Command::EmacsLaunch

Extended by:
RubyPatch::AutoLoad
Defined in:
lib/cmd_tools/command/emacs_launch.rb

Class Method Summary collapse

Class Method Details

.daemon_running?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/cmd_tools/command/emacs_launch.rb', line 35

def self.daemon_running?
  system "emacsclient -e '()' > /dev/null 2>&1"
end

.number_of_framesObject



39
40
41
# File 'lib/cmd_tools/command/emacs_launch.rb', line 39

def self.number_of_frames
  `emacsclient -e "(length (visible-frame-list))"`.to_i
end

.run(mode, *files) ⇒ Object

Open files by mode (:gui/:cui) mode. Launch emacs daemon if necessary. Create new frame if necessary. You can edit ~/.config/cmd_tools/config.yaml to specify an emacs executable. For example, if you are a Mac user who uses MacPorts, following modification will be useful.

- :emacs: emacs
+ :emacs: /Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cmd_tools/command/emacs_launch.rb', line 12

def self.run(mode, *files)
  system "#{::CmdTools::Config.emacs} --daemon" unless self.daemon_running?

  files = files.flatten.join(' ')
  case mode
  when :gui
    if self.number_of_frames <= 1 # emacs daemon has one (invisible) frame.
      exec "emacsclient -c -n #{files}"
    else
      exec "emacsclient -n #{files}"
    end
  when :cui
    exec "emacsclient -t #{files}"
  else
    raise ArgumentError, "Expected :gui or :cui, but got #{mode}."
  end
end

.stopObject

Stop emacs daemon.



31
32
33
# File 'lib/cmd_tools/command/emacs_launch.rb', line 31

def self.stop
  exec "emacsclient -e '(kill-emacs)'"
end