Editing blocks section

This commit is contained in:
Howard Abrams 2024-08-04 22:10:44 -07:00
parent f81f9b4487
commit accf51fcc1

View file

@ -169,6 +169,30 @@ Note: If you are reading this in an Emacs buffer, you can also place your cursor
At this point, you can begin a line with =<s= and hit ~TAB~ to have a src block expanded, with the cursor left at the end of first line, allowing you to type =emacs-lisp=.
This is Emacs, you probably have your favorite template expansion, like [[https://elpa.gnu.org/packages/doc/tempel/tempel.html][TempEL]] or [[https://www.emacswiki.org/emacs/Yasnippet][Yasnippet]], as any system that can generate your text works fine.The magic isnt hidden in markers, but shines plainly in the text itself.
** Editing src Blocks
I find editing prose in an Org file quite nice…editing code? Not so much. Many techniques you expect to use, like jumping to code definitions with the [[info:emacs#Looking Up Identifiers][Xref system]] or manipulating s-expressions in a Lisp with =paredit= or =smart-parens=, arent available.
With your cursor anywhere, the header line, anywhere in the body or one the =end_src= line, type ~C-c '~ to narrow to contents of that block with a mode based on the language on the header line.
Whew, now you can edit your code in a manner you expect. Type ~C-c '~ again to save and return to your full org buffer, or ~C-c C-k~ to cancel your changes.
Lets add more [[info:org#Languages][languages]] to what is available, by running the following code:
#+begin_src emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(python . t)))
#+end_src
Feel free to substitute the =python=, for your favorite language, or add more. Use =sh= for shell scripts, and =js= for Javascript. See [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][Babel]] for details on languages that can be supported.
*Note:* If you dont see you languages pretty colors for its syntax, run this code (and put it in your init file):
#+begin_src emacs-lisp
(setq org-src-fontify-natively t)
#+end_src
* Working with Python
* Calling out to the Shell