Module: Neruda::LispConfig

Included in:
Config
Defined in:
lib/neruda/config/lisp_config.rb

Overview

This module contains utilitary methods to ease ~org-config.el~ file generation

Instance Method Summary collapse

Instance Method Details

#org_last_versionString

Fetch and return the last published version of Org.

Returns:

  • (String)

    the new x.x.x version string of Org



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/neruda/config/lisp_config.rb', line 14

def org_last_version
  return @org_version if @org_version
  if File.exist?('tmp/__last_org_version__')
    @org_version = IO.read('tmp/__last_org_version__')
    return @org_version
  end
  versions = JSON.parse(
    URI('https://updates.orgmode.org/data/releases').open.read
  ).sort { |a, b| b['date'] <=> a['date'] }
  @org_version = versions.first['version']
  FileUtils.mkdir_p 'tmp'
  IO.write('tmp/__last_org_version__', @org_version)
  @org_version
end

#write_dir_localsInteger

Generate emacs directory variables file.

This method generate the file ~.dir-locals.el~, which is responsible to load neruda Org settings when visiting an Org file of this neruda instance.

Returns:

  • (Integer)

    the length written (as returned by the underlying ~IO.write~ method call)



62
63
64
65
66
67
68
# File 'lib/neruda/config/lisp_config.rb', line 62

def write_dir_locals
  workdir = Dir.pwd
  IO.write(
    "#{workdir}/.dir-locals.el",
    "((org-mode . ((eval . (load-file \"#{workdir}/org-config.el\")))))"
  )
end

#write_org_lisp_config(with_tags: false) ⇒ Integer

Generate emacs lisp configuration file for Org and write it.

This method saves the generated configuration in the file ~org-config.el~ at the root of your project, overwriting it if it existed already.

Returns:

  • (Integer)

    the length written (as returned by the underlying ~IO.write~ method call)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/neruda/config/lisp_config.rb', line 37

def write_org_lisp_config(with_tags: false)
  projects = org_generate_projects(with_tags: with_tags)
  workdir = Dir.pwd
  content = IO.read(File.expand_path('./org-config.el', __dir__))
              .gsub('__VERSION__', Neruda::VERSION)
              .gsub('__WORK_DIR__', workdir)
              .gsub('__NERUDA_DIR__', __dir__)
              .gsub('__ORG_VER__', org_last_version)
              .gsub('__ALL_PROJECTS__', all_projects(projects))
              .gsub('__THEME_CONFIG__', org_default_theme_config)
              .gsub('__ALL_PROJECTS_NAMES__', project_names(projects))
              .gsub('__LONG_DATE_FMT__', r18n_full_datetime_format)
              .gsub('__AUTHOR_EMAIL__', settings['author_email'] || '')
              .gsub('__AUTHOR_NAME__', settings['author'])
  IO.write("#{workdir}/org-config.el", content)
end