emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Embedding org-syntax in program source
@ 2010-04-13 10:32 LanX
  2010-04-13 15:08 ` Eric Schulte
  2010-04-13 16:12 ` Dan Davison
  0 siblings, 2 replies; 9+ messages in thread
From: LanX @ 2010-04-13 10:32 UTC (permalink / raw)
  To: emacs-orgmode


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

Hi

is there a way to make org-mode ignore "comment" characters at the beginning
of a line?

Such that
;* Head

or
#** Subhead

work in elisp or perl?

I know of org-babel, but the code produced is no legal Lisp/Perl code
anymore...

Thanks
  Rolf

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

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

_______________________________________________
Emacs-orgmode mailing list
Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 10:32 Embedding org-syntax in program source LanX
@ 2010-04-13 15:08 ` Eric Schulte
       [not found]   ` <y2wec36f5051004130835k5d850907h35f6645b5f5fef17@mail.gmail.com>
  2010-04-13 16:12 ` Dan Davison
  1 sibling, 1 reply; 9+ messages in thread
From: Eric Schulte @ 2010-04-13 15:08 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

Hi Rolf,

LanX <lanx.perl@googlemail.com> writes:

> Hi
>
> is there a way to make org-mode ignore "comment" characters at the beginning
> of a line?
>
> Such that
> ;* Head
>
> or
> #** Subhead
>
> work in elisp or perl?
>

see this thread http://thread.gmane.org/gmane.emacs.orgmode/7957, as I
recall basically it's possible to get most org-like behavior using
orgstruct-mode, but many are continually frustrated by the remaining
missing 20% of behavior.

>
> I know of org-babel, but the code produced is no legal Lisp/Perl code
> anymore...
>

could you please elaborate,

Has there been a recent change in Org-babel which is causing problems
for you?

I'm currently using Org-babel to write code in a variety of programming
languages, and I've had no problems running the tangled code.

Thanks -- Eric

>
> Thanks
>   Rolf
> _______________________________________________
> Emacs-orgmode mailing list
> Please 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] 9+ messages in thread

* Embedding org-syntax in program source
       [not found]   ` <y2wec36f5051004130835k5d850907h35f6645b5f5fef17@mail.gmail.com>
@ 2010-04-13 15:40     ` LanX
  2010-04-13 16:47       ` Eric Schulte
  2010-04-13 21:31       ` Dan Davison
  0 siblings, 2 replies; 9+ messages in thread
From: LanX @ 2010-04-13 15:40 UTC (permalink / raw)
  To: emacs-orgmode


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

Oops, forgot to reply to the list... 8-| ..

---------- Forwarded message ----------

Thanks Eric,


see this thread http://thread.gmane.org/gmane.emacs.orgmode/7957, as I
> recall basically it's possible to get most org-like behavior using
> orgstruct-mode, but many are continually frustrated by the remaining
> missing 20% of behavior.
>

Hmm, for what I read it's NOT easily possible, Tassilo switched back to
outline-minor-mode.



>
> > I know of org-babel, but the code produced is no legal Lisp/Perl code
> > anymore...
>
> could you please elaborate,
> ...
>
> I'm currently using Org-babel to write code in a variety of programming
> languages, and I've had no problems running the tangled code.
>

Thats the point you have to tangle the code and furthermore you have to run
emacs to tangle it.

The file as such is not a legal Perl code anymore because of lines starting
with a "*".
(never actually worked with babel, but thats what I read from the docs)

And relying on an extra step for code generation is dangerous...

This is for sure acceptable with elisp or multilanguage projects.

Anyway I think, I will do some experiments with using a Code Filter in Perl
which eliminates the org-code. (thats a filter run at execution-time
changing the source before it's fed into the compiler)

Cheers
  Rolf

PS: I forgot to mention that when switching to other modes the highlighting
will also get confused and fly-make will report plenty of syntax problems.

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

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

_______________________________________________
Emacs-orgmode mailing list
Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 10:32 Embedding org-syntax in program source LanX
  2010-04-13 15:08 ` Eric Schulte
