jkitchin / ox-ipynb

org-mode exporter to Jupyter notebooks
170 stars 39 forks source link

Export error. s-slice-at: Args out of range: "", 1 #3

Closed hcmbg closed 6 years ago

hcmbg commented 6 years ago

Hi, I am using Emacs 25.2 on Mac OS X 10.12. First of all thank you for making this great library. I was really waiting for this functionality. But I have some issue.

In my simple org file, I have

#+BEGIN_SRC ipython :session 
  a = 1
  a
#+END_SRC

I use C-c e followed by n n to export to notebook. Then I get the following error.

-slice-at: Args out of range: "", 1

Could you help me sort this out?

jkitchin commented 6 years ago

I can't reproduce this. can you try toggling debug on error and post the traceback?

hcmbg commented 6 years ago

Sorry I am new to Emacs. How do I debug this? I tried M-x debug-on-entry RET org-export-dispatch RET. Then I exported using C-C e. I did not get a meaningful traceback as I couldn't enter the n-n argument.

jkitchin commented 6 years ago

M-x toggle-debug-on-error

and then C-c C-e n n

that should lead to a buffer with a traceback in it.

hcmbg commented 6 years ago

Debugger entered--Lisp error: (args-out-of-range "" 1) string-match("^\(\+\)\(?: +\(.?\)\)?[ ]$" "" 1) s-slice-at("^\(\*+\)\(?: +\(.?\)\)?[ ]$" "") (let ((s1 (s-slice-at org-heading-regexp s)) (s2 (let ((--cl-var-- s1) (string nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq string (car --cl-var--)) (setq --cl-var-- (nconc (reverse ...) --cl-var--)) (setq --cl-var-- (cdr --cl-var--))) (nreverse --cl-var--))) (s3 (let ((--cl-var-- s2) (string nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq string (car --cl-var--)) (setq --cl-var-- (nconc (reverse ...) --cl-var--)) (setq --cl-var-- (cdr --cl-var--))) (nreverse --cl-var--)))) s3) ox-ipynb-split-text("") (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let ((md (ox-ipynb-export-markdown-cell (s-trim s)))) (setq cells (cons md cells)))) (setq --cl-var-- (cdr --cl-var--))) nil) (let ((text (buffer-substring-no-properties end (point-max)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let ((md (ox-ipynb-export-markdown-cell ...))) (setq cells (cons md cells)))) (setq --cl-var-- (cdr --cl-var--))) nil)) (if current-source (if (not (string= "" (s-trim (buffer-substring end (org-element-property :begin (car current-source)))))) (progn (let ((text (buffer-substring-no-properties end (org-element-property :begin ...)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let ... ...)) (setq --cl-var-- (cdr --cl-var--))) nil)))) (let ((text (buffer-substring-no-properties end (point-max)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let ((md ...)) (setq cells (cons md cells)))) (setq --cl-var-- (cdr --cl-var--))) nil))) (while current-source (setq cells (cons (ox-ipynb-export-code-cell current-source) cells)) (setq result-end (cdr current-source) result (car result-end) result-end (cdr result-end)) (setq end (max (or result-end 0) (org-element-property :end (car current-source)))) (setq current-source (car-safe (prog1 src-results (setq src-results (cdr src-results))))) (if current-source (if (not (string= "" (s-trim (buffer-substring end (org-element-property :begin ...))))) (progn (let ((text (buffer-substring-no-properties end ...))) (let ((--cl-var-- ...) (s nil)) (while (consp --cl-var--) (setq s ...) (if ... ... ...) (setq --cl-var-- ...)) nil)))) (let ((text (buffer-substring-no-properties end (point-max)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let (...) (setq cells ...))) (setq --cl-var-- (cdr --cl-var--))) nil)))) (let ((cells (if (ox-ipynb-export-keyword-cell) (list (ox-ipynb-export-keyword-cell)) (quote nil))) (ox-ipynb-language (ox-ipynb-get-language)) (metadata (list (quote metadata) (cons (quote org) (let ((all-keywords ...) (ipynb-keywords ...) (include-keywords ...) (keywords ...)) keywords)) (cdr (assoc ox-ipynb-language ox-ipynb-kernelspecs)) (cdr (assoc ox-ipynb-language ox-ipynb-language-infos)))) (ipynb (or (and (boundp (quote export-file-name)) export-file-name) (concat (file-name-base (buffer-file-name)) ".ipynb"))) src-blocks src-results current-src result result-end end data) (setq src-blocks (org-element-map (org-element-parse-buffer) (quote src-block) (function (lambda (src) (if (string= (symbol-name ox-ipynb-language) (org-element-property :language src)) (progn src)))))) (setq src-results (let ((--cl-var-- src-blocks) (src nil) (result=nil nil) (--cl-var-- nil)) (while (consp --cl-var--) (setq src (car --cl-var--)) (setq result (save-excursion (goto-char (org-element-property :begin src)) (let (... start end result-content) (if location ...)))) (setq --cl-var-- (cons (cons src result) --cl-var--)) (setq --cl-var-- (cdr --cl-var--))) (nreverse --cl-var--))) (setq current-source (car-safe (prog1 src-results (setq src-results (cdr src-results))))) (if (car current-source) (if (string= "" (s-trim (buffer-substring-no-properties (point-min) (org-element-property :begin (car current-source))))) nil (let ((text (buffer-substring-no-properties (point-min) (org-element-property :begin ...)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" ...) (progn) (when-let ... ...)) (setq --cl-var-- (cdr --cl-var--))) nil))) (let ((text (buffer-substring-no-properties (point-min) (point-max)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" (s-trim s)) (progn) (when-let (...) (setq cells ...))) (setq --cl-var-- (cdr --cl-var--))) nil))) (while current-source (setq cells (cons (ox-ipynb-export-code-cell current-source) cells)) (setq result-end (cdr current-source) result (car result-end) result-end (cdr result-end)) (setq end (max (or result-end 0) (org-element-property :end (car current-source)))) (setq current-source (car-safe (prog1 src-results (setq src-results (cdr src-results))))) (if current-source (if (not (string= "" (s-trim (buffer-substring end ...)))) (progn (let ((text ...)) (let (... ...) (while ... ... ... ...) nil)))) (let ((text (buffer-substring-no-properties end (point-max)))) (let ((--cl-var-- (ox-ipynb-split-text text)) (s nil)) (while (consp --cl-var--) (setq s (car --cl-var--)) (if (string= "" s) (progn) (when-let ... ...)) (setq --cl-var-- (cdr --cl-var--))) nil)))) (setq data (append (list (cons (quote cells) (reverse cells))) (list metadata) (quote ((nbformat . 4) (nbformat_minor . 0))))) (save-current-buffer (set-buffer (get-buffer-create "ox-ipynb")) (erase-buffer) (insert (json-encode data))) (switch-to-buffer "ox-ipynb") (set (make-local-variable (quote export-file-name)) ipynb) (get-buffer "ox-ipynb")) ox-ipynb-export-to-buffer() (setq buf (ox-ipynb-export-to-buffer)) (save-current-buffer (set-buffer "Org ORG Export") (set (make-local-variable (quote export-file-name)) ipynb) (setq buf (ox-ipynb-export-to-buffer)) (save-current-buffer (set-buffer buf) (set (make-local-variable (quote export-file-name)) ipynb)) (prog1 buf (kill-buffer "Org ORG Export"))) (let ((ipynb (or (if (boundp (quote export-file-name)) (progn export-file-name)) (concat (file-name-base (buffer-file-name)) ".ipynb"))) buf) (org-org-export-as-org async subtreep visible-only body-only info) (save-current-buffer (set-buffer "Org ORG Export") (set (make-local-variable (quote export-file-name)) ipynb) (setq buf (ox-ipynb-export-to-buffer)) (save-current-buffer (set-buffer buf) (set (make-local-variable (quote export-file-name)) ipynb)) (prog1 buf (kill-buffer "Org ORG Export")))) ox-ipynb-export-to-ipynb-buffer(nil nil nil nil nil) (set-buffer (ox-ipynb-export-to-ipynb-buffer async subtreep visible-only body-only info)) (save-current-buffer (set-buffer (ox-ipynb-export-to-ipynb-buffer async subtreep visible-only body-only info)) (let ((efn export-file-name) (buf (find-file-noselect efn))) (write-file efn) (save-current-buffer (set-buffer buf) (set (make-local-variable (quote export-file-name)) efn)) (kill-buffer buf) efn)) ox-ipynb-export-to-ipynb-file(nil nil nil nil) funcall(ox-ipynb-export-to-ipynb-file nil nil nil nil) (save-excursion (if arg (progn (if (eq (marker-buffer org-export-dispatch-last-position) (org-base-buffer (current-buffer))) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq (quote async) optns) t) (and (memq (quote subtree) optns) t) (and (memq (quote visible) optns) t) (and (memq (quote body) optns) t))) (cond ((eql action (quote template)) (org-export-insert-default-template nil optns)) ((eql action (quote stack)) (org-export-stack)) ((eql action (quote publish-current-file)) (org-publish-current-file (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-current-project)) (org-publish-current-project (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-choose-project)) (org-publish (assoc (completing-read "Publish project: " org-publish-project-alist nil t) org-publish-project-alist) (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-all)) (org-publish-all (memq (quote force) optns) (memq (quote async) optns))) (t (save-excursion (if arg (progn (if (eq (marker-buffer org-export-dispatch-last-position) (org-base-buffer ...)) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq (quote async) optns) t) (and (memq (quote subtree) optns) t) (and (memq (quote visible) optns) t) (and (memq (quote body) optns) t))))) (let* ((input (cond ((equal arg (quote (16))) (quote (stack))) ((and arg org-export-dispatch-last-action)) (t (let ((wconfig ...)) (unwind-protect (progn ...) (set-window-configuration wconfig)))))) (action (car input)) (optns (cdr input))) (if (memq (quote subtree) optns) nil (move-marker org-export-dispatch-last-position nil)) (cond ((eql action (quote template)) (org-export-insert-default-template nil optns)) ((eql action (quote stack)) (org-export-stack)) ((eql action (quote publish-current-file)) (org-publish-current-file (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-current-project)) (org-publish-current-project (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-choose-project)) (org-publish (assoc (completing-read "Publish project: " org-publish-project-alist nil t) org-publish-project-alist) (memq (quote force) optns) (memq (quote async) optns))) ((eql action (quote publish-all)) (org-publish-all (memq (quote force) optns) (memq (quote async) optns))) (t (save-excursion (if arg (progn (if (eq ... ...) (goto-char org-export-dispatch-last-position) (move-marker org-export-dispatch-last-position nil)))) (funcall action (and (memq (quote async) optns) t) (and (memq (quote subtree) optns) t) (and (memq (quote visible) optns) t) (and (memq (quote body) optns) t)))))) org-export-dispatch(nil) funcall-interactively(org-export-dispatch nil) call-interactively(org-export-dispatch nil nil) command-execute(org-export-dispatch)

