[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] [babel] demonstration mode-switching between code blocks
From: |
Torsten Wagner |
Subject: |
[Orgmode] [babel] demonstration mode-switching between code blocks |
Date: |
Wed, 4 Nov 2009 15:03:50 +0900 |
User-agent: |
KMail/1.12.2 (Linux/2.6.31-14-generic; KDE/4.3.2; x86_64; ; ) |
Hi everybody,
Abstract: This is a very quick (and I assume very dirty) hack, how to switch
between org-mode and any other mode which you like to use in the source code
blocks. It is far from being addable to org-babel yet but might be a good
starting point.
Problem: If I use source code blocks together with org-mode and org-babel, I
miss sometimes the nice features of the original language mode in emacs.
E.g. In python-mode there is syntax-highlighting for python (obviously). In
org-mode the python syntax is simply unicolor which results (for me) in error
prone usage same for proper line indentation (which is critical in python).
Furthermore, switching frequently between org-mode and python code, key-
bindings which got used by both modes (e.g. the famous C-c C-c) are typed very
quickly within the wrong mode... which might lead to "funny" results on both
sites. Try to think in python (including python-mode) and use org-mode
keybindings or vice versa... ;)
I know I could (and I do) open an explicit buffer with the right mode by C-c `.
However, esp. for debugging and tweaking of the code blocks I like to have at
least syntax-highlighting and proper indention and don't want to switch forth
and back between buffers continuously.
Solution: I found on emacs-wiki the minor-mode two-mode-mode.el [1] from David
N. Welton. I was able to modify it with a minimum to allow switching between
org-mode and python-mode. However, other (multiple) modes should be possible
as well.
I had to change the configuration into the following:
(defvar default-mode (list "org-mode" 'org-mode))
(defvar second-modes (list
(list "python" "#+begin_src python" "#+end_src" 'python-mode))
Making two-mode-mode.el required in emacs init or even hook it to any
automatic load method, after I load an org-file in emacs I can start two-mode-
mode.el (if not loaded automatically).
Moving the pointer to within a python block will switch from org-mode to
python-mode. Leaving the python source code block will allow to switch back to
org-mode automatically.
Placing the pointer on the #+srcname: line still allow C-c C-c and C-` to
evaluate the source code block within org-mode.
Issues: Org-mode file *need* to use the startup variable 'showeverything'
otherwise the switching between the modes results in a permanent folding
between into the overview. Resulting that if you "tab" on a header it opens up
and close directly.
e.g. add
#+STARTUP: showeverything
to the head of the org-file.
If you set the pointer with the mouse the mode-switch does not work. You have
to move the pointer once inside the code block
It seems that sometimes there is a very long freeze state... don't know
whether this is due to my recent system changes or due to the new minor-mode
Result: It seems to work so fare not to bad for a quick hack. The code-base of
the two-mode-mode.el is very minimalistic and I believe it would be very
quickly integrated resp. reimplemented within org-babel. I believe it is a
worth idea even just for the proper syntax-highlighting and the correct
indentation for the particular programming language.
Best regards,
Torsten
[1] http://www.welton.it/freesoftware/files/two-mode-mode.el
- [Orgmode] [babel] demonstration mode-switching between code blocks,
Torsten Wagner <=