@ 2010-04-13 16:12 ` Dan Davison
  1 sibling, 0 replies; 9+ messages in thread
From: Dan Davison @ 2010-04-13 16:12 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

LanX <lanx.perl@googlemail.com> writes:

> Hi
>
> is there a way to make org-mode ignore "comment" characters at the beginning of
> a line?
>
> Such that
> ;* Head
>
> or
> #** Subhead
>
> work in elisp or perl?

Hi Rolf,

Short answer: yes. There are a bunch of good solutions out there, but it
would really benefit from someone putting together a summary tutorial on
Worg.

There are basically two types of solution: org-mode with tangling, and
use of outline-minor-mode (with some org machinery) in pure code files.

> I know of org-babel, but the code produced is no legal Lisp/Perl code
> anymore...

So first let me double-check that you are aware of org-babel-tangle?
That generates legal code from the org file. For example, I would really
recommend trying the org-mode route for an emacs configuration
file. There's support specifically for that
(http://orgmode.org/worg/org-contrib/babel/intro.php#literate-programming
and scroll down to Emacs Initialization with Org-babel)

I'm the secondary author of org-babel, but I don't intend to come across
as a myopic tangling zealot here. For new projects now I do tend to use
org-mode with tangling, but outline-minor-mode is still absolutely
essential to me for working on existing code in traditional format (as
well as large fragments of code held within org files).

Check out this thread from last year. The key post is this one from
Michael Zeller and subsequent ones by Seb Vauban. Ignore all mention of
org-babel in this thread as there has been 9 months of active
development since then.

http://article.gmane.org/gmane.emacs.orgmode/15427/match=org+style+folding

Personally I'm still using a fairly simple outline-minor-mode setup. For
what it's worth, here is my o-m-m config, but I've had this for ages now
and it needs revisiting. This will make elisp fold at ;;; as well as at
all top-level lisp forms. But the regexps below haven't been carefully
thought about.

(defun dan/set-up-outline-minor-mode (local-outline-regexp)
  (set (make-local-variable 'outline-regexp) local-outline-regexp)
  (outline-minor-mode t)
  (org-overview)
  (org-content))

(add-hook 'outline-minor-mode-hook
  (lambda ()
    (define-key outline-minor-mode-map [(control tab)] 'org-cycle)
    (define-key outline-minor-mode-map [(backtab)] 'org-global-cycle)))

(add-hook 'emacs-lisp-mode-hook
          (lambda () (dan/set-up-outline-minor-mode "\\((\\|;;;\\)")))
(add-hook 'python-mode-hook
          (lambda () (dan/set-up-outline-minor-mode "\\( *def \\|if \\|class \\|##\\)")))
(add-hook 'bibtex-mode-hook
          (lambda () (dan/set-up-outline-minor-mode "@")))
(add-hook 'ess-mode-hook
          (lambda () 
            (unless (eq noweb-code-mode 'R-mode)
              (dan/set-up-outline-minor-mode "[a-zA-Z._[\"][a-zA-Z._0-9[\"]* *<- *function"))))

I think this topic can be confusing. E.g. what about Carsten's
outline-magic.el ?? Is there a role for that? Like I say this would be a
good topic for a Worg page.

Dan

>
> Thanks
>   Rolf
> _______________________________________________
> Emacs-orgmode mailing list
> Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 15:40     ` LanX
@ 2010-04-13 16:47       ` Eric Schulte
  2010-04-13 21:31       ` Dan Davison
  1 sibling, 0 replies; 9+ messages in thread
From: Eric Schulte @ 2010-04-13 16:47 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

LanX <lanx.perl@googlemail.com> writes:

