-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
103 lines (81 loc) · 2.99 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- mode: ruby; coding: utf-8; indent-tabs-mode: nil -*-
require 'fileutils'
emacs_cmd = "emacs -Q --batch"
if FileTest::directory?("/opt/homebrew/")
site_lisp_dir = '/opt/homebrew/share/emacs/site-lisp'
else
site_lisp_dir = '/usr/local/share/emacs/site-lisp'
end
user_emacs_dir = "#{Dir.home}/.emacs.d"
init_module_dir = "#{user_emacs_dir}/modules"
core_dir = "#{init_module_dir}/core"
vendor_dir = "#{user_emacs_dir}/vendor"
# Build
task :generate_loaddefs do
site_lisp_dirs = Dir.glob("#{site_lisp_dir}/*/**/")
paths = site_lisp_dirs.join(" ")
s = "(setq make-backup-files nil generated-autoload-file \"#{site_lisp_dir}/site-loaddefs.el\")"
sh "#{emacs_cmd} --eval '#{s}' -f batch-update-autoloads #{paths}"
end
task :link_hooks do
git_hooks = Dir.glob("#{user_emacs_dir}/etc/git-hooks/*")
FileUtils.ln_sf(git_hooks, "#{user_emacs_dir}/.git/hooks/")
end
task :make_dir do
FileUtils.ln_sf(Dir.pwd, user_emacs_dir)
emacs_dirs = ["#{user_emacs_dir}/etc/snippets",
"#{user_emacs_dir}/lib",
"#{user_emacs_dir}/var/backup",
"#{user_emacs_dir}/var/bookmark",
"#{user_emacs_dir}/var/cache/pcache",
"#{user_emacs_dir}/var/log",
"#{user_emacs_dir}/var/tmp",
"#{user_emacs_dir}/vendor"]
FileUtils.mkdir_p(emacs_dirs)
end
task :set_config do
if RUBY_PLATFORM.include?("darwin")
sh "defaults write org.gnu.Emacs TransparentTitleBar DARK"
end
end
# Byte compile
task :compile_all do
els = FileList.new("#{user_emacs_dir}/*init.el", "#{init_module_dir}/*/*init-*.el") do |el|
el.exclude(/.+\-init\-private\-.+\.el/)
el.exclude(/.+\/obsoleted-config\/.+\.el/)
end
conf = els.join(" ")
s = "(let ((default-directory \"#{vendor_dir}\")) (normal-top-level-add-subdirs-to-load-path))"
sh "#{emacs_cmd} -L #{core_dir}/ --eval '#{s}' -f batch-byte-compile #{conf}"
end
task :compile_init_module do
els = FileList.new("#{user_emacs_dir}/*init.el", "#{init_module_dir}/*/*-init-*.el") do |el|
el.exclude(/.+\-init\-private\-.+\.el/)
el.exclude(/.+\/obsoleted-config\/.+\.el/)
end
conf = els.join(" ")
sh "#{emacs_cmd} -L #{core_dir}/ -f batch-byte-compile #{conf}"
end
task :tag do
tag = "#{user_emacs_dir}/TAGS"
els = "#{user_emacs_dir}/*init.el #{init_module_dir}/"
if File.exist?(tag)
sh "ctags -e -u -f #{tag} -R #{els}"
else
sh "ctags -e -f #{tag} -R #{els}"
end
end
# Cleanup
task :remove_elc do
FileUtils.rm(Dir.glob("#{user_emacs_dir}/{early-init.elc,init.elc,modules/*/*.elc}"))
FileUtils.rm_r(Dir.glob("#{user_emacs_dir}/var/eln-cache/*}"))
end
task :remove_cache do
FileUtils.rm_r(Dir.glob("#{user_emacs_dir}/var/{initerror,{backup,cache,log,tmp}/*}"))
end
# Commands
task :compile => [:compile_all, :tag]
task :install => [:set_config, :generate_loaddefs, :make_dir, :link_hooks, :compile_init_module, :tag]
task :cleanup => [:remove_cache, :remove_elc]
task :clear => [:remove_cache]
task :default => [:cleanup, :compile]