emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* automatic tangle
@ 2012-01-11 14:36 András Major
  2012-01-11 15:18 ` Sebastien Vauban
  2012-01-11 22:39 ` Eric S Fraga
  0 siblings, 2 replies; 8+ messages in thread
From: András Major @ 2012-01-11 14:36 UTC (permalink / raw)
  To: emacs-orgmode

Hi fellows,

I've just discovered that I'm missing a feature in org-mode.  These
days I write much of my code in an Org buffer and tangle it into a set
of source files.  Currently, I follow a rather cumbersome procedure
when making changes to the code:

1. I change the Org file using the C-cC-c keystroke within the code
   block I want to edit.

2. After editing, I press C-cc-c again to return to the main buffer.

3. I save the buffer.

4. I tangle the buffer using C-cC-vt.

5. For further editing, I press C-cC-c again.

I know that 3. is optional, but this still leaves me with four steps
instead of (ideally) just one.

What I would like to have is a way of reducing all this to just one
key command.  Would it make sense to introduce such a command that
simply tangles the entire buffer, including the changes made in the
language-specific buffer, but leaving that buffer open for editing?
If it's a reasonably small change, could anyone introduce it?  (I
don't have time to delve into the depths of org-mode.)

Cheers,

  András

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

* Re: automatic tangle
  2012-01-11 14:36 automatic tangle András Major
@ 2012-01-11 15:18 ` Sebastien Vauban
  2012-01-11 22:39 ` Eric S Fraga
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastien Vauban @ 2012-01-11 15:18 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi András,

András Major wrote:
> I've just discovered that I'm missing a feature in org-mode.  These
> days I write much of my code in an Org buffer and tangle it into a set
> of source files.  Currently, I follow a rather cumbersome procedure
> when making changes to the code:
>
> 1. I change the Org file using the C-cC-c keystroke within the code
>    block I want to edit.
>
> 2. After editing, I press C-cc-c again to return to the main buffer.
>
> 3. I save the buffer.
>
> 4. I tangle the buffer using C-cC-vt.
>
> 5. For further editing, I press C-cC-c again.
>
> I know that 3. is optional, but this still leaves me with four steps
> instead of (ideally) just one.
>
> What I would like to have is a way of reducing all this to just one
> key command.  Would it make sense to introduce such a command that
> simply tangles the entire buffer, including the changes made in the
> language-specific buffer, but leaving that buffer open for editing?
> If it's a reasonably small change, could anyone introduce it?  (I
> don't have time to delve into the depths of org-mode.)

I have the impression it's already there: if you edit your code directly in
the Org buffer, without opening an indirect buffer, the only thing you have to
do is:

1. save (optional, as you say)
2. tangle via C-c C-v (C-)t.

You can even advice the tangle function to do the save for you...

Another option is the opposite: edit in your tangled file, and untangle when
you feel it's the right time.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: automatic tangle
@ 2012-01-11 19:21 András Major
  2012-01-11 20:37 ` Sebastien Vauban
  2012-01-14 17:41 ` Eric Schulte
  0 siblings, 2 replies; 8+ messages in thread
From: András Major @ 2012-01-11 19:21 UTC (permalink / raw)
  To: emacs-orgmode

Hi Sebastien,

> I have the impression it's already there: if you edit your code directly in
> the Org buffer, without opening an indirect buffer, the only thing you have to
> do is:

That's precisely what I want to avoid.  I'd like to use the
language-specific indentation and highlighting using the indirect
buffer.  Basically, what I'm after is a quick keyboard command that
tangles the entire file while I'm in the indirect buffer.

> Another option is the opposite: edit in your tangled file, and untangle when
> you feel it's the right time.

I don't think that's practical, since each file can be built up from
several code blocks.  In any case, it would be too easy to lose code
that way by accidentally tangling while there are changes in the
source code file.

  András

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

* Re: automatic tangle
  2012-01-11 19:21 András Major
@ 2012-01-11 20:37 ` Sebastien Vauban
  2012-01-14 17:41 ` Eric Schulte
  1 sibling, 0 replies; 8+ messages in thread
From: Sebastien Vauban @ 2012-01-11 20:37 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi András,

András Major wrote:
>> I have the impression it's already there: if you edit your code directly in
>> the Org buffer, without opening an indirect buffer, the only thing you have to
>> do is:
>
> That's precisely what I want to avoid.  I'd like to use the
> language-specific indentation and highlighting using the indirect
> buffer.  Basically, what I'm after is a quick keyboard command that
> tangles the entire file while I'm in the indirect buffer.

I do have:
- language-specific indentation and
- highlighting
in the Org buffer itself...

Just put this in your .emacs file:

#+begin_src emacs-lisp
        ;; fontify code in code blocks
        (setq org-src-fontify-natively t)

        ;; preserve spaces and `tab' characters in source code blocks
        (setq org-src-preserve-indentation t)

        ;; same effect for `tab' as in the language major mode buffer
        (setq org-src-tab-acts-natively t)
#+end_src