> Oops, forgot to reply to the list... 8-| ..
>
> ---------- Forwarded message ----------
>
> Thanks Eric,
>
>
> see this thread http://thread.gmane.org/gmane.emacs.orgmode/7957, as I
>> recall basically it's possible to get most org-like behavior using
>> orgstruct-mode, but many are continually frustrated by the remaining
>> missing 20% of behavior.
>>
>
> Hmm, for what I read it's NOT easily possible, Tassilo switched back to
> outline-minor-mode.
>
>
>
>>
>> > I know of org-babel, but the code produced is no legal Lisp/Perl code
>> > anymore...
>>
>> could you please elaborate,
>> ...
>>
>> I'm currently using Org-babel to write code in a variety of programming
>> languages, and I've had no problems running the tangled code.
>>
>
> Thats the point you have to tangle the code and furthermore you have to run
> emacs to tangle it.
>
> The file as such is not a legal Perl code anymore because of lines starting
> with a "*".
> (never actually worked with babel, but thats what I read from the docs)
>

Ah, I see, I was worried that you were having a problem with tangling.
Maybe there is some way to hide the org-mode wrappings with "heredoc"
style lines (I'm not very familiar with perl, but I hear it is very
flexible about the syntax in source-code files).  Maybe something like

  =for comment

  org-mode text

  * headlines

  etc...

  #+begin_src perl
  =cut

  =for comment
  #+end_src

  more org-mode...

>
> And relying on an extra step for code generation is dangerous...
>
> This is for sure acceptable with elisp or multilanguage projects.
>

Certainly tangling is an extra step, and as a matter of taste not
something many people will want to use, but I wouldn't say it's
dangerous.  I tangle in a couple of very real very large single-language
projects (sometimes with the same code tangling to run on different
platforms) and find it reliable.

>
> Anyway I think, I will do some experiments with using a Code Filter in
>Perl
> which eliminates the org-code. (thats a filter run at execution-time
> changing the source before it's fed into the compiler)
>

Good luck, if you find a workable solution, I'm sure there'd be interest
to hear about it here.

Best -- Eric

>
> Cheers
>   Rolf
>
> PS: I forgot to mention that when switching to other modes the highlighting
> will also get confused and fly-make will report plenty of syntax problems.
> _______________________________________________
> Emacs-orgmode mailing list
> Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 15:40     ` LanX
  2010-04-13 16:47       ` Eric Schulte
@ 2010-04-13 21:31       ` Dan Davison
  2010-04-13 23:54         ` LanX
  1 sibling, 1 reply; 9+ messages in thread
From: Dan Davison @ 2010-04-13 21:31 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

LanX <lanx.perl@googlemail.com> writes:
[...]
>     > I know of org-babel, but the code produced is no legal Lisp/Perl code
>     > anymore...
>
>     could you please elaborate,
>     ...
>
>     I'm currently using Org-babel to write code in a variety of programming
>     languages, and I've had no problems running the tangled code.
>
>

Hi Rolf,

> Thats the point you have to tangle the code and furthermore you have to run
> emacs to tangle it.

Right. Given the present forum I presume you are using emacs, so that
shouldn't be a problem per se?

> The file as such is not a legal Perl code anymore because of lines starting
> with a "*".
> (never actually worked with babel, but thats what I read from the docs)

I think you may have formed an inaccurate idea of how people are working
with source code in org-mode. It's not just about creating code files
with a bunch of stars in them; it involves embedding source code in
fully-functioning org-mode files (i.e. with headings, tags, properties,
TODO items, tables, links, timestamps etc). So of course these files do
not contain "legal Perl code".

>
> And relying on an extra step for code generation is dangerous...

You would have to explain that assertion. I work on a number of projects
where the code files are generated by tangling, and I'm still here. Also
still here are people whose finished products require the extra step of
running make, latex, gcc compilation etc.

>
> This is for sure acceptable with elisp or multilanguage projects.

I didn't understand this.

[...]
> PS: I forgot to mention that when switching to other modes the highlighting
> will also get confused and fly-make will report plenty of syntax problems.

I'm not sure what you mean here. When working with code in org-mode, one
uses C-c ' to switch to a language major-mode buffer containing the body
of the source code block. Is that working OK for you?

Dan


> _______________________________________________
> Emacs-orgmode mailing list
> Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 21:31       ` Dan Davison
@ 2010-04-13 23:54         ` LanX
  2010-04-14 12:39           ` Sebastian Rose
  2010-04-14 15:22           ` Dan Davison
  0 siblings, 2 replies; 9+ messages in thread
From: LanX @ 2010-04-13 23:54 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode


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

Hi Dan


>
> Right. Given the present forum I presume you are using emacs, so that
> shouldn't be a problem per se?
>

Well, don't you think that telling other people that changing the
_source_-code requires emacs might be a problem?


>
> I think you may have formed an inaccurate idea of how people are working
> with source code in org-mode.
>
> maybe... and I have to admit my knowledge of LP is theoretical (but at
least I investigated  the sources of TeX long ago! :)

my idea for the beginning was to extend my codes with org-modes folding,
linking and some TODO features in perl comments. Maybe automatically
switching the mode when the cursor is entering/leaving comments.

Multiline wouldn't be a problem since I can include them in POD (perl's
simplified approach to LP)

