Add example of installation on Doomemacs and fix the stringp nil in error handling

This commit is contained in:
Samuel Ortion 2023-11-30 07:25:04 +01:00
parent a616da6a1d
commit 3eedcc534a
3 changed files with 30 additions and 8 deletions

0
LICENSE Normal file → Executable file
View File

24
README.org Normal file → Executable file
View File

@ -1,5 +1,5 @@
* ob-pasp * ob-pasp
Org-Babel mode to execute Clingo Potassco code within Org-mode Org-Babel mode to execute Potassco Answer Set Programming code within Org-mode with =clingo=.
#+begin_src pasp #+begin_src pasp
child(C, P) :- parent(P, C). child(C, P) :- parent(P, C).
@ -21,3 +21,25 @@ Calls : 1
Time : 0.000s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s) Time : 0.000s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.000s CPU Time : 0.000s
#+end_example #+end_example
** Installation
The package is not (yet) available on MELPA, so the package should be installed from github directly.
*** Dependencies
To be able to use =ob-pasp= you will need to install =clingo= cli.
*** Doomemacs
In your =$DOOMDIR/package.el= file, you might want to set up the following:
#+begin_src emacs-lisp
(package! pasp-mode) ;; Add syntax highlighting for Potassco ASP
(package! ob-pasp
:recipe (:host github :repo "UncleSamulus/ob-pasp"))
#+end_src
** TODO Spacemacs
** TODO =use-package= / =straight=

6
ob-pasp.el Normal file → Executable file
View File

@ -138,7 +138,7 @@ This function is called by `org-babel-execute-src-block'"
(vars (org-babel--get-vars processed-params)) (vars (org-babel--get-vars processed-params))
(result-params (assq :result-params processed-params)) (result-params (assq :result-params processed-params))
;; either OUTPUT or VALUE which should behave as described above ;; either OUTPUT or VALUE which should behave as described above
(result-type (assq :result-type processed-params)) (result-type "output"); (assq :result-type processed-params))
;; expand the body with `org-babel-expand-body:pasp' ;; expand the body with `org-babel-expand-body:pasp'
(full-body (org-babel-expand-body:pasp (full-body (org-babel-expand-body:pasp
body params processed-params)) body params processed-params))
@ -146,7 +146,7 @@ This function is called by `org-babel-execute-src-block'"
(clingo (executable-find "clingo")) (clingo (executable-find "clingo"))
(cmd (concat (shell-quote-argument (expand-file-name clingo)) (cmd (concat (shell-quote-argument (expand-file-name clingo))
(when models (when models
(concat " -n " models)) (concat " -n " (int-to-string models)))
" " (org-babel-process-file-name temp-file)))) " " (org-babel-process-file-name temp-file))))
;; actually execute the source-code block either in a session or ;; actually execute the source-code block either in a session or
;; possibly by dropping it to a temporary file and evaluating the ;; possibly by dropping it to a temporary file and evaluating the
@ -165,7 +165,7 @@ This function is called by `org-babel-execute-src-block'"
;; ref. https://github.com/arnm/ob-mermaid ;; ref. https://github.com/arnm/ob-mermaid
(unless (file-executable-p clingo) (unless (file-executable-p clingo)
(error "Cannot find or execute %s, please check `clingo`" clingo)) (error "Cannot find or execute `clingo', please check it is installed and in PATH"))
(with-temp-file temp-file (insert full-body)) (with-temp-file temp-file (insert full-body))
(message "%s" cmd) (message "%s" cmd)
(org-babel-eval cmd "") (org-babel-eval cmd "")