From mboxrd@z Thu Jan 1 00:00:00 1970 From: "ZHUO QL (KDr2)" Subject: Proposal: references from code to text. Date: Sat, 12 May 2018 13:29:48 +0000 (UTC) Message-ID: <800808596.465327.1526131788117@mail.yahoo.com> References: <800808596.465327.1526131788117.ref@mail.yahoo.com> Reply-To: "ZHUO QL \(KDr2\)" Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_465326_947387514.1526131788116" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fHUb0-0008KU-1w for emacs-orgmode@gnu.org; Sat, 12 May 2018 09:29:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fHUaw-0002Xn-3g for emacs-orgmode@gnu.org; Sat, 12 May 2018 09:29:58 -0400 Received: from sonic301-21.consmr.mail.gq1.yahoo.com ([98.137.64.147]:41427) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fHUav-0002XC-Q7 for emacs-orgmode@gnu.org; Sat, 12 May 2018 09:29:54 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org ------=_Part_465326_947387514.1526131788116 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi all, I just post a proposal for orgmode on my website(generated by orgmo= de): http://kdr2.com/tech/emacs/1805-proposal-org-ref-code-to-text.html=C2=A0. Here is the source of the proposal: # -*- mode: org; mode: auto-fill; -*- #+TITLE: Proposal for Orgmode: references from code to text. #+AUTHOR: KDr2 #+OPTIONS: toc:nil #+OPTIONS: num:nil #+BEGIN: inc-file :file "common.inc.org" #+END: #+CALL: dynamic-header() :results raw #+CALL: meta-keywords(kws=3D'("orgmode" "literate programming")) :results r= aw # - DATE <2018-05-12 Sat> Literate programming is writing out the program logic in a human language with included (separated by a primitive markup) code snippets and macros. A preprocessor is used to substitute arbitrary hierarchies, or rather "interconnected 'webs' of macros", to produce the compilable source code with one command ("tangle"), and documentation with another ("weave"). So in a literate programming source file, any chunk is either a block of code or a block of document in a human language, I'll call them *code* and *text* below. In my opinion, code and text should be able to reference each other: - *Text refers to text* \\ In the exported/woven documentation, these references act as links, make interconnections between relevant topics. - *Text refers to code* \\ The links in the exported/woven documentation can also link to a line of code if the code blocks are also included in the exported/woven documentation. - *Code refers to code* \\ That's the most important part of the literate programming. This kind of references act as placeholders or something like macro in the C-programming language. With it, literate programming provides an ability to change the order of the source code from a machine-imposed sequence to one convenient to the human mind. [[https://e= n.wikipedia.org/wiki/Literate_programming#Example][Here is a simple Example depicts this concept]]. - *Code refers to text* \\ So far as I know, no literate programming tool has this kind of references. However, this kind of references could be very benifical too. Many programming languages have a mechanism to support embedding documentation(usually as comments) in the source code, AKA [[https://en.wikipedia.org/wiki/Docstring][Docstring]]. These embedded do= cumentations are widely and conveniently used in editor, REPL and IDE. For instance, the docs of any elisp function that we can read in Emacs are from the elisp source. But in literate programming we seldom embed comments into the code blocks, as an impliaction the extracted/tangled code has no docs embeded. If we can refer to chunks of text in the code blocks, we will have the chance to include these chunks of text as embeded docs in the code in the tangling process, which results in well-documented source code. This is useful especially while the programmer are authoring reusable source code, like libraries or frameworks. Here is the implementation status of these kinds of references of noweb and Org mode (~->~ means 'has the ability to make reference to'): | tool | text -> text | code -> code | text -> code | code -> t= ext | |----------+--------------+------------------+----------------+----------= ----| | noweb | No | Yes | No | No = | | Org mode | Yes, links | Yes, noweb style | Yes, ~(ref:*)~ | No = | As we saw, both noweb and Org mode do not implement the reference from code to text. Could we provide this feature in Org mode -- the best and widely used literate programming tool? As a proposal, in Org mode, we can mimic the labels in code blocks(i.e. text -> code reference), use something like ~(ref:text:)~ as the reference from code to text: #+BEGIN_SRC org ,#+NAME: DOC-OF-ADD We use the function add to calculate the sum of two numbers. ,#+BEGIN_SRC elisp (defun add (x y) "(ref:text:DOC-OF-ADD)" (+ x y)) ,#+END_SRC #+END_SRC The Org file above will produce the code below: #+BEGIN_SRC elisp (defun add (x y) "We use the function add to calculate the sum of two numbers." (+ x y)) #+END_SRC - Beside the ~NAME~, we could also support reference via the ~CUSTOM_ID~ property or anything else that can locate a text chunk. - In the tangling process, we should do some kind of transformation of the target text, for example, escape the quote mark. A hook may be needed to let the user customize the transformation too. What do you think? * References - https://en.wikipedia.org/wiki/Literate_programming - https://en.wikipedia.org/wiki/Noweb - https://en.wikipedia.org/wiki/Docstring - http://orgmode.org/manual/Extracting-source-code.html#Extracting-source= -code - http://orgmode.org/manual/Noweb-reference-syntax.html#Noweb-reference-s= yntax - http://orgmode.org/manual/Literal-examples.html#Literal-examples - https://orgmode.org/worg/dev/org-syntax.html * Discuss and Comment #+BEGIN: inc-file :file "comment.inc.org" #+END: ------=_Part_465326_947387514.1526131788116 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
Hi all, I just post a proposal for orgmode on my website(generated by orgmode):