or I could embrace them in heredocs, for instance the following is legal
perlcode as long as the last line is empty (no whitespaces allowed).

<<;
* block1
** [test] bla


> And relying on an extra step for code generation is dangerous...
>
> You would have to explain that assertion.


Sorry, no offence intended, this is the common sense of perlmonks when
talking about run time code generation and adding extra dependencies. (Maybe
not the appropriate slang here...)

I wouldn't find many to join my projects when relying on extra make files
and I suppose running emacs in batch mode to tangle the code is not that
stable.

> This is for sure acceptable with elisp or multilanguage projects.

I didn't understand this.
>

emacs is a natural habitat of elisp , like unix is one for C.

And multilanguage projects would naturally rely on some make mechanisms.




> > PS: I forgot to mention that when switching to other modes the
> highlighting
> > will also get confused and fly-make will report plenty of syntax
> problems.
>
> I'm not sure what you mean here. When working with code in org-mode, one
> uses C-c ' to switch to a language major-mode buffer containing the body
> of the source code block. Is that working OK for you?
>

hm, yes ...but if I do this I could equally embrace all org-mode-stuff in
between "=pod"-lines or prepend a # to each line when switching to
cperl-mode.

Hooking this to save would guaranty to always have legal perlcode...

bye
  Rolf

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

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

_______________________________________________
Emacs-orgmode mailing list
Please 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] 9+ messages in thread

* Re: Embedding org-syntax in program source
  2010-04-13 23:54         ` LanX
@ 2010-04-14 12:39           ` Sebastian Rose
  2010-04-14 15:22           ` Dan Davison
  1 sibling, 0 replies; 9+ messages in thread
From: Sebastian Rose @ 2010-04-14 12:39 UTC (permalink / raw)
  To: LanX; +Cc: Dan Davison, emacs-orgmode

Hi,


I think there's no need for Org-mode in programming modes. I see
Org-mode as emacs' programming mode for plain text.


LanX <lanx.perl@googlemail.com> writes:
> my idea for the beginning was to extend my codes with org-modes folding,
> linking and some TODO features in perl comments. Maybe automatically
> switching the mode when the cursor is entering/leaving comments.

It's all there! For folding I use hs-minor-mode, for linking I still
stick with some old keyboard shortcuts here:

* `H-o o'  => 'org-open-at-point-global
* `H-o l'  => 'org-insert-link-global
* `C-c l'  => 'org-store-link

* `F3'     => 'find-file-at-point

  When in emacs-lisp mode, it will open the appropriate *.el file when
  on the symbol, no matter where I store htmlize.el on my system:

     (require 'htmlize)

  In c-mode, place point on unistd.h and press F3 to open
  /usr/include/unistd.h:

     #include <unistd.h>

  But it will find relative paths, too.


* `M-up'   => 'backward-page
* `M-down' => 'forward-page

   `C-q C-l' inserts the formfeed. I tend to divide source files into
   pages and group functions, classes, methods that way. Does not work
   in PHP, :-/ PHP does not consider ^L a whitespace character...but
   those guys don't even consider it a bug :-D


