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

* Re: [babel] demonstration mode-switching between code blocks
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Spiers @ 2009-11-04 10:42 UTC (permalink / raw)
  To: emacs-orgmode

Torsten Wagner (torsten.wagner@gmail.com) wrote:
> 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.

[snipped]

> 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.

Thanks for sharing.  Just for reference, there are few major modes out
there implementing this kind of approach:

  http://www.emacswiki.org/emacs/MultipleModes

For example I have used mmm-mode to good effect in the past, to
auto-switch between HTML and Perl:

  http://mmm-mode.sourceforge.net/

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

* Re: [babel] demonstration mode-switching between code blocks
  2009-11-04 10:42 ` Adam Spiers
@ 2009-11-04 14:52   ` Torsten Wagner
  2009-11-04 22:05     ` Eric Schulte
  0 siblings, 1 reply; 5+ messages in thread
From: Torsten Wagner @ 2009-11-04 14:52 UTC (permalink / raw)
  To: Adam Spiers, emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 626 bytes --]

Hi Adam,

Thanks for sharing.  Just for reference, there are few major modes out
> there implementing this kind of approach:
>
>  http://www.emacswiki.org/emacs/MultipleModes
>
> For example I have used mmm-mode to good effect in the past, to
> auto-switch between HTML and Perl:
>
>  http://mmm-mode.sourceforge.net/
>
>
Thanks for sharing the alternatives. The  proposed solution has the charm to
use only a minor mode which consist of less then 100 lines of lisp-code. I
thought if it is of general interest, it might be easy adoptable within
org-babel. I would prefer to use org-mode as major mode.

Best regards

Torsten

[-- Attachment #1.2: Type: text/html, Size: 1458 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] demonstration mode-switching between code blocks
  2009-11-04 14:52   ` Torsten Wagner
@ 2009-11-04 22:05     ` Eric Schulte
  2009-11-05  9:53       ` Giovanni Ridolfi
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2009-11-04 22:05 UTC (permalink / raw)
  To: Torsten Wagner; +Cc: emacs-orgmode

Torsten Wagner <torsten.wagner@gmail.com> writes:

> Hi Adam,
>
>     Thanks for sharing.  Just for reference, there are few major modes out
>     there implementing this kind of approach:
>    
>      http://www.emacswiki.org/emacs/MultipleModes
>    
>     For example I have used mmm-mode to good effect in the past, to
>     auto-switch between HTML and Perl:
>    
>      http://mmm-mode.sourceforge.net/
>

I have played with using MuMaMo mode before

http://article.gmane.org/gmane.emacs.orgmode/8112

but found it too buggy for practical use.

>
> Thanks for sharing the alternatives. The  proposed solution has the charm to use only a minor mode which
> consist of less then 100 lines of lisp-code. I thought if it is of general interest, it might be easy
> adoptable within org-babel. I would prefer to use org-mode as major mode.
>

This does sound more promising than previous attempts.  I don't think
this addition would necessarily have to be connected to org-babel, it
may make more sense as it's own contrib package. -- Eric

>
> Best regards
>
> Torsten
>
>  
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: [babel] demonstration mode-switching between code blocks
  2009-11-04 22:05     ` Eric Schulte
@ 2009-11-05  9:53       ` Giovanni Ridolfi
  0 siblings, 0 replies; 5+ messages in thread
From: Giovanni Ridolfi @ 2009-11-05  9:53 UTC (permalink / raw)
  To: Torsten Wagner, Eric Schulte, Adam Spiers; +Cc: emacs-orgmode

Torsten Wagner (torsten.wagner@gmail.com) wrote:
> 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.
> Solution: I found on emacs-wiki the minor-mode two-mode-mode.el
>  [1] from David
> N. Welton. 

--- Mer 4/11/09, Eric Schulte <schulte.eric@gmail.com> ha scritto:
> Torsten Wagner <torsten.wagner@gmail.com>
> writes:
> 
> > Hi Adam,
> > Just for
> reference, there are few major modes out
> >  there implementing this kind
> > of approach:
> >    
> >      http://www.emacswiki.org/emacs/MultipleModes
> >    
> >     For example I have used
> > mmm-mode to good effect in the past, to
> >     auto-switch between HTML and Perl:
> >    
> >      http://mmm-mode.sourceforge.net/
> >
> 
> I have played with using MuMaMo mode before
> 
> http://article.gmane.org/gmane.emacs.orgmode/8112
> 
> but found it too buggy for practical use.
> 

what about using C-c ' ?

(also suggested by Dan Davison)

manual 11.3 Literal examples
C-c '
     Edit the source code example at point in its native mode.  This
     works by switching to a temporary buffer with the source code.
     You need to exit by pressing `C-c '' again(3), the edited version
     will then replace the old version in the Org buffer.  Fixed-width
     regions (where each line starts with a colon followed by a space)
     will be edited using `artist-mode'(4) to allow creating ASCII
     drawings easily.  Using this command in an empty line will create
     a new fixed-width region. 
hth

Giovanni




^ 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).