Compare commits

...

2 Commits

Author SHA1 Message Date
Gerard Vermeulen 6a0ff3b12d Add "Testing Org" section 2024-01-17 12:56:00 +01:00
Gerard Vermeulen 03911e076b Add `org-right-shift-block' 2024-01-17 12:23:17 +01:00
1 changed files with 108 additions and 3 deletions

View File

@ -2306,9 +2306,8 @@ list detailing and motivating each listing:
[[info:org#Hyperlinks][hyperlinks (info)]].
5. Listing [[lst:setup-org-mode-map]] extends the =org-mode-map= with useful
key-bindings.
6. Listing [[lst:setup-org-src]] facilitates [[info:org#Editing Source Code][editing Python source code blocks]],
and it provides a function to remove the indentation of all =org-src-mode=
blocks without =-i= switch.
6. Listing [[lst:setup-org-src]] facilitates [[info:org#Editing Source Code][editing source code blocks]], and it
provides functions to change the indentation of all =org-src-mode= blocks.
7. Listing [[lst:setup-ob-python]] allows to pretty-print Python session source
block values with [[https://github.com/psf/black#readme][black]] instead of [[https://docs.python.org/3/library/pprint.html][pprint]]. This snippet may break in the
future, because it sets =org-babel-python--def-format-value= which is a
@ -2504,6 +2503,21 @@ When called twice, replace the previously inserted \\(\\) by one $."
(org-src-preserve-indentation nil))
(org-indent-block))))
(defun org-right-shift-block (&optional arg)
"Right-shift the block at point 4 spaces.
With prefix argument ARG, prompt for the number of spaces."
(interactive "P")
(let ((spaces 4)
(start (org-babel-where-is-src-block-head)))
(if (not start) (message "Not at block")
(when arg
(setq spaces (read-number "Number of spaces: ")))
;; The `SUBEXP' of the block body is 5.
(goto-char (match-end 5))
(forward-line -1)
(string-insert-rectangle
(match-beginning 5) (point) (make-string spaces ?\s)))))
(declare-function org-babel-map-src-blocks "ext:ob-core" (file &rest body))
(declare-function org-do-remove-indentation "ext:org-macs" (n skip-fl))
@ -3671,6 +3685,97 @@ define the [[https://orgmode.org/][Org mode]] =kbd= macro in listing
(latex (format "@@latex:\\colorbox{PowderBlue}{\\texttt{%s}}@@" keys)))))
#+end_src
*** [[https://orgmode.org/worg/org-tests/index.html][Testing Org]]
:PROPERTIES:
:CUSTOM_ID: sec:testing-org
:END:
Listing [[lst:setup-org-mode-test-1]] and [[lst:setup-org-mode-test-2]] provide
facilities for [[https://orgmode.org/worg/org-tests/index.html][Testing Org]].
#+caption[Testing Org facilities 1]:
#+caption: Testing Org facilities 1.
#+name: lst:setup-org-mode-test-1
#+begin_src emacs-lisp -n
(with-eval-after-load 'emacs
(defvar org-testing-dir nil)
(defvar org-testing-lisp-files nil)
(defun setup-org-mode-test ()
"Intialize an `org-mode' test."
(interactive)
(unless (and org-testing-dir org-testing-lisp-files)
(find-library "org.el")
(quit-window)
(setq org-testing-dir
(file-name-concat
(file-name-directory
(directory-file-name
(file-name-directory
(buffer-file-name (get-buffer "org.el")))))
(file-name-as-directory "testing")))
(message "`%s'" org-testing-dir)
(setq org-testing-lisp-files
(seq-filter
(lambda (f)
(string-suffix-p ".el" f))
(directory-files
(file-name-concat org-testing-dir
(file-name-as-directory "lisp")))))
(message "`%s'" org-testing-lisp-files))
(unless (fboundp 'org-test-with-temp-text)
(find-file (file-name-concat org-testing-dir "org-test.el"))
(eval-buffer)
(quit-window))
(let* ((test
(completing-read "Org-mode test: "
org-testing-lisp-files nil 'require-match))
(file ))
(find-file (file-name-concat
org-testing-dir (file-name-as-directory "lisp") test))
(eval-buffer)
(message "Evaluated '%s'"
(file-name-nondirectory (buffer-file-name (get-buffer test))))
(quit-window))))
#+end_src
#+caption[Testing Org facilities 2]:
#+caption: Testing Org facilities 2.
#+name: lst:setup-org-mode-test-2
#+begin_src emacs-lisp -n
(with-eval-after-load 'emacs
(defun org-test-run-some-tests ()
"Run some defined tests.
Load all test files first."
(interactive)
(org-test-touch-all-examples)
(org-test-update-id-locations)
(org-test-load)
(let (;; Catch errors in diary sexps better.
(calendar-debug-sexp t))
;; test-org-element/normalize-contents fails (can't fix).
;; test-ob-exp/noweb-on-export fails due to spacing (can't fix).
;; test-ob-exp/noweb-on-export-with-exports-results due to spacing (idem).
;; ob-maxima fixed but spacing is fragile. Which Maxima?
;; ob-python hangs sometimes, but very seldom.
;; ob-tangle/continued-code-blocks-w-noweb-ref fails.
(ert (rx (or "org/" "org-fold" "org-element" "org-macro" "org-src"
"property-inheritance"
"ob/" "ob-emacs-lisp" "ob-eshell" "ob-maxima"
"ob-python" "ob-tangle")))
(org-test-kill-all-examples)))
(defun org-test-run-ob-tests ()
"Run all \"ob\" tests.
Load all test files first."
(interactive)
(org-test-load)
(let (;; Catch errors in diary sexps better.
(calendar-debug-sexp t))
(ert "ob/"))))
#+end_src
*** [[info:org#Export Settings][File inclusion (info)]] and [[info:org#Noweb Reference Syntax][Noweb (info)]] trickery
:PROPERTIES:
:CUSTOM_ID: sec:file-inclusion-and-noweb