emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [feature] prepend comment char before org-babel-ref
@ 2018-01-24  4:24 numbchild
  2018-01-24 13:40 ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: numbchild @ 2018-01-24  4:24 UTC (permalink / raw)
  To: Org-mode

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

I'm currently using this advice:
```elisp
;;; prepend comment char ahead of `org-babel-ref'.
;; auto prefix with comment char when create code ref in src block with
`org-store-link'.
(defun org-babel-ref-prepend-comment-char (arg &optional interactive?)
  "Prepend comment chart in Org-mode src code block."
  (when (org-src-edit-buffer-p)
    (comment-dwim nil)
    (insert " ")))

(advice-add 'org-store-link :before #'org-babel-ref-prepend-comment-char)
```

There is another solution but not work:
```elisp
;;; Another implement solution.
(defun org-src-coderef-format (&optional element)
  (cond
   ((and element (org-element-property :label-fmt element)))
   ((org-src-edit-buffer-p) (org-src-do-at-code-block
(org-src-coderef-format)))
   ((org-element-property :label-fmt (org-element-at-point)))
   (t org-coderef-label-format)))

(defun org-src-coderef-prepend-comment-char (args)
  "Prepend comment chart in Org-mode src code block."
  (when (org-src-edit-buffer-p)
    (comment-dwim nil)
    (insert " ")))

(advice-add 'org-src-coderef-format :filter-return
            #'org-src-coderef-prepend-comment-char)
```

I think this function should be in Org-mode itself.
Because when you're editing the source code, will not want this src-coderef
like `(ref:example)` be editable. It should be in comment.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

[-- Attachment #2: Type: text/html, Size: 2933 bytes --]

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-24  4:24 [feature] prepend comment char before org-babel-ref numbchild
@ 2018-01-24 13:40 ` Nicolas Goaziou
  2018-01-25 13:12   ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2018-01-24 13:40 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode

Hello,

"numbchild@gmail.com" <numbchild@gmail.com> writes:

> I think this function should be in Org-mode itself.
> Because when you're editing the source code, will not want this src-coderef
> like `(ref:example)` be editable. It should be in comment.

Thank you for the suggestion. However I have some doubts about this.

What it the comment syntax is not properly defined? What if the coderef
format already contains comment syntax? What if the language does not
support inline comments and you're in the middle of a line (e.g.,
FORTRAN)?

I'm wondering if this is really a panacea. The current situation, albeit
imperfect, is simple and easy to understand.

WDYT?

Regards,

-- 
Nicolas Goaziou

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-24 13:40 ` Nicolas Goaziou
@ 2018-01-25 13:12   ` numbchild
  2018-01-25 20:19     ` Nicolas Goaziou
  0 siblings, 1 reply; 9+ messages in thread
From: numbchild @ 2018-01-25 13:12 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

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

I see. Seems current ob-core.el can filter out the `src-coderef`.
Like the following:

#+begin_src emacs-lisp
(prin1 "hello, world!") (ref:hello)
#+end_src

#+RESULTS[<2018-01-25 20:28:40> 16eccfedcc87d3ca0c7024b2637c646d4708ec42]:
: hello, world!

#+begin_src ruby :results output
puts "hello, world!" (ref:hello)
#+end_src

#+RESULTS[<2018-01-25 20:46:21> e1e8632ccedf7cc3c676be0c89841a885bbcc7d9]:
: hello, world!

But about your questions:
> What it the comment syntax is not properly defined?
I think almost all programming language has comments. About some other
babels which don't have comment. I think `org-babel` can check whether
babel language has comment.
> What if the coderef format already contains comment syntax?
`org-babel` already use current coderef format. Keep current coderef format
is fine. If coderef format is like `#ref:label`. and Ruby language use
comment `#` too. Then after prepending comment char, it becomes `#
#ref:label`. It is fine. Right?
> What if the language does not support inline comments and you're in the
middle of a line?
It is fine too. Current coderef already support insert coderef format at
right align even I'm in the middle of a line. I tested.

All your questions solved.

My wanted feature is simple, just `(insert (concat comment-char
coderef-format))`

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Wed, Jan 24, 2018 at 9:40 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> "numbchild@gmail.com" <numbchild@gmail.com> writes:
>
> > I think this function should be in Org-mode itself.
> > Because when you're editing the source code, will not want this
> src-coderef
> > like `(ref:example)` be editable. It should be in comment.
>
> Thank you for the suggestion. However I have some doubts about this.
>
> What it the comment syntax is not properly defined? What if the coderef
> format already contains comment syntax? What if the language does not
> support inline comments and you're in the middle of a line (e.g.,
> FORTRAN)?
>
> I'm wondering if this is really a panacea. The current situation, albeit
> imperfect, is simple and easy to understand.
>
> WDYT?
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 4079 bytes --]

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-25 13:12   ` numbchild
@ 2018-01-25 20:19     ` Nicolas Goaziou
  2018-01-26 12:34       ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2018-01-25 20:19 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode

