diff --git a/_resources/port1.0/group/elisp-1.0.tcl b/_resources/port1.0/group/elisp-1.0.tcl index 0d4e762f096..3f104592c42 100644 --- a/_resources/port1.0/group/elisp-1.0.tcl +++ b/_resources/port1.0/group/elisp-1.0.tcl @@ -99,6 +99,13 @@ default elisp.byte_compile yes options elisp.autoloads default elisp.autoloads yes +# Filename prefix for the site-start.d snippet that loads this port's +# autoloads. Snippets are loaded in lexical filename order; the value is +# zero-padded so lower numbers load earlier. The default suits ports with no +# ordering requirements. +options elisp.site_start_priority +default elisp.site_start_priority 50 + # Internal flag tracking whether a port has opted in to the managed phases. set elisp_managed 0 @@ -160,14 +167,37 @@ proc elisp.setup {} { } } - # Install autoloads file if generated + # Install autoloads file if generated, plus a site-start.d snippet so + # the emacs port's site-start.el loads it at startup (giving real + # autoloading without the user editing their init file). set autoload_file "${srcdir}/${pkg}-autoloads.el" - if {[file exists $autoload_file]} { + if {[option elisp.autoloads] && [file exists $autoload_file]} { xinstall -m 0644 $autoload_file ${dest} + elisp.install_site_start_snippet ${destroot} ${pkg} ${pkg}-autoloads } } } +# Helper: install a site-start.d snippet that loads ${loaddefs} (an autoloads +# or loaddefs file, named without the .el suffix) from the port's site-lisp +# subdirectory, so the emacs port's site-start.el loads it at startup. Exposed +# so ports that override the managed destroot (e.g. org-mode) can install a +# snippet themselves. +proc elisp.install_site_start_snippet {destroot pkg loaddefs} { + global emacs_lispdir + set ssd ${destroot}${emacs_lispdir}/site-start.d + xinstall -d ${ssd} + set prio [format %03d [option elisp.site_start_priority]] + set snippet ${ssd}/${prio}-${pkg}.el + set fh [open ${snippet} w] + puts $fh ";; -*- lexical-binding: t; -*-" + puts $fh ";; Auto-generated by the elisp 1.0 portgroup for ${pkg}." + puts $fh "(add-to-list 'load-path \"${emacs_lispdir}/${pkg}\")" + puts $fh "(load \"${emacs_lispdir}/${pkg}/${loaddefs}\" nil t)" + close $fh + file attributes ${snippet} -permissions 0644 +} + # Helper: resolve the effective list of .el files. proc elisp._get_files {} { set files [option elisp.files]