Run `create-react-app` from within Common Lisp - lisp

Assuming that a local system has create-react-app installed (npm i -g create-react-app), I want to run it with parameters from within a Common Lisp file. What's the best way to do this?

as far as i know, the potrable solution is uiop:run-program, since your cl distribution probably has the asdf included.
CL-USER> (uiop:run-program "create-react-app" :output t :error-output t)
;;Please specify the project directory:
;; create-react-app <project-directory>
;;For example:
;; create-react-app my-react-app
;;Run create-react-app --help to see all options.
;;; Debugger entered on #<UIOP/RUN-PROGRAM:SUBPROCESS-ERROR {10018B83A3}>
this one reports error, as the create-react-app itself does for no args.
(uiop:run-program "create-react-app my-new-shiny-app" :output t :error-output t)
succeeds, and creates app in your cwd.
you can wrap it into a function like this, for example:
(defun create-react-app (app-path &key verbose info scripts-version template use-npm use-pnp typescript)
(let ((cmd (format nil "create-react-app ~a ~
~#[--verbose~*~] ~
~#[--info~*~] ~
~#[--scripts-version ~a~] ~
~#[--template ~a~] ~
~#[--use-npm~*~] ~
~#[--use-pnp~*~] ~
~#[--typescript~*~]"
app-path verbose info scripts-version template use-npm use-pnp typescript)))
(format t "executing shell command: ~a~%" cmd)
(uiop:run-program cmd :output t :error-output t)))
(create-react-app "my-new-shiny-app" :template "cra-template-quickstart-redux" :use-npm t)
havent thoroughly tested it, but it should work.

Related

ox-hugo github actions : Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md) Error: Process completed with exit code 255

