mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 07:41:37 -05:00
jupyter-org--append-to-example-block: Fix edge case
Fix the case when appending to a line without inserting a newline and adding indentation. Also add tests for `jupyter-org--append-to-example-block`
This commit is contained in:
parent
66f806f478
commit
9f15db7133
2 changed files with 95 additions and 5 deletions
|
@ -1253,11 +1253,19 @@ RESULT."
|
|||
(when (and (not org-src-preserve-indentation)
|
||||
(/= 0 org-edit-src-content-indentation)
|
||||
(version<= "9.2" (org-version)))
|
||||
(let ((ind (make-string org-edit-src-content-indentation ?\s)))
|
||||
(setq result (replace-regexp-in-string
|
||||
(let ((ind (make-string org-edit-src-content-indentation ?\s))
|
||||
head tail)
|
||||
(if keep-newline
|
||||
(setq head ""
|
||||
tail result)
|
||||
(let ((first-newline (save-match-data
|
||||
(string-match "\n" result))))
|
||||
(setq head (substring result 0 (1+ first-newline))
|
||||
tail (substring result (1+ first-newline)))))
|
||||
(setq result (concat head (replace-regexp-in-string
|
||||
"^[ \t]*\\S-"
|
||||
(concat ind "\\&")
|
||||
(org-remove-indentation result)))))
|
||||
(org-remove-indentation tail))))))
|
||||
(insert (concat (when keep-newline "\n") result)))
|
||||
|
||||
(defun jupyter-org--append-stream-result (result)
|
||||
|
|
|
@ -2012,6 +2012,88 @@ file:foo
|
|||
: b
|
||||
"))))
|
||||
|
||||
(defvar org-edit-src-preserve-indentation)
|
||||
(defvar org-src-preserve-indentation)
|
||||
|
||||
(ert-deftest jupyter-org--append-to-example-block ()
|
||||
:tags '(org)
|
||||
(let ((org-src-preserve-indentation 0))
|
||||
(with-temp-buffer
|
||||
(org-mode)
|
||||
(insert "\
|
||||
#+begin_example
|
||||
|
|
||||
#+end_example
|
||||
")
|
||||
(search-backward "|")
|
||||
(forward-char)
|
||||
(jupyter-org--append-to-example-block "a\nb" nil)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|a
|
||||
b
|
||||
#+end_example
|
||||
"))
|
||||
(backward-char)
|
||||
(jupyter-org--append-to-example-block "a\nb" t)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|a
|
||||
b
|
||||
a
|
||||
b
|
||||
#+end_example
|
||||
"))))
|
||||
(when (version<= "9.2" (org-version))
|
||||
(let ((org-src-preserve-indentation nil)
|
||||
(org-edit-src-preserve-indentation 2))
|
||||
(ert-info ("Example block indentation")
|
||||
(with-temp-buffer
|
||||
(org-mode)
|
||||
(insert "\
|
||||
#+begin_example
|
||||
|
|
||||
#+end_example
|
||||
")
|
||||
(search-backward "|")
|
||||
(forward-char)
|
||||
(jupyter-org--append-to-example-block "ab" nil)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|ab
|
||||
#+end_example
|
||||
"))
|
||||
(backward-char)
|
||||
(jupyter-org--append-to-example-block "ab" t)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|ab
|
||||
ab
|
||||
#+end_example
|
||||
"))
|
||||
(backward-char)
|
||||
;; TODO: What to about the case of removing the common indentation
|
||||
;; while appending to a line?
|
||||
(jupyter-org--append-to-example-block " a\n b" nil)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|ab
|
||||
ab a
|
||||
b
|
||||
#+end_example
|
||||
"))
|
||||
(backward-char)
|
||||
(jupyter-org--append-to-example-block " a\n b" t)
|
||||
(should (equal (buffer-string) "\
|
||||
#+begin_example
|
||||
|ab
|
||||
ab a
|
||||
b
|
||||
a
|
||||
b
|
||||
#+end_example
|
||||
")))))))
|
||||
|
||||
(ert-deftest jupyter-org-indent-inserted-region ()
|
||||
:tags '(org)
|
||||
(with-temp-buffer
|
||||
|
|
Loading…
Add table
Reference in a new issue