Here is the source of the proposal:

# -*- mode: org; mode: auto-fill; -*-
#+TITLE: Proposal for Orgmode: references from code to text.
#+AUTHOR: KDr2

#+OPTIONS: toc:nil
#+OPTIONS: num:nil

#+BEGIN: inc-file :file "common.inc.org"
#+END:
#+CALL: dynamic-header() :results raw
#+CALL: meta-keywords(kws='("orgmode" "literate programming")) :results raw

# - DATE
<2018-05-12 Sat>


Literate programming is writing out the program logic in a human
language with included (separated by a primitive markup) code snippets
and macros. A preprocessor is used to substitute arbitrary
hierarchies, or rather "interconnected 'webs' of macros", to produce
the compilable source code with one command ("tangle"), and
documentation with another ("weave").

So in a literate programming source file, any chunk is either a block
of code or a block of document in a human language, I'll call them
*code* and *text* below.

In my opinion, code and text should be able to reference each other:

- *Text refers to text* \\
  In the exported/woven documentation, these references act as links,
  make interconnections between relevant topics.
- *Text refers to code* \\
  The links in the exported/woven documentation can also link to a
  line of code if the code blocks are also included in the
  exported/woven documentation.
- *Code refers to code* \\
  That's the most important part of the literate programming. This
  kind of references act as placeholders or something like macro in
  the C-programming language. With it, literate programming provides
  an ability to change the order of the source code from a
  machine-imposed sequence to one convenient to the human mind. [[https://en.wikipedia.org/wiki/Literate_programming#Example][Here
  is a simple Example depicts this concept]].
- *Code refers to text* \\
  So far as I know, no literate programming tool has this kind of
  references. However, this kind of references could be very benifical
  too. Many programming languages have a mechanism to support
  embedding documentation(usually as comments) in the source code, AKA
  [[https://en.wikipedia.org/wiki/Docstring][Docstring]]. These embedded documentations are widely and conveniently
  used in editor, REPL and IDE. For instance, the docs of any elisp
  function that we can read in Emacs are from the elisp source.

  But in literate programming we seldom embed comments into the code
  blocks, as an impliaction the extracted/tangled code has no docs
  embeded. If we can refer to chunks of text in the code blocks, we
  will have the chance to include these chunks of text as embeded docs
  in the code in the tangling process, which results in
  well-documented source code. This is useful especially while the
  programmer are authoring reusable source code, like libraries or
  frameworks.

Here is the implementation status of these kinds of references of
noweb and Org mode (~->~ means 'has the ability to make reference
to'):

  | tool     | text -> text | code -> code     | text -> code   | code -> text |
  |----------+--------------+------------------+----------------+--------------|
  | noweb    | No           | Yes              | No             | No           |
  | Org mode | Yes, links   | Yes, noweb style | Yes, ~(ref:*)~ | No           |


As we saw, both noweb and Org mode do not implement the reference from
code to text. Could we provide this feature in Org mode -- the best
and widely used literate programming tool?

As a proposal, in Org mode, we can mimic the labels in
code blocks(i.e. text -> code reference), use something like
~(ref:text:<REF-NAME>)~ as the reference from code to text:

#+BEGIN_SRC org
  ,#+NAME: DOC-OF-ADD
  We use the function add to calculate the sum of two numbers.

  ,#+BEGIN_SRC elisp
  (defun add (x y)
    "(ref:text:DOC-OF-ADD)"
    (+ x y))
  ,#+END_SRC
#+END_SRC

The Org file above will produce the code below:

#+BEGIN_SRC elisp
  (defun add (x y)
    "We use the function add to calculate the sum of two numbers."
    (+ x y))
#+END_SRC

- Beside the ~NAME~, we could also support reference via the
  ~CUSTOM_ID~ property or anything else that can locate a text chunk.
- In the tangling process, we should do some kind of transformation of
  the target text, for example, escape the quote mark. A hook may be
  needed to let the user customize the transformation too.

What do you think?

* References
  - https://en.wikipedia.org/wiki/Literate_programming
  - https://en.wikipedia.org/wiki/Noweb
  - https://en.wikipedia.org/wiki/Docstring
  - http://orgmode.org/manual/Extracting-source-code.html#Extracting-source-code
  - http://orgmode.org/manual/Noweb-reference-syntax.html#Noweb-reference-syntax
  - http://orgmode.org/manual/Literal-examples.html#Literal-examples
  - https://orgmode.org/worg/dev/org-syntax.html

* Discuss and Comment
  #+BEGIN: inc-file :file "comment.inc.org"
  #+END:

------=_Part_465326_947387514.1526131788116--