>> Another option is the opposite: edit in your tangled file, and untangle when
>> you feel it's the right time.
>
> I don't think that's practical, since each file can be built up from
> several code blocks.

That's not a problem: if you turn on the "comments", you'll see every chunked
delimited in the tangled buffer.

> In any case, it would be too easy to lose code that way by accidentally
> tangling while there are changes in the source code file.

If you play within both files, yes, that's a real potential danger.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: automatic tangle
  2012-01-11 14:36 automatic tangle András Major
  2012-01-11 15:18 ` Sebastien Vauban
@ 2012-01-11 22:39 ` Eric S Fraga
  1 sibling, 0 replies; 8+ messages in thread
From: Eric S Fraga @ 2012-01-11 22:39 UTC (permalink / raw)
  To: András Major; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1708 bytes --]

András Major <andras.g.major@gmail.com> writes:

> Hi fellows,
>
> I've just discovered that I'm missing a feature in org-mode.  These
> days I write much of my code in an Org buffer and tangle it into a set
> of source files.  Currently, I follow a rather cumbersome procedure
> when making changes to the code:
>
> 1. I change the Org file using the C-cC-c keystroke within the code
>    block I want to edit.
>
> 2. After editing, I press C-cc-c again to return to the main buffer.
>
> 3. I save the buffer.
>
> 4. I tangle the buffer using C-cC-vt.
>
> 5. For further editing, I press C-cC-c again.
>
> I know that 3. is optional, but this still leaves me with four steps
> instead of (ideally) just one.
>
> What I would like to have is a way of reducing all this to just one
> key command.  Would it make sense to introduce such a command that
> simply tangles the entire buffer, including the changes made in the
> language-specific buffer, but leaving that buffer open for editing?
> If it's a reasonably small change, could anyone introduce it?  (I
> don't have time to delve into the depths of org-mode.)
>
> Cheers,
>
>   András

Probably not what you want but, assuming that the keys you hit are
always the same, you could always define a keyboard macro, name it and
save it as emacs lisp code.

for example, the attached (because the insert-kbd-macro command creates
emacs lisp code with control characters) defines a new command which, if
starting from a code block special edit mode, exits that block, saves
the file, tangles the whole buffer and re-enters the code block:
You can then bind this new command to a key of your choice.  Untested...


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: function definition --]
[-- Type: text/orgmode, Size: 375 bytes --]

* new function
  Allows one to exit a special code block editing mode, save the file,
  tangle all code blocks and then re-enter the code block editing
  mode.

#+begin_src emacs-lisp
(fset 'esf/org-save-tangle-reedit-macro
   (lambda (&optional arg) 
     "Keyboard macro." 
     (interactive "p") 
     (kmacro-exec-ring-item (quote ("\x03'\x18\x13\x03\x16t\x03'" 0 "%d")) arg)))
#+end_src


