emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] demonstration mode-switching between code blocks
@ 2009-11-04  6:03 Torsten Wagner
  2009-11-04 10:42 ` Adam Spiers
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Wagner @ 2009-11-04  6:03 UTC (permalink / raw)
  To: org-mode Mailing List

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
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-05  9:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-04  6:03 [babel] demonstration mode-switching between code blocks Torsten Wagner
2009-11-04 10:42 ` Adam Spiers
2009-11-04 14:52   ` Torsten Wagner
2009-11-04 22:05     ` Eric Schulte
2009-11-05  9:53       ` Giovanni Ridolfi

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).