From: Kaushal Modi <kaushal.modi@gmail.com>
To: emacs-org list <emacs-orgmode@gnu.org>
Subject: Prevent creating empty lines with trailing spaces when tangling noweb
Date: Sat, 06 May 2017 06:30:45 +0000 [thread overview]
Message-ID: <CAFyQvY1cLjuEyqc_EhyjV2g67sFwws5wLtaSaPDCmCXhaJv6sg@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 2800 bytes --]
Hello,
I have this MWE:
#+TITLE: Org babel tangle and noweb
#+PROPERTY: header-args:shell :shebang "#!/usr/bin/env bash"
* Shell Script
#+BEGIN_SRC shell :noweb yes :tangle code.sh
exec emacs -Q "$@" \
--eval '(progn
<<elisp>>
)' 2>/dev/null </dev/tty
#+END_SRC
* Emacs Configuration
#+BEGIN_SRC emacs-lisp :noweb-ref elisp :noweb-sep "\\n\\n"
(menu-bar-mode -1)
#+END_SRC
Some comment.
#+BEGIN_SRC emacs-lisp :noweb-ref elisp
(line-number-mode 1)
#+END_SRC
When tangled (C-c C-v t), it generates:
[image: image.png]
Notice that the empty line is created between noweb segments as expected
because of ":noweb-sep "\\n\\n"". But what was unexpected to me was the
creation of empty line with spaces inserted to match the indentation.
Is this by design?
If it is by design, I would propose to have a new switch called something
like ":noweb-notrailingspc" (would like a better suggestion for this switch
name).
So the src block where noweb expansion needs to happen will look like this:
#+BEGIN_SRC shell :noweb yes :tangle code.sh :noweb-notrailingspc yes
exec emacs -Q "$@" \
--eval '(progn
<<elisp>>
)' 2>/dev/null </dev/tty
#+END_SRC
Now, tangling will generate
[image: image.png]
Here is a diff (without whitespace differences) of the change I made to
ob-core locally to get this:
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index cb332ffea92..0f04d8b85e1 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2730,9 +2730,7 @@ block but are passed literally to the
\"example-block\"."
(funcall nb-add (buffer-substring index (point)))
(goto-char (match-end 0))
(setq index (point))
- (funcall
- nb-add
- (with-current-buffer parent-buffer
+ (let ((body-str (with-current-buffer parent-buffer
(save-restriction
(widen)
(mapconcat ;; Interpose PREFIX between every line.
@@ -2794,6 +2792,9 @@ block but are passed literally to the
\"example-block\"."
"`org-babel-noweb-error-langs')"))
"")))
"[\n\r]") (concat "\n" prefix))))))
+ (when (string= "yes" (cdr (assq :noweb-notrailingspc (nth 2 info))))
+ (setq body-str (replace-regexp-in-string "^[ \n\r]*\n" "\n" body-str)))
+ (funcall nb-add body-str)))
(funcall nb-add (buffer-substring index (point-max))))
new-body))
Questions:
1. If the above empty lines with prefix number of spaces are not expected,
the fix would be simpler.. to just throw in that (setq body-str
(replace-regexp-in-string "^[ \n\r]*\n" "\n" body-str)) form in-between.
2a. If the spacey empty lines are as per design, then does this diff look
good? Should I work on a proper patch?
2b. What would be a better/more intuitive switch name than
":noweb-notrailingspc"?
--
Kaushal Modi
[-- Attachment #1.2: Type: text/html, Size: 5195 bytes --]
[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 17908 bytes --]
[-- Attachment #3: image.png --]
[-- Type: image/png, Size: 17794 bytes --]
next reply other threads:[~2017-05-06 6:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-06 6:30 Kaushal Modi [this message]
2017-05-06 6:54 ` Prevent creating empty lines with trailing spaces when tangling noweb Kaushal Modi
2017-05-06 7:23 ` Nicolas Goaziou
2017-05-06 12:59 ` Kaushal Modi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFyQvY1cLjuEyqc_EhyjV2g67sFwws5wLtaSaPDCmCXhaJv6sg@mail.gmail.com \
--to=kaushal.modi@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).