emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Torsten Wagner <torsten.wagner@gmail.com>
To: org-mode Mailing List <emacs-orgmode@gnu.org>
Subject: [babel] demonstration mode-switching between code blocks
Date: Wed, 4 Nov 2009 15:03:50 +0900	[thread overview]
Message-ID: <200911041503.51029.torsten.wagner@googlemail.com> (raw)

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
 

             reply	other threads:[~2009-11-04  6:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-04  6:03 Torsten Wagner [this message]
2009-11-04 10:42 ` [babel] demonstration mode-switching between code blocks Adam Spiers
2009-11-04 14:52   ` Torsten Wagner
2009-11-04 22:05     ` Eric Schulte
2009-11-05  9:53       ` Giovanni Ridolfi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200911041503.51029.torsten.wagner@googlemail.com \
    --to=torsten.wagner@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).