Hello,

"numbchild@gmail.com" <numbchild@gmail.com> writes:

> I see. Seems current ob-core.el can filter out the `src-coderef`.
> Like the following:

[...]

> My wanted feature is simple, just `(insert (concat comment-char
> coderef-format))`

Per the above, may I ask why you do need it?

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-25 20:19     ` Nicolas Goaziou
@ 2018-01-26 12:34       ` numbchild
  2018-01-26 12:35         ` numbchild
  2018-01-27 10:56         ` Nicolas Goaziou
  0 siblings, 2 replies; 9+ messages in thread
From: numbchild @ 2018-01-26 12:34 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

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

Because it is not good for tangling.
For example, tangle the bellowing src block, the tangled source code file
will has `(ref:hello)` too.
```
#+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
(message "hello, world") (ref:hello)
#+end_src
```
The tangled source code file looks like this:
```
(message "hello, world") (ref:hello)
```
This absolutely is not a good idea.



And after a test, I found I can't tangle the bellowing src block:
```
#+begin_src ruby :dir "data/code/src-coderef.rb"
puts "hello, world" (ref:hello)
#+end_src
```
Even with a comment char prefix:
```
#+begin_src ruby :dir "data/code/src-coderef.rb"
puts "hello, world" # (ref:hello)
#+end_src

```

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Fri, Jan 26, 2018 at 4:19 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> "numbchild@gmail.com" <numbchild@gmail.com> writes:
>
> > I see. Seems current ob-core.el can filter out the `src-coderef`.
> > Like the following:
>
> [...]
>
> > My wanted feature is simple, just `(insert (concat comment-char
> > coderef-format))`
>
> Per the above, may I ask why you do need it?
>
> Regards,
>
> --
> Nicolas Goaziou                                                0x80A93738
>

