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
-
#org_last_version ⇒ String
Fetch and return the last published version of Org.
-
#write_dir_locals ⇒ Integer
Generate emacs directory variables file.
-
#write_org_lisp_config(with_tags: false) ⇒ Integer
Generate emacs lisp configuration file for Org and write it.
Instance Method Details
#org_last_version ⇒ String
Fetch and return the last published version of Org.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/neruda/config/lisp_config.rb', line 13 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 index = URI('https://orgmode.org/index.html').open.read last_ver = index.match(/https:\/\/orgmode\.org\/org-([0-9.]+)\.tar\.gz/) # :nocov: if last_ver.nil? warn 'Org last version not found' return nil end FileUtils.mkdir_p 'tmp' IO.write('tmp/__last_org_version__', last_ver[1]) # :nocov: @org_version = last_ver[1] end |
#write_dir_locals ⇒ Integer
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.
65 66 67 68 69 70 71 |
# File 'lib/neruda/config/lisp_config.rb', line 65 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/neruda/config/lisp_config.rb', line 40 def write_org_lisp_config(with_tags: false) projects = org_generate_projects(with_tags: ) workdir = Dir.pwd content = IO.read(File.('./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 |