jkitchin commented 6 years ago

hm. that is an error in s.el.

What do you get from:

M-x describe-package s

hcmbg commented 6 years ago

Here is what I get:

dash is a dependency package.

     Status: Installed in ‘dash-20170810.137/’ (unsigned).
    Version: 20170810.137
    Summary: A modern list library for Emacs
Required by: pythonic-20160221.1123, ob-ipython-20170628.1116, f-20170404.1039,
               ein-20170810.1253, dash-functional-20160615.1351,
               company-anaconda-20160809.705, anaconda-mode-20170405.301,
               ac-anaconda-20160221.1123
   Keywords: lists 
Other versions: 20170810.137 (melpa), 2.12.0 (gnu), 2.11.0 (marmalade).
jkitchin commented 6 years ago

I meant the s library.

hcmbg commented 6 years ago

You mean M-x describe-package s?

s is a dependency package.

     Status: Installed in ‘s-1.11.0/’ (unsigned).
    Version: 1.11.0
    Summary: The long lost Emacs string manipulation library.
Required by: pythonic-20160221.1123, ob-ipython-20170628.1116, f-20170404.1039,
               elpy-20170701.1412, company-anaconda-20160809.705,
               anaconda-mode-20170405.301
   Keywords: strings 
Other versions: 20170428.1026 (melpa), 1.10.0 (marmalade).
jkitchin commented 6 years ago

hm. can you try updating that from Melpa? I have a newer version that does not have that problem.

hcmbg commented 6 years ago

I updated to "s-20170428.1026" and it works! Thank you so much for your help.

jkitchin commented 6 years ago

Great!

dmankins commented 6 years ago

Hi, I am running emacs version 25.3.2 on Ubuntu Linux 16.

I get told that "Symbol's function definition is void: s-slice-at

M-x describe-package s just prompts me to keep typing (there are many packages that begin with 's', it seems).

So, I installed melpa, restarted emacs, executed a (require 's), and now I am told: that 'json-encode' is undefined. Google for 'json-encode emacs' sends me here:https://www.emacswiki.org/emacs/JSON, which says json.el is built-in, so:

I think you need to add:

(require 's) (require 'json)

to ox-ipynb.el

Thanks! I'm looking forward to using this package!

jkitchin commented 6 years ago

Thanks for mentioning this. I think the commit 80ad4f1 I just added addresses this.