Module: CmdTools::Commands::EmacsLaunch
- Extended by:
- RubyPatch::AutoLoad
- Defined in:
- lib/cmd_tools/commands/emacs_launch.rb
Class Method Summary collapse
- .daemon_running? ⇒ Boolean
- .emacsclient_open(files_str) ⇒ Object
- .is_gui_running? ⇒ Boolean
-
.run(mode, *files) ⇒ Object
This method is created to provide ‘open -a Emacs.app’ command of Mac to Linux.
-
.stop ⇒ Object
Stop emacs daemon.
Class Method Details
.daemon_running? ⇒ Boolean
39 40 41 |
# File 'lib/cmd_tools/commands/emacs_launch.rb', line 39 def self.daemon_running? system "emacsclient -e '()' > #{File::NULL} 2>&1" end |
.emacsclient_open(files_str) ⇒ Object
47 48 49 |
# File 'lib/cmd_tools/commands/emacs_launch.rb', line 47 def self.emacsclient_open(files_str) spawn "emacsclient -n #{files_str}" end |
.is_gui_running? ⇒ Boolean
43 44 45 |
# File 'lib/cmd_tools/commands/emacs_launch.rb', line 43 def self.is_gui_running? ::CmdTools::Config.emacs_window_systems.include?(`emacsclient -e "(window-system)"`.strip) end |
.run(mode, *files) ⇒ Object
This method is created to provide ‘open -a Emacs.app’ command of Mac to Linux. Unfortunately, This method is not work satisfactory on Mac (but you have ‘open -a Emacs.app’). This method will
-
open
filesbymode(:gui/:cui) mode -
launch emacs daemon if necessary
-
create new frame if necessary
You can edit ~/.config/cmd_tools/config.yaml to specify a path to an emacs executable.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cmd_tools/commands/emacs_launch.rb', line 13 def self.run(mode, *files) Process.waitpid(spawn "#{::CmdTools::Config.emacs} --daemon") unless daemon_running? files_str = files.flatten.join(' ') case mode when :gui if is_gui_running? emacsclient_open(files_str) else spawn "emacsclient -c -n #{files_str}" end when :cui Process.waitpid(emacsclient_open(files_str)) # To retain a file even if a terminal, which the file was opened, have closed. exec "emacsclient -t #{files_str}" else raise ArgumentError, "Expected :gui or :cui, but got #{mode}." end end |
.stop ⇒ Object
Stop emacs daemon.
33 34 35 |
# File 'lib/cmd_tools/commands/emacs_launch.rb', line 33 def self.stop exec "emacsclient -e '(kill-emacs)'" if daemon_running? end |