From mboxrd@z Thu Jan 1 00:00:00 1970 From: Torsten Wagner Subject: [babel] demonstration mode-switching between code blocks Date: Wed, 4 Nov 2009 15:03:50 +0900 Message-ID: <200911041503.51029.torsten.wagner@googlemail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N5YyY-0004Pe-Se for emacs-orgmode@gnu.org; Wed, 04 Nov 2009 01:04:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N5YyT-0004Oq-LO for emacs-orgmode@gnu.org; Wed, 04 Nov 2009 01:04:09 -0500 Received: from [199.232.76.173] (port=55860 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N5YyS-0004Om-Na for emacs-orgmode@gnu.org; Wed, 04 Nov 2009 01:04:04 -0500 Received: from mail-yx0-f191.google.com ([209.85.210.191]:53496) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N5YyS-0000QY-7q for emacs-orgmode@gnu.org; Wed, 04 Nov 2009 01:04:04 -0500 Received: by yxe29 with SMTP id 29so6520839yxe.14 for ; Tue, 03 Nov 2009 22:04:03 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org 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