[-- Attachment #2: Type: text/html, Size: 3161 bytes --]

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-26 12:34       ` numbchild
@ 2018-01-26 12:35         ` numbchild
  2018-01-27 10:56         ` Nicolas Goaziou
  1 sibling, 0 replies; 9+ messages in thread
From: numbchild @ 2018-01-26 12:35 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

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

Sorry, I miss typed my header argument `:dir "data/code/src-coderef.rb"`.
It should be `:tangle`.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Fri, Jan 26, 2018 at 8:34 PM, numbchild@gmail.com <numbchild@gmail.com>
wrote:

> Because it is not good for tangling.
> For example, tangle the bellowing src block, the tangled source code file
> will has `(ref:hello)` too.
> ```
> #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
> (message "hello, world") (ref:hello)
> #+end_src
> ```
> The tangled source code file looks like this:
> ```
> (message "hello, world") (ref:hello)
> ```
> This absolutely is not a good idea.
>
>
>
> And after a test, I found I can't tangle the bellowing src block:
> ```
> #+begin_src ruby :dir "data/code/src-coderef.rb"
> puts "hello, world" (ref:hello)
> #+end_src
> ```
> Even with a comment char prefix:
> ```
> #+begin_src ruby :dir "data/code/src-coderef.rb"
> puts "hello, world" # (ref:hello)
> #+end_src
>
> ```
>
> [stardiviner]           <Hack this world!>      GPG key ID: 47C32433
> IRC(freeenode): stardiviner                     Twitter:  @numbchild
> Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
> Blog: http://stardiviner.github.io/
>
> On Fri, Jan 26, 2018 at 4:19 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
> wrote:
>
>> Hello,
>>
>> "numbchild@gmail.com" <numbchild@gmail.com> writes:
>>
>> > I see. Seems current ob-core.el can filter out the `src-coderef`.
>> > Like the following:
>>
>> [...]
>>
>> > My wanted feature is simple, just `(insert (concat comment-char
>> > coderef-format))`
>>
>> Per the above, may I ask why you do need it?
>>
>> Regards,
>>
>> --
>> Nicolas Goaziou                                                0x80A93738
>>
>
>

[-- Attachment #2: Type: text/html, Size: 3957 bytes --]

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-26 12:34       ` numbchild
  2018-01-26 12:35         ` numbchild
@ 2018-01-27 10:56         ` Nicolas Goaziou
  2018-01-27 10:58           ` Nicolas Goaziou
  1 sibling, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2018-01-27 10:56 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode

Hello,

"numbchild@gmail.com" <numbchild@gmail.com> writes:

> Because it is not good for tangling.
> For example, tangle the bellowing src block, the tangled source code file
> will has `(ref:hello)` too.
> ```
>
> #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
> (message "hello, world") (ref:hello)
> #+end_src

You need to add "-r" switch so Org knows you want to remove coderefs:

  #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
  (message "hello, world") (ref:hello)
  #+end_src


Regards,

-- 
Nicolas Goaziou                                                0x80A93738

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-27 10:56         ` Nicolas Goaziou
@ 2018-01-27 10:58           ` Nicolas Goaziou
  2018-01-28  9:52             ` numbchild
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Goaziou @ 2018-01-27 10:58 UTC (permalink / raw)
  To: numbchild@gmail.com; +Cc: Org-mode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> "numbchild@gmail.com" <numbchild@gmail.com> writes:
>
>> Because it is not good for tangling.
>> For example, tangle the bellowing src block, the tangled source code file
>> will has `(ref:hello)` too.
>> ```
>>
>> #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
>> (message "hello, world") (ref:hello)
>> #+end_src
>
> You need to add "-r" switch so Org knows you want to remove coderefs:
>
>   #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
>   (message "hello, world") (ref:hello)
>   #+end_src

I meant

  #+begin_src emacs-lisp -r :tangle "data/code/src-coderef.el"
                        ^^^^

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

* Re: [feature] prepend comment char before org-babel-ref
  2018-01-27 10:58           ` Nicolas Goaziou
@ 2018-01-28  9:52             ` numbchild
  0 siblings, 0 replies; 9+ messages in thread
From: numbchild @ 2018-01-28  9:52 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org-mode

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

Thanks. @Nicolas

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

On Sat, Jan 27, 2018 at 6:58 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
> > Hello,
> >
> > "numbchild@gmail.com" <numbchild@gmail.com> writes:
> >
> >> Because it is not good for tangling.
> >> For example, tangle the bellowing src block, the tangled source code
> file
> >> will has `(ref:hello)` too.
> >> ```
> >>
> >> #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
> >> (message "hello, world") (ref:hello)
> >> #+end_src
> >
> > You need to add "-r" switch so Org knows you want to remove coderefs:
> >
> >   #+begin_src emacs-lisp :tangle "data/code/src-coderef.el"
> >   (message "hello, world") (ref:hello)
> >   #+end_src
>
> I meant
>
>   #+begin_src emacs-lisp -r :tangle "data/code/src-coderef.el"
>                         ^^^^
>

[-- Attachment #2: Type: text/html, Size: 2125 bytes --]

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

end of thread, other threads:[~2018-01-28  9:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-24  4:24 [feature] prepend comment char before org-babel-ref numbchild
2018-01-24 13:40 ` Nicolas Goaziou
2018-01-25 13:12   ` numbchild
2018-01-25 20:19     ` Nicolas Goaziou
2018-01-26 12:34       ` numbchild
2018-01-26 12:35         ` numbchild
2018-01-27 10:56         ` Nicolas Goaziou
2018-01-27 10:58           ` Nicolas Goaziou
2018-01-28  9:52             ` numbchild

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