From 280b19d61425b83e335d22e643ba7b11048c4146 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Tue, 17 Jun 2025 17:21:04 +0200 Subject: [PATCH] fix ob-python --- lisp/my/my.el | 13 ++++++++++++- scripts/test/test.org | 32 ++++++++++++++++++++++++++++++-- settings/org-settings.el | 7 ++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lisp/my/my.el b/lisp/my/my.el index 343a92a7..c9f621b5 100644 --- a/lisp/my/my.el +++ b/lisp/my/my.el @@ -91,7 +91,8 @@ *Table* [[help:org-shiftleft][Move cell left]] .......... =S-left= [[help:org-shiftup][Move cell up]] .............. =S-up= [[help:org-shiftright][Move cell right]] ........ =S-right= [[help:org-shiftdown][Move cell down]] .......... =S-down= - [[help:org-table-blank-field][Clear cell]] ................. =SPC= + [[help:org-table-blank-field][Clear cell]] ................. =SPC= [[help:org-table-shrink][Shrink columns]] ..... =C-u C-c TAB= + [[help:org-table-toggle-column-width][Shrink/expand column]] ... =C-c TAB= [[help:org-table-expand][Expand columns]] . =C-u C-u C-c TAB= [[help:org-table-create-or-convert-from-region][Convert seperator (1. tab, 2. comma, 3. space)]] ............... =C-c= =|= , comma .............. =C-u= =C-c= =|= , tab separator .. =C-u= =C-u= =C-c= =|= @@ -130,6 +131,7 @@ - [[help:eval-last-sexp][last to echo]] ......... =C-x= =C-e= [[help:backward-sexp][Jump tp prev. expression]] . =C-M-b= - [[help:eval-print-last-sexp][last to buffer]] [[help:kill-sexp][Cut expression]] ........... =C-M-k= [[help:mark-sexp][Mark expression]] .......... =C-M-@= [[help:backward-kill-sexp][Cut last expression]] . =C-M-backsp= + [[help:counsel-set-variable][Set variable]] .............. =F2 j= *IBuffer* @@ -310,6 +312,15 @@ print it in the message buffer." ;; https://emacs.stackexchange.com/questions/7375/can-i-format-cells-in-an-org-mode-table-differently-depending-on-a-formula (require 'ov) + (defun my-org-toggle-emphasis () + "Toggle hiding/showing of org emphasize markers." + (interactive) + (if org-hide-emphasis-markers + (set-variable 'org-hide-emphasis-markers nil) + (set-variable 'org-hide-emphasis-markers t)) + (org-mode-restart)) + (define-key org-mode-map (kbd "C-c C-x C-e") 'my-org-toggle-emphasis) + (defun my-org-keywords () "Parse the buffer and return a cons list of (key . value) from lines like: diff --git a/scripts/test/test.org b/scripts/test/test.org index 903811ac..71cac32e 100644 --- a/scripts/test/test.org +++ b/scripts/test/test.org @@ -1,6 +1,7 @@ +* syntax highlighting -* graphviz dot +** graphviz dot #+begin_src dot digraph G { main -> parse -> execute; @@ -14,7 +15,7 @@ digraph G { } #+end_src -* gnuplot +** gnuplot #+begin_src gnuplot :results silent reset @@ -35,3 +36,30 @@ h(x) = 10*sqrt(abs(x)) plot f(x) w lp lw 1, g(x) w p lw 2, h(x) w l lw 3 #+end_src + + +* custom header + +** python + +- interactive inside org +- html export creates a svg file +- latex export creates a pgf file + +#+HEADER: :var fname=(mpl-var "img/peltier-characteristic") +#+HEADER: :epilogue (by-backend (html "fig.savefig(fname);print(fname, end='')") (t "plt.show()")) +#+HEADER: :results (by-backend (html "output file") (t "none")) +#+begin_src python :exports results +import numpy as np +import matplotlib.pyplot as plt +x = [-4, -3, -2, -1, 0, 1, 2, 3] +y1 = [-11.2, -11.6, -7.0, 3.2, 18.3, 39.0, 68.2, 125.0] +y2 = [-8.2, -8.3, -3.9, 7.3, 22.9, 47.3, 87.1, 136.2] +fig, ax = plt.subplots(1, 1, dpi=100, layout='constrained', figsize=[6.4*1.5/2, 4.8*1.5/2]) +ax.plot(x, y1, '.-', label='15°C') +ax.plot(x, y2, '.-', label='20°C') +ax.legend() +ax.set_xlabel('Electrical current, A') +ax.set_ylabel('Temperature, °C') +ax.set_title('Characteristic curve of the peltier element') +#+end_src diff --git a/settings/org-settings.el b/settings/org-settings.el index 83321036..7ab9f3dd 100644 --- a/settings/org-settings.el +++ b/settings/org-settings.el @@ -955,7 +955,12 @@ usage: #+HEADER: :results (tpl-results) ) (use-package ob-python - :defer t + :after (org-src python) + ;; :commands (org-babel-execute:python + ;; org-babel-variable-assignments:python) + ;; :init + ;; (with-eval-after-load 'org + ;; (add-to-list 'org-babel-load-languages '(python . t))) :config (defun mpl-var (filename) "\