Add `zero-all-org-src-blocks-indentation' and improve editing
This commit is contained in:
parent
c51224323e
commit
d8df141bde
150
README.org
150
README.org
@ -879,6 +879,7 @@ defined in this Org file.
|
||||
(org-inactive-current-time-stamp :nomanual t)
|
||||
(org-syntax-convert-keyword-case-to-lower :no-manual t)
|
||||
(smart-latex-engrave-org-source-blocks :no-manual t)
|
||||
(zero-all-org-src-blocks-indentation :no-manual t)
|
||||
"Python"
|
||||
(choose-common-python-interpreter :no-manual t))))
|
||||
#+end_src
|
||||
@ -1952,20 +1953,26 @@ zeromatrix zmat")))
|
||||
:CUSTOM_ID: sec:customize-org
|
||||
:END:
|
||||
|
||||
Listing [[lst:customize-org-babel]], [[lst:customize-org]], [[lst:customize-org-src]],
|
||||
[[lst:customize-org-link]] does basic customization of [[https://orgmode.org/][Org-mode]] variables, where
|
||||
listing [[lst:customize-org-src]] facilitates [[info:org#Editing Source Code][editing Python source code blocks]]. In
|
||||
addition, listing [[lst:customize-org-babel]] selects the Python interpreter by
|
||||
means of src_emacs-lisp{(choose-common-python-interpreter)} defined in listing
|
||||
[[lst:choose-common-python-interpreter]]. Listing
|
||||
[[lst:customize-org-for-lualatex-export]], and
|
||||
Listing [[lst:customize-org-babel]], [[lst:customize-org]], [[lst:customize-org-link]], and
|
||||
[[lst:customize-org-src]] handle basic customization of [[https://orgmode.org/][Org-mode]] variables, where:
|
||||
1. listing [[lst:customize-org-babel]] selects the Python interpreter by means of
|
||||
src_emacs-lisp{(choose-common-python-interpreter)} defined in listing
|
||||
[[lst:choose-common-python-interpreter]].
|
||||
2. listing [[lst:customize-org-src]] facilitates [[info:org#Editing Source Code][editing Python source code blocks]] and
|
||||
provides a function to remove the indentation of all =org-src-mode= blocks
|
||||
without =-i= switch.
|
||||
Listing [[lst:configure-org-mode-map]] extends the =org-mode-map= with useful
|
||||
key-bindings. Listing [[lst:customize-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]]. Listing
|
||||
[[lst:customize-org-export-ui]] selects the expert user interface for export
|
||||
dispatching. Listing [[lst:customize-org-for-lualatex-export]], and
|
||||
[[lst:customize-ox-latex-for-lualatex-export]] configure [[https://orgmode.org/][Org-mode]] for export to
|
||||
LuaLaTeX. Listing [[lst:customize-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]]. Listing
|
||||
[[lst:customize-org-link]] configures =org-link= to use relative file path links.
|
||||
Listing [[lst:customize-org-latex-classes]] defines [[info:org#LaTeX specific export settings][org-latex-classes (info)]] for
|
||||
backward compatibility. See table [[tab:org-latex-class-tag-placeholder]] and type
|
||||
{{{kbd(C-h v org-latex-classes)}}} for an explanation of the code in listing
|
||||
LuaLaTeX. Listing [[lst:customize-org-link]] configures =org-link= to use relative
|
||||
file path links.
|
||||
Listing [[lst:customize-org-latex-classes]] defines [[info:org#LaTeX
|
||||
specificexportsettings][org-latex-classes (info)]] for backward
|
||||
compatibility. See table [[tab:org-latex-class-tag-placeholder]] and type {{{kbd(C-h
|
||||
v org-latex-classes)}}} for an explanation of the code in listing
|
||||
[[lst:customize-org-latex-classes]].
|
||||
|
||||
#+attr_latex: :booktabs yes :float table
|
||||
@ -2010,45 +2017,6 @@ backward compatibility. See table [[tab:org-latex-class-tag-placeholder]] and ty
|
||||
(choose-common-python-interpreter 'python))
|
||||
#+end_src
|
||||
|
||||
#+caption[Customize =ob-python=]:
|
||||
#+caption: Customize =ob-python=.
|
||||
#+name: lst:customize-ob-python
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'ob-python
|
||||
(defun org-babel-python-format-session-value-override
|
||||
(src-file result-file result-params)
|
||||
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE.
|
||||
Use `black' instead of `pprint' when \"pp\" is a member of RESULT-PARAMS."
|
||||
(format "\
|
||||
import ast
|
||||
with open('%s') as __org_babel_python_tmpfile:
|
||||
__org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
|
||||
__org_babel_python_final = __org_babel_python_ast.body[-1]
|
||||
if isinstance(__org_babel_python_final, ast.Expr):
|
||||
__org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
|
||||
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
|
||||
__org_babel_python_final = eval(
|
||||
compile(ast.Expression(__org_babel_python_final.value), '<string>', 'eval')
|
||||
)
|
||||
with open('%s', 'w') as __org_babel_python_tmpfile:
|
||||
if %s:
|
||||
import black
|
||||
__org_babel_python_tmpfile.write(
|
||||
black.format_str(repr(__org_babel_python_final), mode=black.Mode())
|
||||
)
|
||||
else:
|
||||
__org_babel_python_tmpfile.write(str(__org_babel_python_final))
|
||||
else:
|
||||
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
|
||||
__org_babel_python_final = None"
|
||||
(org-babel-process-file-name src-file 'noquote)
|
||||
(org-babel-process-file-name result-file 'noquote)
|
||||
(if (member "pp" result-params) "True" "False")))
|
||||
|
||||
(advice-add 'org-babel-python-format-session-value
|
||||
:override #'org-babel-python-format-session-value-override))
|
||||
#+end_src
|
||||
|
||||
#+caption[Customize =Org=]:
|
||||
#+caption: Customize =Org=.
|
||||
#+name: lst:customize-org
|
||||
@ -2099,13 +2067,43 @@ else:
|
||||
("v" . "verse")))))
|
||||
#+end_src
|
||||
|
||||
|
||||
#+caption[Customize =org-link=]:
|
||||
#+caption: Customize =org-link=.
|
||||
#+name: lst:customize-org-link
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'ol
|
||||
(custom-set-variables
|
||||
'(org-link-file-path-type 'relative)))
|
||||
#+end_src
|
||||
|
||||
#+caption[Customize =org-src=]:
|
||||
#+caption: Customize =org-src=.
|
||||
#+name: lst:customize-org-src
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'org-src
|
||||
(with-eval-after-load 'emacs
|
||||
(custom-set-variables
|
||||
'(org-src-preserve-indentation t)))
|
||||
'(org-src-preserve-indentation t))
|
||||
|
||||
(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))
|
||||
|
||||
(defun zero-all-org-src-blocks-indentation ()
|
||||
"Remove the indentation of all `org-src-mode' blocks without `-i' switch."
|
||||
(interactive)
|
||||
(when (derived-mode-p 'org-mode)
|
||||
(save-excursion
|
||||
(org-babel-map-src-blocks
|
||||
nil
|
||||
(unless (or (string-match "-i " switches)
|
||||
(string-match (rx (or bos bol) graph) body))
|
||||
(when-let ((new (with-temp-buffer
|
||||
(insert body)
|
||||
(org-do-remove-indentation)
|
||||
(buffer-string))))
|
||||
(goto-char beg-body)
|
||||
(delete-region beg-body end-body)
|
||||
(insert new))))))))
|
||||
#+end_src
|
||||
|
||||
#+caption[Configure =org-mode-map=]:
|
||||
@ -2154,18 +2152,48 @@ When called twice, replace the previously inserted \\(\\) by one $."
|
||||
(define-key org-mode-map (kbd "M-q") #'org-fill-paragraph)))
|
||||
#+end_src
|
||||
|
||||
#+caption[Customize =org-link=]:
|
||||
#+caption: Customize =org-link=.
|
||||
#+name: lst:customize-org-link
|
||||
#+caption[Customize =ob-python=]:
|
||||
#+caption: Customize =ob-python=.
|
||||
#+name: lst:customize-ob-python
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'ol
|
||||
(custom-set-variables
|
||||
'(org-link-file-path-type 'relative)))
|
||||
(with-eval-after-load 'ob-python
|
||||
(defun org-babel-python-format-session-value-override
|
||||
(src-file result-file result-params)
|
||||
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE.
|
||||
Use `black' instead of `pprint' when \"pp\" is a member of RESULT-PARAMS."
|
||||
(format "\
|
||||
import ast
|
||||
with open('%s') as __org_babel_python_tmpfile:
|
||||
__org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
|
||||
__org_babel_python_final = __org_babel_python_ast.body[-1]
|
||||
if isinstance(__org_babel_python_final, ast.Expr):
|
||||
__org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
|
||||
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
|
||||
__org_babel_python_final = eval(
|
||||
compile(ast.Expression(__org_babel_python_final.value), '<string>', 'eval')
|
||||
)
|
||||
with open('%s', 'w') as __org_babel_python_tmpfile:
|
||||
if %s:
|
||||
import black
|
||||
__org_babel_python_tmpfile.write(
|
||||
black.format_str(repr(__org_babel_python_final), mode=black.Mode())
|
||||
)
|
||||
else:
|
||||
__org_babel_python_tmpfile.write(str(__org_babel_python_final))
|
||||
else:
|
||||
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
|
||||
__org_babel_python_final = None"
|
||||
(org-babel-process-file-name src-file 'noquote)
|
||||
(org-babel-process-file-name result-file 'noquote)
|
||||
(if (member "pp" result-params) "True" "False")))
|
||||
|
||||
(advice-add 'org-babel-python-format-session-value
|
||||
:override #'org-babel-python-format-session-value-override))
|
||||
#+end_src
|
||||
|
||||
#+caption[Customize =org-export=]:
|
||||
#+caption: Customize =org-export=.
|
||||
#+name: lst:customize-org-export
|
||||
#+name: lst:customize-org-export-ui
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'ox
|
||||
(custom-set-variables
|
||||
|
Loading…
Reference in New Issue
Block a user