* [PATCH] Better handling labels in source code blocks + A suggestion
@ 2016-08-01 13:43 Bernard Hurley
2016-08-01 13:53 ` Bernard Hurley
2016-08-08 12:23 ` Nicolas Goaziou
0 siblings, 2 replies; 3+ messages in thread
From: Bernard Hurley @ 2016-08-01 13:43 UTC (permalink / raw
To: emacs-orgmode
Hi all,
At present the value of org-coderef-label-format in a source code
editing buffer does not inherit its value from the value in the
corresponding org-mode buffer but instead, if it is not specified by a
-l option, defaults to the global value. Note that it is the value in the
org mode buffer and not the global value that is used for such things as
exporting so this can lead to inconsistent behaviour.
The following patch on org-src.el will fix this, and, as far as I can
tell, it doesn’t break anything else:
(N.B. I’m using org-plus-contrib-20160725 and Emacs 25.1.50.1)
========= snip=====
*** org-src.old.el 2016-08-01 13:23:35.596041600 +0100
--- org-src.el 2016-08-01 13:34:08.420047376 +0100
***************
*** 828,834 ****
name of the sub-editing buffer."
(interactive)
(let* ((element (org-element-at-point))
! (type (org-element-type element)))
(unless (and (memq type '(example-block src-block))
(org-src--on-datum-p element))
(user-error "Not in a source or example block"))
--- 828,835 ----
name of the sub-editing buffer."
(interactive)
(let* ((element (org-element-at-point))
! (type (org-element-type element))
! (local-coderef-label-format org-coderef-label-format))
(unless (and (memq type '(example-block src-block))
(org-src--on-datum-p element))
(user-error "Not in a source or example block"))
***************
*** 862,868 ****
;; Finalize buffer.
(org-set-local 'org-coderef-label-format
(or (org-element-property :label-fmt element)
! org-coderef-label-format))
(when (eq type 'src-block)
(org-set-local 'org-src--babel-info babel-info)
(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
--- 863,869 ----
;; Finalize buffer.
(org-set-local 'org-coderef-label-format
(or (org-element-property :label-fmt element)
! local-coderef-label-format))
(when (eq type 'src-block)
(org-set-local 'org-src--babel-info babel-info)
(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
======== snip =======
After this you can do things like the following in an org-mode buffer,
so that the labels are embedded in comments and the code block will
still execute:
# Local Variables:
# org-coderef-label-format: "#(ref:%s)"
# End:
and you could write something like:
#+BEGIN_SRC ruby -r
instead of:
#+BEGIN_SRC ruby -f -l "#(ref:%s)"
which is quite convenient if you have lots of blocks
A Suggestion:
============
In addition it would be nice if there were some way of giving a default
value for org-coderef-label-format that depends on the language of the
code block it is associated with, but I’m not sure what the best way to
implement this would be.
--
Your fortune cookie for today:
To code the impossible code, This is my quest --
To bring up a virgin machine, To debug that code,
To pop out of endless recursion, No matter how hopeless,
To grok what appears on the screen, No matter the load,
To write those routines
To right the unrightable bug, Without question or pause,
To endlessly twiddle and thrash, To be willing to hack FORTRAN IV
To mount the unmountable magtape, For a heavenly cause.
To stop the unstoppable crash! And I know if I'll only be true
To this glorious quest,
And the queue will be better for this, That my code will run CUSPy and calm,
That one man, scorned and When it's put to the test.
destined to lose,
Still strove with his last allocation
To scrap the unscrappable kludge!
-- To "The Impossible Dream", from Man of La Mancha
** Fortune cookies are brought to you by GNU/Linux "fortunes" **
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Better handling labels in source code blocks + A suggestion
2016-08-01 13:43 [PATCH] Better handling labels in source code blocks + A suggestion Bernard Hurley
@ 2016-08-01 13:53 ` Bernard Hurley
2016-08-08 12:23 ` Nicolas Goaziou
1 sibling, 0 replies; 3+ messages in thread
From: Bernard Hurley @ 2016-08-01 13:53 UTC (permalink / raw
To: emacs-orgmode
>>>>> "Bernard" == Bernard Hurley <bernard@marcade.biz> writes:
Bernard> #+BEGIN_SRC ruby -f -l "#(ref:%s)"
Sorry that should have been:
#+BEGIN_SRC ruby -r -l "#(ref:%s)"
--
Your fortune cookie for today:
Bridge ahead. Pay troll.
** Fortune cookies are brought to you by GNU/Linux "fortunes" **
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Better handling labels in source code blocks + A suggestion
2016-08-01 13:43 [PATCH] Better handling labels in source code blocks + A suggestion Bernard Hurley
2016-08-01 13:53 ` Bernard Hurley
@ 2016-08-08 12:23 ` Nicolas Goaziou
1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2016-08-08 12:23 UTC (permalink / raw
To: Bernard Hurley; +Cc: emacs-orgmode
Hello,
Bernard Hurley <bernard@marcade.biz> writes:
> At present the value of org-coderef-label-format in a source code
> editing buffer does not inherit its value from the value in the
> corresponding org-mode buffer but instead, if it is not specified by a
> -l option, defaults to the global value. Note that it is the value in the
> org mode buffer and not the global value that is used for such things as
> exporting so this can lead to inconsistent behaviour.
>
> The following patch on org-src.el will fix this, and, as far as I can
> tell, it doesn’t break anything else:
[...]
> After this you can do things like the following in an org-mode buffer,
> so that the labels are embedded in comments and the code block will
> still execute:
>
> # Local Variables:
> # org-coderef-label-format: "#(ref:%s)"
> # End:
>
> and you could write something like:
>
> #+BEGIN_SRC ruby -r
>
> instead of:
>
> #+BEGIN_SRC ruby -f -l "#(ref:%s)"
>
> which is quite convenient if you have lots of blocks
It is already possible to do that with the current implementation, so
I'm not sure to understand the bug you're reporting.
Besides, I added support for evaluating code blocks containing coderefs.
It might be related to your post.
> A Suggestion:
> ============
>
> In addition it would be nice if there were some way of giving a default
> value for org-coderef-label-format that depends on the language of the
> code block it is associated with, but I’m not sure what the best way to
> implement this would be.
`org-coderef-label-format' could become `org-coderef-label-alist' where
key is the language, as a string, and value the format string. You
would also need to implement a getter e.g.,
(defun org-src-get-coderef-fmt element)
that would return the appropriate format-string.
Would you want to provide a patch for that?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-08-08 12:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-01 13:43 [PATCH] Better handling labels in source code blocks + A suggestion Bernard Hurley
2016-08-01 13:53 ` Bernard Hurley
2016-08-08 12:23 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.