Let's say I want to use elisp functions in a script . I rely in my script on some library, dash which I require.

#!/usr/local/bin/emacs --script
(require 'dash)

(message (describe-variable 'load-path))

As is, I will get

$ ./loader.sh
Cannot open load file: No such file or directory, dash

What is the simplest way to make a set of packages accessible to an elisp environment used in a script ?

PS : The equivalent for haskell, using nix, would be

#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages(p: with p; [type-level-sets])"
#! nix-shell -I nixpkgs=channel:nixos-18.03

{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}

module Main where

import Data.Type.Set (Set(..), Proxy(..))

class Get a s where
  get :: Set s -> a

instance {-# OVERLAPS #-} Get a (a ': s) where
  get (Ext a _) = a

instance {-# OVERLAPPABLE #-} Get a s => Get a (b ': s) where
  get (Ext _ xs) = get xs

main :: IO ()
main = do
  let lst = Ext "hello" $ Ext 10 $ Empty
  putStrLn $ show $ get @String lst

I have one answer with Nix, but I am curious as to how it is possible to do so without Nix

#! /usr/bin/env nix-shell
#! nix-shell -i "emacs --script"  -p "pkgs.emacsWithPackages(epkgs: (with epkgs.melpaPackages; [ dash ]))"
#! nix-shell -I nixpkgs=channel:nixos-18.03
(require 'dash)

(message "Hi")

Just put the directory where dash.el[c] resides in your load-path value, before you require that library:

(add-to-list 'load-path "/YOUR/DIRECTORY/CONTAINING/DASH/")
(require 'dash)



or for more modern Emacsen you can use


In either case, it needs to come before the require.

  • it does not seem to work unfortunately. If I ask (message (describe-variable package-load-list)) in the script $./loader.sh, I get Symbol’s value as variable is void: package-load-list – nicolas Nov 28 '18 at 14:02
  • Works for me with Emacs-25.1. Your error description seems odd: how come you don't get an error during package-initialize (i.e. before getting to package-load-list) then? – Stefan Nov 28 '18 at 14:11
  • The documentation for package-initialize mentions this variable, which is why I looked into its it "controls which packages to load" it says... I guess it has some "safety" mechanism if it's not defined. in the end, it does not seem to load anything gist.github.com/nrolland/7e4e38e160b0cfa32f522742707fab6e – nicolas Nov 28 '18 at 14:16
  • with nix and your tip, I have one solution. thank you – nicolas Nov 28 '18 at 15:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.