Im trying to deploy my hugo site on github actions. Im using the following github action which does the following :
1.On Ubuntu
2.Setup up emacs
3.git clone ox-hugo package
4.ox-hugo package should convert my .org files to .md
setup and build using Hugo and deploy
https://gist.github.com/shwetarkadam/d890b7054b65fe21b63609ca03650bdc
I'm facing an issue on step 4 where I encounter the following error on GitHub action :
Run emacs ./config.org --batch -L ./ox-hugo -L ox-hugo.el --eval="(org-hugo-export-wim-to-md t)" --kill
Debugger entered--Lisp error: (void-function org-hugo-export-wim-to-md)
(org-hugo-export-wim-to-md t)
eval((org-hugo-export-wim-to-md t) t)
command-line-1(("./config.org" "-L" "./ox-hugo" "-L" "ox-hugo.el" "--eval=(org-hugo-export-wim-to-md t)" "--kill"))
command-line()
normal-top-level()
Approaches tried till now :
Changing (org-hugo-export-wim-to-md t) to (org-hugo-export-wim-to-md :all-subtrees)
Adding the expression (org-hugo-export-wim-to-md :all-subtrees) in single quotes and double quotes.
I happened to be working on a similar problem today. I had searched for guidance on it and I stumbled across Batch export of org-mode files from the command line which led me to fniessen/orgmk and in orgmk.el in particular.
After experimenting in my *scratch* buffer and asking Emacs' various help facilities a few questions, I bludgeoned my way to a standalone file containing Emacs Lisp code that appears to work independently of my initialization files.
$ touch export.el
$ emacs -q --batch -l export.el
Designating package sites
Designating package site melpa-stable => https://stable.melpa.org/packages/
Designating package site melpa => https://melpa.org/packages/
Designating package site gnu => https://elpa.gnu.org/packages/
Installing package ox-hugo
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
‘ox-hugo’ is already installed
Exporting org subtrees to hugo from content.org
1 files scanned, 0 files contains IDs, and 0 IDs found.
[ox-hugo] 1/ Exporting ‘Redacted site title’ ..
[ox-hugo] 2/ Exporting ‘Posts’ ..
[ox-hugo] 3/ Exporting ‘Redacted post title’ ..
[ox-hugo] Exported 3 subtrees from content.org in 0.510s (0.170s avg)
Exporting all org subtrees in all files in /redacted/directory
$ find content -newer export.el
content
content/_index.md
content/posts
content/posts/redacted-post-title.md
content/posts/_index.md
(Some names have been changed to protect the guilty er um I mean innocent.)
The file export.el contains:
(defvar my/package-archives
(list
(cons "melpa-stable" "https://stable.melpa.org/packages/")
(cons "melpa" "https://melpa.org/packages/")
(cons "gnu" "https://elpa.gnu.org/packages/")))
(defvar my/packages-to-install '(ox-hugo))
(defun my/designate-package-site (site)
(message "Designating package site %s => %s" (car site) (cdr site))
(add-to-list 'package-archives site t))
(defun my/designate-package-sites ()
(message "Designating package sites")
(mapcar #'my/designate-package-site my/package-archives))
(defun my/install-package (pkg)
(message "Installing package %s" pkg)
(ignore-errors (package-install pkg)))
(when (locate-library "package")
(require 'package)
(my/designate-package-sites)
(package-initialize)
(unless package-archive-contents (package-refresh-contents))
(mapcar #'my/install-package my/packages-to-install))
(defun my/batch-ox-hugo-file (file)
(message "Exporting org subtrees to hugo from %s" file)
(let ((all-subtrees t)
(any-visibility nil))
(with-current-buffer (find-file-noselect file)
(org-hugo-export-wim-to-md all-subtrees any-visibility))))
(defun my/batch-ox-hugo-directory (directory)
(message "Exporting all org subtrees in all files in %s" directory
(let ((default-directory (expand-file-name directory)))
(mapcar #'my/batch-ox-hugo-file
(file-expand-wildcards "*.org")))))
(my/batch-ox-hugo-directory default-directory)
The execution environment where I developed this is Emacs 28.2 on FreeBSD 13.1.
I haven't tried it out with Github Actions yet, but that's my next step.

Racket web server write file error

I write a web program to write file,and read file.And it failed.
And the program code is following:
#lang web-server/insta
(define (start request)
(index-wrap request))
(define (index-wrap request)
(define (response-generator embed/url)
(response/xexpr
`(html
(head (title "test"))
(body
(h1 "Test Write")
(form ((action ,(embed/url write-handler)))
(input ((type "submit"))))))))
(define (write-handler request)
(call-with-output-file "write_file"
#:exists 'truncate
(lambda (out) (print "hello,world" out)))
(index-wrap request))
(send/suspend/dispatch response-generator))
And when you click the button,it occurs an error:
call-with-output-file: cannot open output file
path: /usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/htdocs/write_file
system error: Permission denied; errno=13
And I also write a test program to test the call-with-output-file function,and it write file successful.And my test program code are following:
#lang racket
(call-with-output-file "write_other"
#:exists 'truncate
(lambda (out) (print "hello,racket" out)))
So what's the problem about it?
Try
(define (write-handler request)
(displayln (list "HERE" (current-directory)))
(call-with-output-file "write_file"
#:exists 'truncate
(lambda (out) (print "hello,world" out)))
(index-wrap request))
(send/suspend/dispatch response-generator))
to see which directory you are trying to write to. I suspect the web-server has changed directory to something else than you expect.
EDIT
Now you know that the path is
/usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/htdocs/
you have two options.
Change the permissions of the folder
Start the web-server somewhere else
The easiest is to change the permissions:
cd /usr/share/racket/pkgs/web-server-lib/web-server/default-web-root/
chmod +w htdocs
sudo chmod +w htdocs
Hopefully one of the two last lines work. If not you need to
google how to set file permissions to write on your OS.

how to setup custom error processing only for custom compile command in emacs?

I'm using scons to build my c++ projects.
I'm using next script to correctly process scons's errors:
34;;; SCons builds into a 'build' subdir, but we want to find the errors
35;;; in the regular source dir. So we remove build/XXX/YYY/{dbg,final}/ from the
36;;; filenames.
37(defun process-error-filename (filename)
38 (let ((case-fold-search t))
39 (setq f (replace-regexp-in-string
40 "[Ss]?[Bb]uild[\\/].*\\(final\\|dbg\\)[^\\/]*[\\/]" "" filename))
41 (cond ((file-exists-p f)
42 f)
43 (t filename))))
44
45(setq compilation-parse-errors-filename-function 'process-error-filename)
So. I want to use emacs not only with c++ and scons. But also with java and other languages.
How to setup emacs to use this "process-error-filename" function only when I'm running the
M-x compile
scons
command?
You can use mode hooks
http://www.gnu.org/software/emacs/manual/html_node/emacs/Hooks.html
http://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html
(defun my-c++-mode-hook ()
(set (make-local-variable
'compilation-parse-errors-filename-function)
'process-error-filename))
(add-hook 'c++-mode-hook 'my-c++-mode-hook)

loading clojure-contrib

I'm new to the whole JVM thing, and trying to play with clojure. I'm attempting to load clojure-contrib and failing:
# in bash
$ java -cp /path/to/clojure.jar:/path/to/contrib.jar clojure.main
# in REPL
user=> (require 'clojure.contrib.math)
nil
user=> (sqrt 2)
java.lang.Exception: Unable to resolve symbol: sqrt in this context (NO_SOURCE_FILE:10)
Any pointers will be great - thanks.
I'm no expert, but it seemed like a namespace issue. The solution I employed was this:
;; for REPL
user=> (ns user (:use clojure.contrib.math))
nil
user=> (sqrt 2)
1.4142135623730951
You should put refer after require which will map all the symbols into current namespace
(require 'clojure.contrib.math)
(refer 'clojure.contrib.math)
(sqrt 2)
(expt 2 3)
For detailed intro you may read wikibooks article.
http://en.wikibooks.org/wiki/Clojure_Programming/Concepts#Refer_and_Use

cl-pdf output error

I'm trying to use cl-pdf for some fairly basic PDF generation, but I'm getting tripped up at the examples (which is embarassing to say the least).
When I run the first example included in the package
(defun example1 (&optional (file #P"/tmp/ex1.pdf"))
(pdf:with-document ()
(pdf:with-page ()
(pdf:with-outline-level ("Example" (pdf:register-page-reference))
(let ((helvetica (pdf:get-font "Helvetica")))
(pdf:in-text-mode
(pdf:set-font helvetica 36.0)
(pdf:move-text 100 800)
(pdf:draw-text "cl-pdf: Example 1"))
(pdf:translate 230 500)
(loop repeat 150
for i = 0.67 then (* i 1.045)
do (pdf:in-text-mode
(pdf:set-font helvetica i)
(pdf:set-rgb-fill (/ (random 255) 255.0)
(/ (random 255) 255.0)
(/ (random 255) 255.0))
(pdf:move-text (* i 3) 0)
(pdf:show-text "cl-typesetting"))
(pdf:rotate 13)))))
(pdf:write-document file)))
by running (example1 #P"/home/inaimathi/Desktop/ex1.pdf") it gives me this error
#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf"
{CF9D931}> is not a binary output stream.
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Exit debugger, returning to top level.
The same thing happens when I call (example1), or when I do
(with-open-file
(test-file #P"/home/inaimathi/Desktop/ex1.pdf"
:direction :output :if-does-not-exist :create)
(example1 test-file))
Finally, if I try
(with-open-file
(test-file #P"/home/inaimathi/Desktop/ex1.pdf"
:direction :output :if-does-not-exist :create
:element-type '(unsigned-byte 8))
(example1 test-file))
I get the error
#<SB-SYS:FD-STREAM for "file /home/inaimathi/Desktop/test.pdf"
{D197C99}> is not a character output stream.
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Exit debugger, returning to top level.
Is there a way to declare a binary character stream? How do I get simple output out of cl-pdf? I'm using SBCL straight out of the debian repos (which is 1.0.29, I think), in case it matters.
(setf pdf:*compress-streams* nil) should help. It's trying to write binary data to a character stream, and while that works on LispWorks and some other systems, it doesn't work everywhere and particularly not on SBCL.
EDIT 2: asdf-install is unmaintained and deprecated. It is best to use Quicklisp. To install Quicklisp, you'll need to download it:
$ curl -O https://beta.quicklisp.org/quicklisp.lisp
Then add cl-pdf to your lisp installation:
$ sbcl --load quicklisp.lisp
* (quicklisp-quickstart:install)
* (ql:quickload "vecto")
* (ql:add-to-init-file)
* (exit)
Now all you need to do is add
(load "~/quicklisp/setup.lisp") ; if it installed in the default location
to your .lisp file, and you can then add
(ql:quickload "cl-pdf")
EDIT: This is what I ended up doing. The solution by xach above would also work.
In the end I had to wget http://www.fractalconcept.com/download/cl-pdf-current.tgz and install that.
For the newbs (since I remember how frustrating it is for someone new to Common Lisp to hear "just do a checkout and install it"):
1.Do the checkout as above (I assume you've done this in your home directory from now on)
2.Type in tar xvzf cl-pdf-current.tgz (the point is to get a tarball of the folder. You can do this through the GUI too, it makes no difference)
3.Hop into your SBCL prompt and enter
(require 'asdf)
(require 'asdf-install)
4.If you already installed cl-pdf using (asdf-install:install 'cl-pdf), then you'll need to enter (asdf-install:uninstall 'cl-pdf)
5.Type (asdf-install:install "/home/[your home folder name]/cl-pdf-current.tgz")
I got one compilation error throughout this process, which I just selected [Accept] for. It still seems to work fine.
Hopefully the upcoming release of quicklisp will reduce the need for this sort of package hunting.