[-- Attachment #3: Type: text/plain, Size: 137 bytes --]



HTH,
eric
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.92.1
: using Org-mode version 7.8.03 (release_7.8.03.99.gce5c5)

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

* Re: automatic tangle
  2012-01-11 19:21 András Major
  2012-01-11 20:37 ` Sebastien Vauban
@ 2012-01-14 17:41 ` Eric Schulte
  2012-01-17  8:06   ` András Major
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2012-01-14 17:41 UTC (permalink / raw)
  To: András Major; +Cc: emacs-orgmode

András Major <andras.g.major@gmail.com> writes:

> Hi Sebastien,
>
>> I have the impression it's already there: if you edit your code directly in
>> the Org buffer, without opening an indirect buffer, the only thing you have to
>> do is:
>
> That's precisely what I want to avoid.  I'd like to use the
> language-specific indentation and highlighting using the indirect
> buffer.  Basically, what I'm after is a quick keyboard command that
> tangles the entire file while I'm in the indirect buffer.
>

The following functions provide for (1) easily executing code in the
org-mode buffer related to the current edit buffer and (2) tangling the
org-mode buffer related to the current edit buffer.  Binding (2) to a
key in `org-src-mode' should provide the functionality you describe.

#+BEGIN_SRC emacs-lisp
  (defmacro org-src-in-org-buffer (&rest body)
    `(save-window-excursion
       (org-edit-src-exit 'save)
       ,@body
       (setq msg (current-message))
       (if (eq org-src-window-setup 'other-frame)
           (let ((org-src-window-setup 'current-window))
             (org-edit-src-code 'save))
         (org-edit-src-code 'save))
       (message (or msg ""))))

  (defun org-src-tangle (arg)
    (interactive "P")
    (org-src-in-org-buffer (org-babel-tangle arg)))
#+END_SRC

I think that the above should be folded into org-src.el, but I'm not
entirely sure how.  (1) could be used to perform a number of functions
in the org buffer from an edit buffer, although off the top of my head
I'm not sure if there exists a need for this aside from tangling.

Best,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

* Re: automatic tangle
  2012-01-14 17:41 ` Eric Schulte
@ 2012-01-17  8:06   ` András Major
  2012-01-20 17:54     ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: András Major @ 2012-01-17  8:06 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Thanks Eric,

Thanks a lot for the quick reply.  Any chances of this being
incorporated into Org-Mode in the near future?

  András


On 1/14/12, Eric Schulte <eric.schulte@gmx.com> wrote:
> András Major <andras.g.major@gmail.com> writes:
>
>> Hi Sebastien,
>>
>>> I have the impression it's already there: if you edit your code directly
>>> in
>>> the Org buffer, without opening an indirect buffer, the only thing you
>>> have to
>>> do is:
>>
>> That's precisely what I want to avoid.  I'd like to use the
>> language-specific indentation and highlighting using the indirect
>> buffer.  Basically, what I'm after is a quick keyboard command that
>> tangles the entire file while I'm in the indirect buffer.
>>
>
> The following functions provide for (1) easily executing code in the
> org-mode buffer related to the current edit buffer and (2) tangling the
> org-mode buffer related to the current edit buffer.  Binding (2) to a
> key in `org-src-mode' should provide the functionality you describe.
>
> #+BEGIN_SRC emacs-lisp
>   (defmacro org-src-in-org-buffer (&rest body)
>     `(save-window-excursion
>        (org-edit-src-exit 'save)
>        ,@body
>        (setq msg (current-message))
>        (if (eq org-src-window-setup 'other-frame)
>            (let ((org-src-window-setup 'current-window))
>              (org-edit-src-code 'save))
>          (org-edit-src-code 'save))
>        (message (or msg ""))))
>
>   (defun org-src-tangle (arg)
>     (interactive "P")
>     (org-src-in-org-buffer (org-babel-tangle arg)))
> #+END_SRC
>
> I think that the above should be folded into org-src.el, but I'm not
> entirely sure how.  (1) could be used to perform a number of functions
> in the org buffer from an edit buffer, although off the top of my head
> I'm not sure if there exists a need for this aside from tangling.
>
> Best,
>
> --
> Eric Schulte
> http://cs.unm.edu/~eschulte/
>

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

* Re: automatic tangle
  2012-01-17  8:06   ` András Major
@ 2012-01-20 17:54     ` Eric Schulte
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Schulte @ 2012-01-20 17:54 UTC (permalink / raw)
  To: András Major; +Cc: emacs-orgmode, Eric Schulte

I've just added the two functions below to org-src.el.

Cheers,

András Major <andras.g.major@gmail.com> writes:

> Thanks Eric,
>
> Thanks a lot for the quick reply.  Any chances of this being
> incorporated into Org-Mode in the near future?
>
>   András
>
>
> On 1/14/12, Eric Schulte <eric.schulte@gmx.com> wrote:
>> András Major <andras.g.major@gmail.com> writes:
>>
>>> Hi Sebastien,
>>>
>>>> I have the impression it's already there: if you edit your code directly
>>>> in
>>>> the Org buffer, without opening an indirect buffer, the only thing you
>>>> have to
>>>> do is:
>>>
>>> That's precisely what I want to avoid.  I'd like to use the
>>> language-specific indentation and highlighting using the indirect
>>> buffer.  Basically, what I'm after is a quick keyboard command that
>>> tangles the entire file while I'm in the indirect buffer.
>>>
>>
>> The following functions provide for (1) easily executing code in the
>> org-mode buffer related to the current edit buffer and (2) tangling the
>> org-mode buffer related to the current edit buffer.  Binding (2) to a
>> key in `org-src-mode' should provide the functionality you describe.
>>
>> #+BEGIN_SRC emacs-lisp
>>   (defmacro org-src-in-org-buffer (&rest body)
>>     `(save-window-excursion
>>        (org-edit-src-exit 'save)
>>        ,@body
>>        (setq msg (current-message))
>>        (if (eq org-src-window-setup 'other-frame)
>>            (let ((org-src-window-setup 'current-window))
>>              (org-edit-src-code 'save))
>>          (org-edit-src-code 'save))
>>        (message (or msg ""))))
>>
>>   (defun org-src-tangle (arg)
>>     (interactive "P")
>>     (org-src-in-org-buffer (org-babel-tangle arg)))
>> #+END_SRC
>>
>> I think that the above should be folded into org-src.el, but I'm not
>> entirely sure how.  (1) could be used to perform a number of functions
>> in the org buffer from an edit buffer, although off the top of my head
>> I'm not sure if there exists a need for this aside from tangling.
>>
>> Best,
>>
>> --
>> Eric Schulte
>> http://cs.unm.edu/~eschulte/
>>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

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

end of thread, other threads:[~2012-01-20 19:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-11 14:36 automatic tangle András Major
2012-01-11 15:18 ` Sebastien Vauban
2012-01-11 22:39 ` Eric S Fraga
  -- strict thread matches above, loose matches on Subject: below --
2012-01-11 19:21 András Major
2012-01-11 20:37 ` Sebastien Vauban
2012-01-14 17:41 ` Eric Schulte
2012-01-17  8:06   ` András Major
2012-01-20 17:54     ` Eric Schulte

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