0

I have the following emacs script from here

#!/usr/local/bin/emacs --script
;;; rcat --- cat
;;; Commentary:
;;; cat function in elisp

;;; Code:

;;-*- mode: emacs-lisp;-*-

(defun process (string)
  "Just reverse the STRING."
  (concat (nreverse (string-to-list string))))

(condition-case nil
    (let (line)
      ;;commented out b/c not relevant for `cat`, but potentially useful
      (princ "argv is ")
      (princ argv)
      (princ "\n")
      (princ "command-line-args is" )
      (princ command-line-args)
      (princ "\n")

      (while (setq line (read-from-minibuffer ""))
        (princ (process line))
        (princ "\n")))
  (error nil))

(provide 'rcat)
;;; rcat ends here

It works well but I want to use the s package for string manipulation, and convert my script to this:

#!/usr/local/bin/emacs --batch
;;; rcat --- cat
;;; Commentary:
;;; reverse lines cat function in elisp

;;; Code:

;;-*- mode: emacs-lisp;-*-
(require 's)

(condition-case nil
    (let (line)
      ;;commented out b/c not relevant for `cat`, but potentially useful
      (princ "argv is ")
      (princ argv)
      (princ "\n")
      (princ "command-line-args is" )
      (princ command-line-args)
      (princ "\n")

      (while (setq line (read-from-minibuffer ""))
        (princ (s-reverse line))
        (princ "\n")))
  (error nil))

(provide 'rcat)
;;; rcat ends here

The first code works well:

./rcat 1 2 3 4 < stuff.txt                           
argv is (1 2 3 4)
command-line-args is(/usr/local/Cellar/emacs/HEAD-5583e64_1/Emacs.app/Contents/MacOS/Emacs -scriptload ./rcat 1 2 3 4)
dcba
4321

But executing the second, I get:

Cannot open load file: No such file or directory, s

I'm not sure if using cask, batch-mode or something should work.

2

You have to tell Emacs where to find the s library:

(add-to-list 'load-path "/path/to/s/")

Or if you put s in the same directory:

(add-to-list 'load-path ".")
2

--batch doesn't process your init file, so it has no idea where your personal libraries are.

Instead of (require 's) (which, as per clemera's answer, means you need to set load-path), you could simply (load "path/to/s") for any library you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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