From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Genovese Subject: Re: Four issues with org-babel-tangle Date: Thu, 15 Sep 2011 17:36:35 -0400 Message-ID: References: <87litphkf9.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec520f0b7f6627304ad01acf4 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:49267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4JcF-00008q-EA for emacs-orgmode@gnu.org; Thu, 15 Sep 2011 17:37:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R4Jc9-0003zE-VM for emacs-orgmode@gnu.org; Thu, 15 Sep 2011 17:37:03 -0400 Received: from mail-pz0-f41.google.com ([209.85.210.41]:62151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R4Jc9-0003yj-A3 for emacs-orgmode@gnu.org; Thu, 15 Sep 2011 17:36:57 -0400 Received: by pzk4 with SMTP id 4so2405476pzk.0 for ; Thu, 15 Sep 2011 14:36:55 -0700 (PDT) In-Reply-To: <87litphkf9.fsf@gmail.com> 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org --bcaec520f0b7f6627304ad01acf4 Content-Type: text/plain; charset=ISO-8859-1 Hi Eric, Thanks for your note. > I would encourage you to begin the FSF assignment process if > you anticipate potentially contributing more fixes in the > future. Could you please send a git format-patch version of > the simple fix to the list so that I might apply it? I will begin the FSF assignment process, and I will send a git-format patch based on the simple fix. (I'll send that tonight.) > I like the idea of introducing a customizable function for > comment text transformation, however ... rather perhaps we > should just leave the default value of this function as > simple as possible and allow users to customize it .... That makes sense, and I like the way you did it. In particular, I absolutely agree that the org-babel-trim should be removed from org-babel-spec-to-string (to allow flexibility in the customization). Making it the default processor works well, I think. Would you like me to submit a separate patch based on this change or should I include that as part of the patch with the simple fix? > Finally I'm not sure I fully understand what you mean by ... Sorry, I wasn't clear. It's a small thing. If you put '#+tangle' in column 0, the line is not exported because it begins with #; if you put #+ tangle on a line (spaces after + and possibly before #), the line is not exported because it begins with #+; but if you put #+tangle (no spaces after the + but spaces before the #), the line is exported. I think it would be useful if something like #+tangle's (with no spaces between the # and +) were *not* exported because such lines can support useful customizations. Having to put the spaces after the + is a bit bothersome and looks uglier to me. > ..., it was a long email. Yeah, sorry. :) Thanks for slogging through. Best, Christopher On Thu, Sep 15, 2011 at 11:49, Eric Schulte wrote: > Hi Christopher, > > Thank you for the thorough examples and for suggesting fixes. I would > like to apply your "simple fix" immediately, and the resulting patch > should be small enough (less than 10 lines of changes) that it can be > applied without FSF assignment -- although I would encourage you to > begin the FSF assignment process if you anticipate potentially > contributing more fixes in the future. Could you please send a git > format-patch version of the simple fix to the list so that I might apply > it? > > I like the idea of introducing a customizable function for comment text > transformation, however I'm not sure that the temporary-buffer mechanics > need to be included by default, rather perhaps we should just leave the > default value of this function as simple as possible and allow users to > customize it to be as simple or complex as they wish. Perhaps a change > like the following, where the call to `org-babel-trim' in > `org-babel-spec-to-string' is removed. > > #+begin_src emacs-lisp > (buffer-substring > (max (condition-case nil > (save-excursion > (org-back-to-heading t) (point)) > (error 0)) > (save-excursion > (re-search-backward > org-babel-src-block-regexp nil t) > (match-end 0))) > (point)) > > ;; | becomes > ;; v > > (org-babel-process-comment-text > (buffer-substring > (max (condition-case nil > (save-excursion > (org-back-to-heading t) (point)) > (error 0)) > (save-excursion > (re-search-backward > org-babel-src-block-regexp nil t) > (match-end 0))) > (point))) > > ;; where > > (defcustom org-babel-process-comment-text #'org-babel-trim > "Customizable function for processing comment text." > :group 'org-babel > :type 'function) > #+end_src > > This change may end up being more than 10 lines long, but a patch would > still be welcome, otherwise if the solution I sketched out above sounds > reasonable I could compose a patch and then share it with you for double > checking before it is applied. > > Finally I'm not sure I fully understand what you mean by > > > > > [fn:2] A feature request: I would propose that the =#+tangle:= construct > > be recognized as non-exported even with spaces preceding the =#= and no > > spaces after the =+=. This would enable a variety of interesting > > customization for tangled comments. Alternatively, a generic construct > > such as =#+noop:= or =#+generic:= could be a valuable for user-based > > tags in an org file that serves a similar purpose -- allow customized > > processing without directly being exported. > > > > Please do let me know if I missed anything, it was a long email. > > Thanks for contributing! -- Eric > > Christopher Genovese writes: > > > /Semi-verbose Preamble/. > > Having recently begun intensive use of org-mode for tangling source > > files, I encountered four issues related to comment extraction (two > > bugs, one undesirable behavior, and one ... unfulfilled need), which I > > describe in detail below. I started by creating an org file that would > > reproduce the problems, and soon started /describing/ the problems in > > the org file as well as putting my fixes in the source blocks. At the > > risk of it being too meta or annoying, I've included that org file at > > the end of this message as the problem description. All the details are > > there as well as two fixes. Tangling that file in various ways described > > demonstrates the problems, and you can export to PDF for nicer reading. > > (I've attached the PDF to this mail for convenience. It looks good; > > kudos, org-mode!) I've also attached a tarball with files that make it > > easy to try my changes and to restore the original behavior, as well as > > tests and results from the org file for easy comparison. See the > > included README. > > > > I've been using the revised code now for a few days. It fixes the > > problems I describe, and I think it provides a flexible framework for > > comment extraction with minimal change to the base code. If the reaction > > to this is positive, I will happily submit a patch, sign paperwork, or > > whatever is needed, after fixing any problems that you all see. In any > > case, I very much look forward to any feedback you can offer. Thanks. > > > > -- Christopher > > > > P.S. In case the attachments get dropped, I've put the PDF and the > > tarball at > > > > http://www.stat.cmu.edu/~genovese/depot/tangle-error.pdf > > http://www.stat.cmu.edu/~genovese/depot/tangle-bundle.tgz > > > > /Problem Description/ > > ################ Cut Here #################### > > # -*- org-return-follows-link: t; comment-empty-lines: t; -*- > > #+TITLE: Tangle this file: four issues with org-babel-tangle > > #+AUTHOR: Christopher Genovese > > #+DATE: 14 Sep 2011\vspace*{-0.5cm} > > #+EMAIL: genovese@cmu.edu > > #+OPTIONS: toc:1 H:1 > > #+BABEL: :tangle yes :comments org :results silent :exports code > > #+BIND: org-export-latex-hyperref-format "\\hyperlink{%s}{%s}" > > #+STARTUP: showall > > #+LATEX_HEADER: \usepackage[labelsep=period,labelfont=bf]{caption} > > #+LaTeX: \vspace*{-1cm}\vspace*{-2pt} > > > > > > * Four Related Issues with org-babel-tangle > > > > Running org-mode version 7.7 on both Gnu Emacs 23.2.1 and 24.0.50.1 > > with Mac OS X 10.5.8 (with and without a -Q option), I encountered the > > following issues/problems/bugs when tangling files with code blocks > > for which the :comment header argument is org: > > > > 1. The subtree associated with the very first code block has > > its headline tangled without leading stars, but all subsequent > > sub-trees associated with code blocks have the leading stars > > included in the comments. > > > > 2. If the first code block comes before the first headline, the start > > of the comment text will be determined by pre-existing match data > > and thus will likely be incorrect. > > > > 3. Org structural elements such as headline stars, =#+= control lines, > > and drawers are included in the comments. > > > > 4. There is no way easy to delimit comment text or transform it that > > does not also change the structure of the org file (e.g., by adding > > headlines or source blocks). > > > > Issues 1 and 2 seem to be genuine bugs. Issues 3 and 4 are more > > subjective, I admit, but seem undesirable. Stars, drawers, and > > control lines are org structure rather than content, and they > > are often inappropriate in comments. > > > > To reproduce the behaviors for issues 1 and 3, look at the result of > > tangling this file. To reproduce issue 2 as well, remove the first two > > stars from this file and tangle again. Alternatively, within emacs, > > evaluate the =(buffer-substring ...)= sexp from the original-code code > > below at the beginning character of a source block. (You > > can also export this file to PDF for more pleasant reading.) > > > > Below, I give details on these issues and code for two fixes: > > a [[simple-fix][simple fix]] that handles the first two issues and the > > stars in the third, > > and a [[preferred-fix][better fix]] that handles all four issues in a > more > > modular, customizable framework. I'd be interested in hearing > > feedback on all of this. If the reaction is positive, I will gladly > > submit a patch. Thanks for your consideration. > > > > > > > > * The Original Code and Details on the Problem > > > > The relevant section of the original code from org-mode version 7.7 > > is shown below, comprising lines 344 through 357 > > of ob-tangle.el in function =org-babel-tangle-collect-blocks=. With > point > > is at a =#+begin_src=, it scans back either > > for a heading line or for the end of the previous code block, > > whichever comes later. The resulting region becomes the > > comment text. > > > > #+latex: \begin{figure}[h] > > #+latex: \hypertarget{original-code}{} % <> > > #+source: original-code > > #+begin_src emacs-lisp > > (comment > > (when (or (string= "both" (cdr (assoc :comments params))) > > (string= "org" (cdr (assoc :comments params)))) > > ;; from the previous heading or code-block end > > (buffer-substring > > (max (condition-case nil > > (save-excursion > > (org-back-to-heading t) (point)) > > (error 0)) > > (save-excursion > > (re-search-backward > > org-babel-src-block-regexp nil t) > > (match-end 0))) > > (point)))) > > #+end_src > > #+latex: \caption{Original Code, lines 344--357 in {\tt ob-tangle.el}.} > > #+latex: \label{fig::original-code} > > #+latex: \end{figure} > > > > /Issue 1/. When in the first code block in the file, the > > second search fails (there is no previous code block), > > so the (match-end 0) call uses the match data from the (implicit) > match > > during > > =org-back-to-heading=, which skips the stars. (Not a particularly > > transparent reference, incidentally.) For subsequent blocks, the > > =(match-end 0)= gives the end of the previous code block, which in > these > > examples is earlier than the previous headline location. > > > > /Issue 2/. When the first code block lies before the first headline > > (say with some text before it), the searches fail in /both/ clauses of > > the max. So, the =match-end= will return an essentially arbitrary > > result, which is a bug. > > > > /Issue 3/. =org-back-to-heading= leaves point at the beginning of the > > stars, so a headline included in the text will have stars, except for > > the first one. > > > > /Issue 4/. Control lines at the end of the previous code block and > > before point are not filtered out and so are included in the comments. > > > > > > * A Simple Fix for the First Three Issues > > > > A small change addresses issues 1, 2, and the stars for issue 3: in > > both cases, simply use the =match-end= and replace 0 values with > > =(point-min)=. The latter gives a sensible result even if both > > computed positions are trivial (as when the first code block comes > > before the first headline) and respects narrowing. > > > > #+latex: \begin{figure}[h] > > #+latex: \hypertarget{simple-fix}{} % <> > > #+begin_src emacs-lisp > > (comment > > (when (or (string= "both" (cdr (assoc :comments params))) > > (string= "org" (cdr (assoc :comments params)))) > > ;; from the previous heading or code-block end > > (buffer-substring > > (max (condition-case nil > > (save-excursion > > (org-back-to-heading t) ; sets match data > > (match-end 0)) > > (error (point-min))) > > (save-excursion > > (if (re-search-backward > > org-babel-src-block-regexp nil t) > > (match-end 0) > > (point-min)))) > > (point)))) > > #+end_src > > #+latex: \caption{Simple Fix, replacement for lines 344--357 in {\tt > > ob-tangle.el}.} > > #+latex: \label{fig::simple-fix} > > #+latex: \end{figure} > > > > * A Fix for All Four Issues > > > > A better fix that handles issues 1--4 starts with the region computed > as > > in the [[simple-fix][simple fix]] > > and then processes that text through a user-configurable sequence of > > functions > > to derive the final form of the comment text. > > > > The following changes are required. > > > > ** Extract Initial Comment Text and State from Org Buffer > > > > The initial comment text ranges from either the most recent headline > > at the point after the stars, the beginning of the line after the > > =#+end_src= of the most recent code block, or the beginning of the > > buffer, whichever is later, through the line before the source > > block.[fn:1] > > > > The [[preferred-fix][code]] to extract this is given below. > > #+latex: (See Figure \ref{fig::preferred-fix}.) > > It replaces lines 344 through 357 of > > =ob-tangle.el= from org-mode version 7.7 in the function > > =org-babel-tangle-collect-blocks=. > > > > #+latex: \begin{figure}[h] > > #+latex: \hypertarget{preferred-fix}{} % <> > > #+begin_src emacs-lisp > > (comment > > (when (or (string= "both" (cdr (assoc :comments params))) > > (string= "org" (cdr (assoc :comments params)))) > > (let* ((prev-heading > > (condition-case nil > > (save-excursion > > (org-back-to-heading t) ; sets match data > > (match-end 0)) > > (error (point-min)))) > > (end-of-prev-src-block > > (save-excursion > > (if (null (re-search-backward > > org-babel-src-block-regexp nil t)) > > (point-min) > > (goto-char (match-end 0)) > > (forward-line 1) > > (point)))) > > (comment-start > > (max prev-heading end-of-prev-src-block)) > > (comment-end > > (save-excursion > > (forward-line 0) > > (point))) > > (state > > (list (cons 'org-drawers > > org-drawers) > > (cons 'after-heading > > (= comment-start prev-heading)) > > (cons 'first-line > > (= comment-start (point-min)))))) > > (org-babel-process-comment-text > > (buffer-substring comment-start comment-end) state)))) > > #+end_src > > #+latex: \caption{Better Fix, replacement for lines 344--357 in {\tt > > ob-tangle.el}.} > > #+latex: \label{fig::preferred-fix} > > #+latex: \end{figure} > > > > ** Adjust =org-babel-spec-to-string= > > > > The commment block collected by the [[original-code][original code]] > > #+latex: (Figure \ref{fig::original-code}) > > in =org-babel-tangle-collect-blocks= is further processed in \newline > > =org-babel-spec-to-string= to trim leading and trailing whitespace > > from string. This was needed because spaces after a source block were > > included in the comment. In the revised code, however, this space > > trimming is handled during text transformation, except for removing > > trailing newlines. (Note: trailing /spaces/ are not removed to allow > > more flexibility in comment processing.) Hence, > > =org-babel-spec-to-string= needs to be slightly adjusted. > > #+latex: See Figure \ref{fig::spec-string-diff}. > > > > #+latex: \begin{figure}[h] > > #+begin_example > > --- ob-tangle.el 2011-09-14 11:48:26.000000000 -0400 > > +++ new-ob-tangle.el 2011-09-14 11:55:56.000000000 -0400 > > @@ -398,3 +398,3 @@ > > (flet ((insert-comment (text) > > - (let ((text (org-babel-trim text))) > > + (let ((text (org-babel-chomp text "[\f\t\n\r\v]"))) > > (when (and comments (not (string= comments "no")) > > #+end_example > > #+latex: \caption{Changes to {\tt org-spec-to-string} in {\tt > > ob-tangle.el}, unified diff, one line of context} > > #+latex: \label{fig::spec-string-diff} > > #+latex: \end{figure} > > > > ** Process Comment Text Through Sequence of Transforms > > > > At the end of the revised [[preferred-fix][comment collection code]], > > the comment text is passed to > > =org-babel-process-comment-text= which > > applies a sequence of transformation functions. > > #+latex: (See Figure \ref{fig::comment-transformation}.) > > The list of transformation functions is stored in a customizable > > variable described [[Define Customization Variable for > > Transforms][below]]. Several predefined transformations are > > given [[Define A Collection of Transform Functions][below]] as well. > > > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-process-comment-text (text &optional state) > > "Apply list of transforms to comment TEXT assuming bindings in > alist > > STATE. > > Returns the modified text string, which may have text properties. > > See `org-babel-comment-processing-functions' for the transforms to > be > > applied and details on the allowed keys in the STATE alist." > > (let ((funcs org-babel-comment-processing-functions)) > > (with-temp-buffer > > (insert text) > > (let ((org-drawers > > (or (cdr (assoc 'org-drawers state)) > > org-drawers)) > > (after-heading > > (cdr (assoc 'after-heading state))) > > (first-line > > (cdr (assoc 'first-line state)))) > > (while funcs > > (goto-char (point-min)) > > (funcall (car funcs)) > > (setq funcs (cdr funcs)))) > > (buffer-substring (point-min) (point-max))))) > > #+end_src > > #+latex: \caption{Better Fix, comment transformation driver.} > > #+latex: \label{fig::comment-transformation} > > #+latex: \end{figure} > > > > ** Define Customization Variable for Transforms > > > > A list of nullary functions applied in order to > > the comment text. The text is inserted > > in a temporary buffer, so these functions can use > > the entire Emacs library for operating on buffer text. > > #+latex: See Figure \ref{fig::comment-transformation-function-list}. > > > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defcustom org-babel-comment-processing-functions > > '(org-babel-comment-delete-file-variables-line > > org-babel-comment-delete-org-control-lines > > org-babel-comment-delete-drawers > > org-babel-comment-trim-blank-lines > > org-babel-comment-trim-indent-prefix) > > "List of functions to transform source-block comment text before > > insertion. > > Each function will be called with no arguments with point at the > > beginning of a buffer containing only the comment text. Each > > function can modify the text at will and leave point anywhere, > > but it should *not* modify the narrowing state of the buffer. > > Several dynamic state variables are set prior to execution that > > each function can reference. These currently include: > > > > + org-drawers: names of drawers in the original org buffer. > > + from-heading: t if comment starts at an org heading line, > > nil otherwise. > > + first-line: t if initial comment starts on first line > > of the original org buffer, nil otherwise. > > > > If a function changes the value of these state variables, the new > > value will be seen by all following functions in the list, but > > this is not generally recommended. > > > > The functions in this list are called *in order*, and this order > > can influence the form of the resulting comment text." > > :group 'org-babel > > :type 'list) > > #+end_src > > #+latex: \caption{Better Fix, customizable transform list.} > > #+latex: \label{fig::comment-transformation-function-list} > > #+latex: \end{figure} > > > > ** Define A Collection of Transform Functions > > > > An advantage of this design is that transformation of the > > comments is modular and customizable. We can include in > > =ob-tangle.el= a collection of pre-defined transforms. > > The default processing stream in > =org-babel-comment-processing-functions= > > is as follows: > > > > 1. Delete a file variables if on the first line of the buffer. > > 2. Delete all drawers and their contents. > > 3. Delete all org control lines from the comment text. > > 4. Trim blank lines from the beginning and end. > > 5. Reindent the text by removing the longest common leading > > string of spaces. > > > > #+ TANGLE: end-comment > > These and several other useful transforms are given below > > (e.g., deleting drawer delimiters but not contents).. > > #+latex: See Figures \ref{fig::transformA}--\ref{fig::transformZ}. > > It is easy to define new transforms; any function that > > operates on text in the current buffer beginning at point-min > > will work. > > > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-delete-file-variables-line () > > "Delete file variables comment line if at beginning of buffer. > > This only checks the first line of the buffer, and so should be > > placed first (or at least early enough) in the list > > `org-babel-comment-processing-functions' to ensure that the no > > other text has been inserted earlier." > > (when (and first-line > > (looking-at ; file-variables line > > "^#[ \t]*-\\*-.*:.*;[ \t]**-\\*-[ \t]*$")) > > (let ((kill-whole-line t)) > > (kill-line)))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \label{fig::transformA} > > #+latex: \end{figure} > > > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-delete-org-control-lines () > > "Remove all org #+ control lines from comment." > > (let ((control-regexp "^[ \t]*#\\+.*$")) > > (delete-matching-lines control-regexp))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \end{figure} > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-delete-org-in-buffer-settings () > > "Remove all org #+ in-buffer setting lines, leaving other control > > lines. > > In-buffer setting lines begin with #+ and have all caps keyword > > names." > > (let ((setting-regexp "^#\\+[ \t]*[A-Z_]+:.*$")) > > (delete-matching-lines setting-regexp))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \end{figure} > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-delete-drawers () > > "Delete drawer delimiters and contents from comment. > > Drawer names are restricted to those in the `org-drawers' state." > > (let ((drawer-start-regexp > > (format "^[ \t]*:\\(?:%s\\):[ \t]*$" > > (mapconcat 'identity > > org-drawers > > "\\|"))) > > (drawer-end-regexp "^[ \t]*:END:[ \t]*$")) > > (while (re-search-forward drawer-start-regexp nil t) > > (let ((beg (save-excursion > > (forward-line 0) > > (point))) > > (end (save-excursion > > (re-search-forward drawer-end-regexp nil t) > > (forward-line 1) > > (point)))) > > (goto-char end) > > (delete-region beg end))))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \end{figure} > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-delete-drawer-delimiters () > > "Delete drawer delimiters from comment leaving content. > > Drawer names are restricted to those given by the `org-drawers' > > state." > > (let ((drawer-delim-regexp > > (format "^[ \t]*:\\(?:%s\\)" > > (mapconcat 'identity > > (cons "END" org-drawers) > > "\\|")))) > > (delete-matching-lines drawer-delim-regexp))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \end{figure} > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-trim-blank-lines () > > "Trim whitespace-only lines from beginning and end of text." > > (while (and (looking-at "^[ \t\f]*$") > > (< (point) (point-max))) > > (forward-line 1)) > > (delete-region (point-min) (point)) > > (when (< (point) (point-max)) > > (goto-char (point-max)) > > (let ((last-point (point))) > > (forward-line 0) > > (while (and (looking-at "^[ \t\f]*$") > > (> (point) (point-min))) > > (setq last-point (point)) > > (forward-line -1)) > > (delete-region last-point (point-max))))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \end{figure} > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-trim-indent-prefix () > > "Remove longest common leading prefix of spaces from each line of > > TEXT. > > Prefix is computed from the initial whitespace on each line with > > tabs converted to spaces, preserving indentation." > > (let* ((common-indent nil) > > (common-length (1+ (- (point-max) (point-min)))) > > (current-indent "") ; enter first loop > > (current-length common-length)) ; skip first > assignment > > (goto-char (point-min)) > > (while current-indent > > (when (< current-length common-length) > > (setq common-indent current-indent > > common-length current-length)) > > (setq current-indent > > (let* ((found (re-search-forward "^\\([ \t]*\\)\\S-" nil > > t)) > > (bol (match-beginning 0)) > > (eos (match-end 1)) > > (space-str (match-string 1)) > > (indent-tabs-mode nil)) > > (cond > > ((not found) > > nil) > > ((not (string-match "\t" space-str)) > > space-str) > > (t ; detabify indent string > > (goto-char eos) > > (let ((col (current-column))) > > (delete-region bol eos) > > (indent-to col)) > > (buffer-substring-no-properties bol (point)))))) > > (setq current-length (length current-indent))) > > (when (and common-indent (> common-length 0)) > > (let ((indent-re (concat "^" common-indent))) > > (goto-char (point-min)) > > (while (re-search-forward indent-re nil t) > > (replace-match "" nil nil)))))) > > #+end_src > > #+latex: \caption{Comment Transform.} > > #+latex: \label{fig::transformZ} > > #+latex: \end{figure} > > #+latex: \end{itemize} > > #+latex: \noindent > > This kind of customization offers some nice possibilities, > > including controlling indentation, eliminating or > > transforming org markup, eliminating trailing whitespace, and > > automating specialized comment formatting (e.g., javadoc). As > > an additional illustration, consider the transform > > =org-babel-comment-restrict-comment-range= > > #+latex: in Figure \ref{fig::transform-illustration} > > below. The idea is that it is sometimes useful to select > > from the text under a headline a /part/ of the text for > > the comment. We want some org markup that will not affect > > either the export or the structure of the org file itself. > > To do this, we use the fact that =#+=\textvisiblespace > > lines are not exported.[fn:2] So, we can /de facto/ use the > > =#+ TANGLE:= construct to control various aspects of tangling. > > Here, we use the =#+ TANGLE: start-comment= and > > =#+ TANGLE: end-comment= to delimit the comment text. > > (This function needs to come earlier in the function list than the > > functions that eliminate org control lines. It is sufficient to > > prepend it to that list.) This is used in the current file, > > for example. > > > > #+latex: \begin{figure}[h] > > #+begin_src emacs-lisp > > (defun org-babel-comment-restrict-comment-range () > > "Remove all comment text outside start-comment and end-comment > > delimiters. > > Comment delimiters are #+TANGLE lines with respective keywords > > start-comment and end-comment. THE #+TANGLE lines are also > > deleted. To be effective, this function should be positioned in > > the list `org-babel-comment-processing-functions' before any > > functions that remove org control lines or process other > > co-occuring attributes of #+TANGLE lines." > > (when (re-search-forward "^[ \t]*#\\+[ > \t]*TANGLE:.*start-comment.*$" > > nil t) > > (forward-line 1) > > (delete-region (point-min) (point))) > > (when (re-search-forward "^[ \t]*#\\+[ > \t]*TANGLE:.*end-comment.*$" > > nil t) > > (forward-line 0) > > (delete-region (point) (point-max)))) > > #+end_src > > #+latex: \caption{Transform to illustrate some customization > > possibilities.} > > #+latex: \label{fig::transform-illustration} > > #+latex: \end{figure} > > #+latex: \begin{itemize} > > > > [fn:1] In the original code and in the simple fix above, the comment > > starts /immediately/ after the =#+end_src= rather than at the start of > > the next line. Starting at the next line seems more natural to me > > because the comment being constructed relates to the /following/ code > > block. But the original behavior is easily restored if people disagree. > > > > [fn:2] A feature request: I would propose that the =#+tangle:= construct > > be recognized as non-exported even with spaces preceding the =#= and no > > spaces after the =+=. This would enable a variety of interesting > > customization for tangled comments. Alternatively, a generic construct > > such as =#+noop:= or =#+generic:= could be a valuable for user-based > > tags in an org file that serves a similar purpose -- allow customized > > processing without directly being exported. > > > > > > -- > Eric Schulte > http://cs.unm.edu/~eschulte/ > --bcaec520f0b7f6627304ad01acf4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Eric,
=A0=A0
=A0=A0 Thanks for your note.

> I would enc= ourage you to begin the FSF assignment process if
> you anticipate po= tentially contributing more fixes in the
> future. Could you please s= end a git format-patch version of
> the simple fix to the list so that I might apply it?

=A0=A0 I w= ill begin the FSF assignment process, and I will send a git-format
patch= based on the simple fix. (I'll send that tonight.)

> I like = the idea of introducing a customizable function for
> comment text transformation, however ... rather perhaps we
> sho= uld just leave the default value of this function as
> simple as poss= ible and allow users to customize it ....

=A0=A0 That makes sense, a= nd I like the way you did it. In particular,
I absolutely agree that the org-babel-trim should be removed
from org-b= abel-spec-to-string (to allow flexibility in the customization).
Making = it the default processor works well, I think.

=A0=A0 Would you like = me to submit a separate patch based on this change
or should I include that as part of the patch with the simple fix?

&= gt; Finally I'm not sure I fully understand what you mean by ...
Sorry, I wasn't clear. It's a small thing. If you put
'#+ta= ngle' in column 0, the line is not exported because it
begins with #; if you put #+ tangle on a line (spaces
after + and possib= ly before #), the line is not exported
because it begins with #+; but if= you put #+tangle (no
spaces after the + but spaces before the #), the l= ine is
exported. I think it would be useful if something like
=A0#+tangle's= (with no spaces between the # and +) were
*not* exported because such l= ines can support
useful customizations. Having to put the spaces after = the +
is a bit bothersome and looks uglier to me.

> ..., it was a long= email.

Yeah, sorry. :) Thanks for slogging through.

=A0 Best= ,

=A0=A0=A0 Christopher


On Thu= , Sep 15, 2011 at 11:49, Eric Schulte <schulte.eric@gmail.com> wrote:
Hi Christopher,
Thank you for the thorough examples and for suggesting fixes. =A0I would like to apply your "simple fix" immediately, and the resulting pa= tch
should be small enough (less than 10 lines of changes) that it can be
applied without FSF assignment -- although I would encourage you to
begin the FSF assignment process if you anticipate potentially
contributing more fixes in the future. =A0Could you please send a git
format-patch version of the simple fix to the list so that I might apply it?

I like the idea of introducing a customizable function for comment text
transformation, however I'm not sure that the temporary-buffer mechanic= s
need to be included by default, rather perhaps we should just leave the
default value of this function as simple as possible and allow users to
customize it to be as simple or complex as they wish. =A0Perhaps a change like the following, where the call to `org-babel-trim' in
`org-babel-spec-to-string' is removed.

#+begin_src emacs-lisp
=A0(buffer-substring
=A0 (max (condition-case nil
=A0 =A0 =A0 =A0 =A0 =A0(save-excursion
=A0 =A0 =A0 =A0 =A0 =A0 =A0(org-back-to-heading t) (point))
=A0 =A0 =A0 =A0 =A0(error 0))
=A0 =A0 =A0 =A0(save-excursion
=A0 =A0 =A0 =A0 =A0(re-search-backward
=A0 =A0 =A0 =A0 =A0 org-babel-src-block-regexp nil t)
=A0 =A0 =A0 =A0 =A0(match-end 0)))
=A0 (point))

=A0;; | becomes
=A0;; v

=A0(org-babel-process-comment-text
=A0 (buffer-substring
=A0 =A0(max (condition-case nil
=A0 =A0 =A0 =A0 =A0 =A0 (save-excursion
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-back-to-heading t) (point))
=A0 =A0 =A0 =A0 =A0 (error 0))
=A0 =A0 =A0 =A0 (save-excursion
=A0 =A0 =A0 =A0 =A0 (re-search-backward
=A0 =A0 =A0 =A0 =A0 =A0org-babel-src-block-regexp nil t)
=A0 =A0 =A0 =A0 =A0 (match-end 0)))
=A0 =A0(point)))

=A0;; where

=A0(defcustom org-babel-process-comment-text #'org-babel-trim
=A0 =A0"Customizable function for processing comment text."
=A0 =A0:group 'org-babel
=A0 =A0:type 'function)
#+end_src

This change may end up being more than 10 lines long, but a patch would
still be welcome, otherwise if the solution I sketched out above sounds
reasonable I could compose a patch and then share it with you for double checking before it is applied.

Finally I'm not sure I fully understand what you mean by

>
> [fn:2] A feature request: I would propose that the =3D#+tangle:=3D con= struct
> be recognized as non-exported even with spaces preceding the =3D#=3D a= nd no
> spaces after the =3D+=3D. This would enable a variety of interesting > customization for tangled comments. Alternatively, a generic construct=
> such as =3D#+noop:=3D or =3D#+generic:=3D could be a valuable for user= -based
> tags in an org file that serves a similar purpose -- allow customized<= br> > processing without directly being exported.
>

Please do let me know if I missed anything, it was a long email.

Thanks for contributing! -- Eric

Christopher Genovese <genovese.= cr@gmail.com> writes:

> /Semi-verbose Preamble/.
> Having recently begun intensive use of org-mode for tangling source > files, I encountered four issues related to comment extraction (two > bugs, one undesirable behavior, and one ... unfulfilled need), which I=
> describe in detail below. I started by creating an org file that would=
> reproduce the problems, and soon started /describing/ the problems in<= br> > the org file as well as putting my fixes in the source blocks. At the<= br> > risk of it being too meta or annoying, I've included that org file= at
> the end of this message as the problem description. All the details ar= e
> there as well as two fixes. Tangling that file in various ways describ= ed
> demonstrates the problems, and you can export to PDF for nicer reading= .
> (I've attached the PDF to this mail for convenience. It looks good= ;
> kudos, org-mode!) I've also attached a tarball with files that mak= e it
> easy to try my changes and to restore the original behavior, as well a= s
> tests and results from the org file for easy comparison. See the
> included README.
>
> I've been using the revised code now for a few days. It fixes the<= br> > problems I describe, and I think it provides a flexible framework for<= br> > comment extraction with minimal change to the base code. If the reacti= on
> to this is positive, I will happily submit a patch, sign paperwork, or=
> whatever is needed, after fixing any problems that you all see. In any=
> case, I very much look forward to any feedback you can offer. Thanks.<= br> >
> =A0 -- Christopher
>
> P.S. In case the attachments get dropped, I've put the PDF and the=
> =A0 =A0 =A0tarball at
>
> =A0 =A0 =A0http://www.stat.cmu.edu/~genovese/depot/tangl= e-error.pdf
> =A0 =A0 =A0http://www.stat.cmu.edu/~genovese/depot/tang= le-bundle.tgz
>
> /Problem Description/
> ################ Cut Here ####################
> # -*- org-return-follows-link: t; comment-empty-lines: t; -*-
> #+TITLE: Tangle this file: four issues with org-babel-tangle
> #+AUTHOR: Christopher Genovese
> #+DATE: 14 Sep 2011\vspace*{-0.5cm}
> #+EMAIL: genovese@cmu.edu
> #+OPTIONS: toc:1 H:1
> #+BABEL: :tangle yes :comments org :results silent :exports code
> #+BIND: org-export-latex-hyperref-format "\\hyperlink{%s}{%s}&quo= t;
> #+STARTUP: showall
> #+LATEX_HEADER: \usepackage[labelsep=3Dperiod,labelfont=3Dbf]{caption}=
> #+LaTeX: \vspace*{-1cm}\vspace*{-2pt}
>
>
> * Four Related Issues with org-babel-tangle
>
> =A0 Running org-mode version 7.7 on both Gnu Emacs 23.2.1 and 24.0.50.= 1
> =A0 with Mac OS X 10.5.8 (with and without a -Q option), I encountered= the
> =A0 following issues/problems/bugs when tangling files with code block= s
> =A0 for which the :comment header argument is org:
>
> =A0 1. The subtree associated with the very first code block has
> =A0 =A0 =A0its headline tangled without leading stars, but all subsequ= ent
> =A0 =A0 =A0sub-trees associated with code blocks have the leading star= s
> =A0 =A0 =A0included in the comments.
>
> =A0 2. If the first code block comes before the first headline, the st= art
> =A0 =A0 =A0of the comment text will be determined by pre-existing matc= h data
> =A0 =A0 =A0and thus will likely be incorrect.
>
> =A0 3. Org structural elements such as headline stars, =3D#+=3D contro= l lines,
> =A0 =A0 =A0and drawers are included in the comments.
>
> =A0 4. There is no way easy to delimit comment text or transform it th= at
> =A0 =A0 =A0does not also change the structure of the org file (e.g., b= y adding
> =A0 =A0 =A0headlines or source blocks).
>
> =A0 Issues 1 and 2 seem to be genuine bugs. Issues 3 and 4 are more > =A0 subjective, I admit, but seem undesirable. Stars, drawers, and
> =A0 control lines are org structure rather than content, and they
> =A0 are often inappropriate in comments.
>
> =A0 To reproduce the behaviors for issues 1 and 3, look at the result = of
> =A0 tangling this file. To reproduce issue 2 as well, remove the first= two
> =A0 stars from this file and tangle again. Alternatively, within emacs= ,
> =A0 evaluate the =3D(buffer-substring ...)=3D sexp from the original-c= ode code
> =A0 below at the beginning character of a source block. (You
> =A0 can also export this file to PDF for more pleasant reading.)
>
> =A0 Below, I give details on these issues and code for two fixes:
> =A0 a [[simple-fix][simple fix]] that handles the first two issues and= the
> stars in the third,
> =A0 and a [[preferred-fix][better fix]] that handles all four issues i= n a more
> =A0 modular, customizable framework. I'd be interested in hearing<= br> > =A0 feedback on all of this. If the reaction is positive, I will gladl= y
> =A0 submit a patch. Thanks for your consideration.
>
>
>
> * The Original Code and Details on the Problem
>
> =A0 The relevant section of the original code from org-mode version 7.= 7
> =A0 is shown below, comprising lines 344 through 357
> =A0 of ob-tangle.el in function =3Dorg-babel-tangle-collect-blocks=3D.= With point
> =A0 is at a =3D#+begin_src=3D, it scans back either
> =A0 for a heading line or for the end of the previous code block,
> =A0 whichever comes later. The resulting region becomes the
> =A0 comment text.
>
> =A0 #+latex: \begin{figure}[h]
> =A0 #+latex: \hypertarget{original-code}{} % <<original-code>= >
> =A0 #+source: original-code
> =A0 #+begin_src emacs-lisp
> =A0 =A0 (comment
> =A0 =A0 =A0(when (or (string=3D "both" (cdr (assoc :comments= params)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(string=3D "org" (cdr (assoc = :comments params))))
> =A0 =A0 =A0 =A0;; from the previous heading or code-block end
> =A0 =A0 =A0 =A0(buffer-substring
> =A0 =A0 =A0 =A0 (max (condition-case nil
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-back-to-heading t) (point)= )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(error 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(re-search-backward
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org-babel-src-block-regexp nil t)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(match-end 0)))
> =A0 =A0 =A0 =A0 (point))))
> =A0 #+end_src
> =A0 #+latex: \caption{Original Code, lines 344--357 in {\tt ob-tangle.= el}.}
> =A0 #+latex: \label{fig::original-code}
> =A0 #+latex: \end{figure}
>
> =A0 /Issue 1/. When in the first code block in the file, the
> =A0 second search fails (there is no previous code block),
> =A0 so the (match-end 0) =A0call uses the match data from the (implici= t) match
> during
> =A0 =3Dorg-back-to-heading=3D, which skips the stars. (Not a particula= rly
> =A0 transparent reference, incidentally.) For subsequent blocks, the > =A0 =3D(match-end 0)=3D gives the end of the previous code block, whic= h in these
> =A0 examples is earlier than the previous headline location.
>
> =A0 /Issue 2/. When the first code block lies before the first headlin= e
> =A0 (say with some text before it), the searches fail in /both/ clause= s of
> =A0 the max. So, the =3Dmatch-end=3D will return an essentially arbitr= ary
> =A0 result, which is a bug.
>
> =A0 /Issue 3/. =3Dorg-back-to-heading=3D leaves point at the beginning= of the
> =A0 stars, so a headline included in the text will have stars, except = for
> =A0 the first one.
>
> =A0 /Issue 4/. Control lines at the end of the previous code block and=
> =A0 before point are not filtered out and so are included in the comme= nts.
>
>
> * A Simple Fix for the First Three Issues
>
> =A0 A small change addresses issues 1, 2, and the stars for issue 3: i= n
> =A0 both cases, simply use the =3Dmatch-end=3D and replace 0 values wi= th
> =A0 =3D(point-min)=3D. The latter gives a sensible result even if both=
> =A0 computed positions are trivial (as when the first code block comes=
> =A0 before the first headline) and respects narrowing.
>
> =A0 #+latex: \begin{figure}[h]
> =A0 #+latex: \hypertarget{simple-fix}{} % <<simple-fix>> > =A0 #+begin_src emacs-lisp
> =A0 =A0 (comment
> =A0 =A0 =A0(when (or (string=3D "both" (cdr (assoc :comments= params)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(string=3D "org" (cdr (assoc = :comments params))))
> =A0 =A0 =A0 =A0;; from the previous heading or code-block end
> =A0 =A0 =A0 =A0(buffer-substring
> =A0 =A0 =A0 =A0 (max (condition-case nil
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(org-back-to-heading t) =A0; se= ts match data
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(match-end 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(error (point-min)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if (re-search-backward
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org-babel-src-block-regexp nil= t)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(match-end 0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(point-min))))
> =A0 =A0 =A0 =A0 (point))))
> =A0 #+end_src
> =A0 #+latex: \caption{Simple Fix, replacement for lines 344--357 in {\= tt
> ob-tangle.el}.}
> =A0 #+latex: \label{fig::simple-fix}
> =A0 #+latex: \end{figure}
>
> * A Fix for All Four Issues
>
> =A0 A better fix that handles issues 1--4 starts with the region compu= ted as
> in the [[simple-fix][simple fix]]
> =A0 and then processes that text through a user-configurable sequence = of
> functions
> =A0 to derive the final form of the comment text.
>
> =A0 The following changes are required.
>
> ** Extract Initial Comment Text and State from Org Buffer
>
> =A0 =A0The initial comment text ranges from either the most recent hea= dline
> =A0 =A0at the point after the stars, the beginning of the line after t= he
> =A0 =A0=3D#+end_src=3D of the most recent code block, or the beginning= of the
> =A0 =A0buffer, whichever is later, through the line before the source<= br> > =A0 =A0block.[fn:1]
>
> =A0 =A0The [[preferred-fix][code]] to extract this is given below.
> =A0 =A0#+latex: (See Figure \ref{fig::preferred-fix}.)
> =A0 =A0It replaces lines 344 through 357 of
> =A0 =A0=3Dob-tangle.el=3D from org-mode version 7.7 in the function > =A0 =A0=3Dorg-babel-tangle-collect-blocks=3D.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+latex: \hypertarget{preferred-fix}{} % <<preferred-fix&= gt;>
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(comment
> =A0 =A0 =A0 (when (or (string=3D "both" (cdr (assoc :comment= s params)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (string=3D "org" (cdr (assoc= :comments params))))
> =A0 =A0 =A0 =A0 (let* ((prev-heading
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (condition-case nil
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (org-back-to-heading t) ; = sets match data
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (match-end 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (error (point-min))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(end-of-prev-src-block
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (null (re-search-backward
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0org-babel-s= rc-block-regexp nil t))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (point-min)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (goto-char (match-end 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-line 1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (point))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(comment-start
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (max prev-heading end-of-prev-src-bloc= k))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(comment-end
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-line 0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (point)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(state
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (list (cons 'org-drawers
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org-drawers) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cons 'after-heading > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (=3D comment-s= tart prev-heading))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cons 'first-line
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (=3D comment-s= tart (point-min))))))
> =A0 =A0 =A0 =A0 =A0 (org-babel-process-comment-text
> =A0 =A0 =A0 =A0 =A0 =A0(buffer-substring comment-start comment-end) st= ate))))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Better Fix, replacement for lines 344--357 in= {\tt
> ob-tangle.el}.}
> =A0 =A0#+latex: \label{fig::preferred-fix}
> =A0 =A0#+latex: \end{figure}
>
> ** Adjust =3Dorg-babel-spec-to-string=3D
>
> =A0 =A0The commment block collected by the [[original-code][original c= ode]]
> =A0 =A0#+latex: (Figure \ref{fig::original-code})
> =A0 =A0in =3Dorg-babel-tangle-collect-blocks=3D is further processed i= n \newline
> =A0 =A0=3Dorg-babel-spec-to-string=3D to trim leading and trailing whi= tespace
> =A0 =A0from string. This was needed because spaces after a source bloc= k were
> =A0 =A0included in the comment. In the revised code, however, this spa= ce
> =A0 =A0trimming is handled during text transformation, except for remo= ving
> =A0 =A0trailing newlines. (Note: trailing /spaces/ are not removed to = allow
> =A0 =A0more flexibility in comment processing.) Hence,
> =A0 =A0=3Dorg-babel-spec-to-string=3D needs to be slightly adjusted. > =A0 =A0#+latex: See Figure \ref{fig::spec-string-diff}.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_example
> =A0 =A0 =A0--- ob-tangle.el =A0 =A0 =A0 =A0 =A0 2011-09-14 11:48:26.00= 0000000 -0400
> =A0 =A0 =A0+++ new-ob-tangle.el =A0 =A0 =A0 2011-09-14 11:55:56.000000= 000 -0400
> =A0 =A0 =A0@@ -398,3 +398,3 @@
> =A0 =A0 =A0 =A0 =A0 (flet ((insert-comment (text)
> =A0 =A0 =A0- =A0 =A0 =A0 =A0 =A0 =A0(let ((text (org-babel-trim text))= )
> =A0 =A0 =A0+ =A0 =A0 =A0 =A0 =A0 =A0(let ((text (org-babel-chomp text = "[\f\t\n\r\v]")))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (when (and comments (not (string=3D commen= ts "no"))
> =A0 =A0#+end_example
> =A0 =A0#+latex: \caption{Changes to {\tt org-spec-to-string} in {\tt > ob-tangle.el}, unified diff, one line of context}
> =A0 =A0#+latex: \label{fig::spec-string-diff}
> =A0 =A0#+latex: \end{figure}
>
> ** Process Comment Text Through Sequence of Transforms
>
> =A0 =A0At the end of the revised [[preferred-fix][comment collection c= ode]],
> =A0 =A0the comment text is passed to
> =A0 =A0=3Dorg-babel-process-comment-text=3D which
> =A0 =A0applies a sequence of transformation functions.
> =A0 =A0#+latex: (See Figure \ref{fig::comment-transformation}.)
> =A0 =A0The list of transformation functions is stored in a customizabl= e
> =A0 =A0variable described [[Define Customization Variable for
> Transforms][below]]. Several predefined transformations are
> =A0 =A0given [[Define A Collection of Transform Functions][below]] as = well.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-process-comment-text (text &optional s= tate)
> =A0 =A0 =A0 =A0"Apply list of transforms to comment TEXT assuming= bindings in alist
> STATE.
> =A0 =A0 =A0Returns the modified text string, which may have text prope= rties.
> =A0 =A0 =A0See `org-babel-comment-processing-functions' for the tr= ansforms to be
> =A0 =A0 =A0applied and details on the allowed keys in the STATE alist.= "
> =A0 =A0 =A0 =A0(let ((funcs org-babel-comment-processing-functions)) > =A0 =A0 =A0 =A0 =A0(with-temp-buffer
> =A0 =A0 =A0 =A0 =A0 =A0(insert text)
> =A0 =A0 =A0 =A0 =A0 =A0(let ((org-drawers
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (or (cdr (assoc 'org-drawers s= tate))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 org-drawers))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(after-heading
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cdr (assoc 'after-heading sta= te)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(first-line
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (cdr (assoc 'first-line state)= )))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(while funcs
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(goto-char (point-min))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(funcall (car funcs))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(setq funcs (cdr funcs))))
> =A0 =A0 =A0 =A0 =A0 =A0(buffer-substring (point-min) (point-max))))) > =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Better Fix, comment transformation driver.} > =A0 =A0#+latex: \label{fig::comment-transformation}
> =A0 =A0#+latex: \end{figure}
>
> ** Define Customization Variable for Transforms
>
> =A0 =A0A list of nullary functions applied in order to
> =A0 =A0the comment text. The text is inserted
> =A0 =A0in a temporary buffer, so these functions can use
> =A0 =A0the entire Emacs library for operating on buffer text.
> =A0 =A0#+latex: See Figure \ref{fig::comment-transformation-function-l= ist}.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defcustom org-babel-comment-processing-functions
> =A0 =A0 =A0 =A0'(org-babel-comment-delete-file-variables-line
> =A0 =A0 =A0 =A0 =A0org-babel-comment-delete-org-control-lines
> =A0 =A0 =A0 =A0 =A0org-babel-comment-delete-drawers
> =A0 =A0 =A0 =A0 =A0org-babel-comment-trim-blank-lines
> =A0 =A0 =A0 =A0 =A0org-babel-comment-trim-indent-prefix)
> =A0 =A0 =A0 =A0"List of functions to transform source-block comme= nt text before
> insertion.
> =A0 =A0 =A0Each function will be called with no arguments with point a= t the
> =A0 =A0 =A0beginning of a buffer containing only the comment text. Eac= h
> =A0 =A0 =A0function can modify the text at will and leave point anywhe= re,
> =A0 =A0 =A0but it should *not* modify the narrowing state of the buffe= r.
> =A0 =A0 =A0Several dynamic state variables are set prior to execution = that
> =A0 =A0 =A0each function can reference. These currently include:
>
> =A0 =A0 =A0 =A0 + org-drawers: =A0 names of drawers in the original or= g buffer.
> =A0 =A0 =A0 =A0 + from-heading: =A0t if comment starts at an org headi= ng line,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0nil otherwise.
> =A0 =A0 =A0 =A0 + first-line: =A0 =A0t if initial comment starts on fi= rst line
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0of the original org= buffer, nil otherwise.
>
> =A0 =A0 =A0If a function changes the value of these state variables, t= he new
> =A0 =A0 =A0value will be seen by all following functions in the list, = but
> =A0 =A0 =A0this is not generally recommended.
>
> =A0 =A0 =A0The functions in this list are called *in order*, and this = order
> =A0 =A0 =A0can influence the form of the resulting comment text."=
> =A0 =A0 =A0 =A0:group 'org-babel
> =A0 =A0 =A0 =A0:type 'list)
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Better Fix, customizable transform list.}
> =A0 =A0#+latex: \label{fig::comment-transformation-function-list}
> =A0 =A0#+latex: \end{figure}
>
> ** Define A Collection of Transform Functions
>
> =A0 =A0An advantage of this design is that transformation of the
> =A0 =A0comments is modular and customizable. We can include in
> =A0 =A0=3Dob-tangle.el=3D a collection of pre-defined transforms.
> =A0 =A0The default processing stream in =3Dorg-babel-comment-processin= g-functions=3D
> =A0 =A0is as follows:
>
> =A0 =A01. Delete a file variables if on the first line of the buffer.<= br> > =A0 =A02. Delete all drawers and their contents.
> =A0 =A03. Delete all org control lines from the comment text.
> =A0 =A04. Trim blank lines from the beginning and end.
> =A0 =A05. Reindent the text by removing the longest common leading
> =A0 =A0 =A0 string of spaces.
>
> =A0 =A0#+ TANGLE: end-comment
> =A0 =A0These and several other useful transforms are given below
> =A0 =A0(e.g., deleting drawer delimiters but not contents)..
> =A0 =A0#+latex: See Figures \ref{fig::transformA}--\ref{fig::transform= Z}.
> =A0 =A0It is easy to define new transforms; any function that
> =A0 =A0operates on text in the current buffer beginning at point-min > =A0 =A0will work.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-delete-file-variables-line ()
> =A0 =A0 =A0 =A0"Delete file variables comment line if at beginnin= g of buffer.
> =A0 =A0 =A0This only checks the first line of the buffer, and so shoul= d be
> =A0 =A0 =A0placed first (or at least early enough) in the list
> =A0 =A0 =A0`org-babel-comment-processing-functions' to ensure that= the no
> =A0 =A0 =A0other text has been inserted earlier."
> =A0 =A0 =A0 =A0(when (and first-line
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (looking-at ; file-variables line<= br> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"^#[ \t]*-\\*-.*:.*;[ \t]*= *-\\*-[ \t]*$"))
> =A0 =A0 =A0 =A0 =A0(let ((kill-whole-line t))
> =A0 =A0 =A0 =A0 =A0 =A0(kill-line))))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \label{fig::transformA}
> =A0 =A0#+latex: \end{figure}
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-delete-org-control-lines ()
> =A0 =A0 =A0 =A0"Remove all org #+ control lines from comment.&quo= t;
> =A0 =A0 =A0 =A0(let ((control-regexp "^[ \t]*#\\+.*$"))
> =A0 =A0 =A0 =A0 =A0(delete-matching-lines control-regexp)))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-delete-org-in-buffer-settings () > =A0 =A0 =A0 =A0"Remove all org #+ in-buffer setting lines, leavin= g other control
> lines.
> =A0 =A0 =A0In-buffer setting lines begin with #+ and have all caps key= word
> =A0 =A0 =A0names."
> =A0 =A0 =A0 =A0(let ((setting-regexp "^#\\+[ \t]*[A-Z_]+:.*$"= ;))
> =A0 =A0 =A0 =A0 =A0(delete-matching-lines setting-regexp)))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-delete-drawers ()
> =A0 =A0 =A0 =A0"Delete drawer delimiters and contents from commen= t.
> =A0 =A0 =A0Drawer names are restricted to those in the `org-drawers= 9; state."
> =A0 =A0 =A0 =A0(let ((drawer-start-regexp
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (format "^[ \t]*:\\(?:%s\\):[ \t]*$&q= uot;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (mapconcat 'identity > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0org= -drawers
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&qu= ot;\\|")))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(drawer-end-regexp "^[ \t]*:END:[ \t]*= $"))
> =A0 =A0 =A0 =A0 =A0(while (re-search-forward drawer-start-regexp nil t= )
> =A0 =A0 =A0 =A0 =A0 =A0(let ((beg (save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-line 0)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (point)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(end (save-excursion
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (re-search-forward dra= wer-end-regexp nil t)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (forward-line 1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (point))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(goto-char end)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(delete-region beg end)))))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-delete-drawer-delimiters ()
> =A0 =A0 =A0 =A0"Delete drawer delimiters from comment leaving con= tent.
> =A0 =A0 =A0Drawer names are restricted to those given by the `org-draw= ers'
> =A0 =A0 =A0state."
> =A0 =A0 =A0 =A0(let ((drawer-delim-regexp
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (format "^[ \t]*:\\(?:%s\\)"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (mapconcat 'identity > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(co= ns "END" org-drawers)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&qu= ot;\\|"))))
> =A0 =A0 =A0 =A0 =A0(delete-matching-lines drawer-delim-regexp)))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-trim-blank-lines ()
> =A0 =A0 =A0 =A0"Trim whitespace-only lines from beginning and end= of text."
> =A0 =A0 =A0 =A0(while (and (looking-at "^[ \t\f]*$")
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(< (point) (point-max)))
> =A0 =A0 =A0 =A0 =A0(forward-line 1))
> =A0 =A0 =A0 =A0(delete-region (point-min) (point))
> =A0 =A0 =A0 =A0(when (< (point) (point-max))
> =A0 =A0 =A0 =A0 =A0(goto-char (point-max))
> =A0 =A0 =A0 =A0 =A0(let ((last-point (point)))
> =A0 =A0 =A0 =A0 =A0 =A0(forward-line 0)
> =A0 =A0 =A0 =A0 =A0 =A0(while (and (looking-at "^[ \t\f]*$")=
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(> (point) (point-mi= n)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(setq last-point (point))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(forward-line -1))
> =A0 =A0 =A0 =A0 =A0 =A0(delete-region last-point (point-max)))))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-trim-indent-prefix ()
> =A0 =A0 =A0 =A0"Remove longest common leading prefix of spaces fr= om each line of
> TEXT.
> =A0 =A0 =A0Prefix is computed from the initial whitespace on each line= with
> =A0 =A0 =A0tabs converted to spaces, preserving indentation."
> =A0 =A0 =A0 =A0(let* ((common-indent nil)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (common-length (1+ (- (point-max) (point-m= in))))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (current-indent "") =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 ; enter first loop
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (current-length common-length)) =A0 =A0 = =A0 ; skip first assignment
> =A0 =A0 =A0 =A0 =A0(goto-char (point-min))
> =A0 =A0 =A0 =A0 =A0(while current-indent
> =A0 =A0 =A0 =A0 =A0 =A0(when (< current-length common-length)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(setq common-indent current-indent
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0common-length current-length))<= br> > =A0 =A0 =A0 =A0 =A0 =A0(setq current-indent
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(let* ((found (re-search-forward &q= uot;^\\([ \t]*\\)\\S-" nil
> t))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (bol (match-beginning = 0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (eos (match-end 1)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (space-str (match-stri= ng 1))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (indent-tabs-mode nil)= )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(cond
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((not found)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0nil)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((not (string-match "\t&q= uot; space-str))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0space-str)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (t =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 ; detabify indent string
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(goto-char eos)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(let ((col (current-column)= ))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(delete-region bol eos)=
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(indent-to col))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(buffer-substring-no-proper= ties bol (point))))))
> =A0 =A0 =A0 =A0 =A0 =A0(setq current-length (length current-indent)))<= br> > =A0 =A0 =A0 =A0 =A0(when (and common-indent (> common-length 0)) > =A0 =A0 =A0 =A0 =A0 =A0(let ((indent-re (concat "^" common-i= ndent)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(goto-char (point-min))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(while (re-search-forward indent-re nil t)<= br> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(replace-match "" nil nil))))= ))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Comment Transform.}
> =A0 =A0#+latex: \label{fig::transformZ}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \end{itemize}
> =A0 =A0#+latex: \noindent
> =A0 =A0This kind of customization offers some nice possibilities,
> =A0 =A0including controlling indentation, eliminating or
> =A0 =A0transforming org markup, eliminating trailing whitespace, and > =A0 =A0automating specialized comment formatting (e.g., javadoc). As > =A0 =A0an additional illustration, consider the transform
> =A0 =A0=3Dorg-babel-comment-restrict-comment-range=3D
> =A0 =A0#+latex: in Figure \ref{fig::transform-illustration}
> =A0 =A0below. The idea is that it is sometimes useful to select
> =A0 =A0from the text under a headline a /part/ of the text for
> =A0 =A0the comment. We want some org markup that will not affect
> =A0 =A0either the export or the structure of the org file itself.
> =A0 =A0To do this, we use the fact that =3D#+=3D\textvisiblespace
> =A0 =A0lines are not exported.[fn:2] So, we can /de facto/ use the
> =A0 =A0=3D#+ TANGLE:=3D construct to control various aspects of tangli= ng.
> =A0 =A0Here, we use the =3D#+ TANGLE: start-comment=3D and
> =A0 =A0=3D#+ TANGLE: end-comment=3D to delimit the comment text.
> =A0 =A0(This function needs to come earlier in the function list than = the
> =A0 =A0functions that eliminate org control lines. It is sufficient to=
> =A0 =A0prepend it to that list.) This is used in the current file,
> =A0 =A0for example.
>
> =A0 =A0#+latex: \begin{figure}[h]
> =A0 =A0#+begin_src emacs-lisp
> =A0 =A0 =A0(defun org-babel-comment-restrict-comment-range ()
> =A0 =A0 =A0 =A0"Remove all comment text outside start-comment and= end-comment
> delimiters.
> =A0 =A0 =A0Comment delimiters are #+TANGLE lines with respective keywo= rds
> =A0 =A0 =A0start-comment and end-comment. THE #+TANGLE lines are also<= br> > =A0 =A0 =A0deleted. To be effective, this function should be positione= d in
> =A0 =A0 =A0the list `org-babel-comment-processing-functions' befor= e any
> =A0 =A0 =A0functions that remove org control lines or process other > =A0 =A0 =A0co-occuring attributes of #+TANGLE lines."
> =A0 =A0 =A0 =A0(when (re-search-forward "^[ \t]*#\\+[ \t]*TANGLE:= .*start-comment.*$"
> nil t)
> =A0 =A0 =A0 =A0 =A0(forward-line 1)
> =A0 =A0 =A0 =A0 =A0(delete-region (point-min) (point)))
> =A0 =A0 =A0 =A0(when (re-search-forward "^[ \t]*#\\+[ \t]*TANGLE:= .*end-comment.*$"
> nil t)
> =A0 =A0 =A0 =A0 =A0(forward-line 0)
> =A0 =A0 =A0 =A0 =A0(delete-region (point) (point-max))))
> =A0 =A0#+end_src
> =A0 =A0#+latex: \caption{Transform to illustrate some customization > possibilities.}
> =A0 =A0#+latex: \label{fig::transform-illustration}
> =A0 =A0#+latex: \end{figure}
> =A0 =A0#+latex: \begin{itemize}
>
> [fn:1] In the original code and in the simple fix above, the comment > starts /immediately/ after the =3D#+end_src=3D rather than at the star= t of
> the next line. Starting at the next line seems more natural to me
> because the comment being constructed relates to the /following/ code<= br> > block. But the original behavior is easily restored if people disagree= .
>
> [fn:2] A feature request: I would propose that the =3D#+tangle:=3D con= struct
> be recognized as non-exported even with spaces preceding the =3D#=3D a= nd no
> spaces after the =3D+=3D. This would enable a variety of interesting > customization for tangled comments. Alternatively, a generic construct=
> such as =3D#+noop:=3D or =3D#+generic:=3D could be a valuable for user= -based
> tags in an org file that serves a similar purpose -- allow customized<= br> > processing without directly being exported.
>
>

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

--bcaec520f0b7f6627304ad01acf4--