* `M-+'     => 'hs-toggle-hiding

   Finally, here's your fast and simple folding.


All these shortcuts work in comments, too.




>> And relying on an extra step for code generation is dangerous...

I'm a control freak myself - that's why I use emacs in the end :-)




Best wishes

   Sebastian

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

* Re: Embedding org-syntax in program source
  2010-04-13 23:54         ` LanX
  2010-04-14 12:39           ` Sebastian Rose
@ 2010-04-14 15:22           ` Dan Davison
  1 sibling, 0 replies; 9+ messages in thread
From: Dan Davison @ 2010-04-14 15:22 UTC (permalink / raw)
  To: LanX; +Cc: emacs-orgmode

LanX <lanx.perl@googlemail.com> writes:

> Hi Dan
>  
>
>
>     Right. Given the present forum I presume you are using emacs, so that
>     shouldn't be a problem per se?
>
>
> Well, don't you think that telling other people that changing the _source_-code
> requires emacs might be a problem?

Hi Rolf,

Yes I agree that this is something to think about. I mean, obviously
*they* can change it easily, but incorporating their edits to tangled
output back into your (version-controlled) source org file isn't so
easy.

Best wishes,

Dan

>  

>
>
>     I think you may have formed an inaccurate idea of how people are working
>     with source code in org-mode.
>
>
> maybe... and I have to admit my knowledge of LP is theoretical (but at least I
> investigated  the sources of TeX long ago! :)
>
> my idea for the beginning was to extend my codes with org-modes folding,
> linking and some TODO features in perl comments. Maybe automatically switching
> the mode when the cursor is entering/leaving comments.
>
> Multiline wouldn't be a problem since I can include them in POD (perl's
> simplified approach to LP)
>
> or I could embrace them in heredocs, for instance the following is legal
> perlcode as long as the last line is empty (no whitespaces allowed).
>
> <<;
> * block1
> ** [test] bla
>
>
>
>     > And relying on an extra step for code generation is dangerous...
>
>     You would have to explain that assertion. 
>
>  
> Sorry, no offence intended, this is the common sense of perlmonks when talking
> about run time code generation and adding extra dependencies. (Maybe not the
> appropriate slang here...)
>
> I wouldn't find many to join my projects when relying on extra make files and I
> suppose running emacs in batch mode to tangle the code is not that stable.
>  
>> This is for sure acceptable with elisp or multilanguage projects.
>
>
>     I didn't understand this.
>
>
> emacs is a natural habitat of elisp , like unix is one for C.
>
> And multilanguage projects would naturally rely on some make mechanisms.
>
>
>  
>
>     > PS: I forgot to mention that when switching to other modes the
>     highlighting
>     > will also get confused and fly-make will report plenty of syntax
>     problems.
>
>     I'm not sure what you mean here. When working with code in org-mode, one
>     uses C-c ' to switch to a language major-mode buffer containing the body
>     of the source code block. Is that working OK for you?
>
>
> hm, yes ...but if I do this I could equally embrace all org-mode-stuff in
> between "=pod"-lines or prepend a # to each line when switching to cperl-mode.
>
> Hooking this to save would guaranty to always have legal perlcode...
>
> bye
>   Rolf

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

end of thread, other threads:[~2010-04-14 15:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-13 10:32 Embedding org-syntax in program source LanX
2010-04-13 15:08 ` Eric Schulte
     [not found]   ` <y2wec36f5051004130835k5d850907h35f6645b5f5fef17@mail.gmail.com>
2010-04-13 15:40     ` LanX
2010-04-13 16:47       ` Eric Schulte
2010-04-13 21:31       ` Dan Davison
2010-04-13 23:54         ` LanX
2010-04-14 12:39           ` Sebastian Rose
2010-04-14 15:22           ` Dan Davison
2010-04-13 16:12 ` Dan Davison

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