From: Daniel P Gomez <gomez.danp@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Have SRC_BLOCK :padline accept numbers
Date: Tue, 28 Mar 2017 21:47:42 +0200 [thread overview]
Message-ID: <CAJTMgxg0+bub2OzaKhUVN32O3iLWe44OkyS1P0nb-4H8z-PT=w@mail.gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 703 bytes --]
A use case is tangling python source code snippets containing class
definitions.
(
http://emacs.stackexchange.com/questions/31738/org-mode-babel-ensure-two-empty-lines-between-tangled-code-blocks-for-python
)
Per PEP8, the use of blank lines stipulates:
"Surround top-level function and class definitions with two blank lines."
To achieve two blank lines before a class definition, one would have to set
:padline 2.
I've written a small patch (attached here), following the contribution
guidelines on the org-mode website. The "patched" repository can be found
here: https://github.com/dangom/org-mode/tree/feature_padline
Please let me know if there is anything else I should do.
Thanks,
Daniel
[-- Attachment #1.2: Type: text/html, Size: 1077 bytes --]
[-- Attachment #2: 0001-Add-support-for-padline-with-numbers-in-ob-tangle.patch --]
[-- Type: application/octet-stream, Size: 1300 bytes --]
From f5e67856b6cefb7c5e9c1b6bd74321d3b47f1b05 Mon Sep 17 00:00:00 2001
From: Daniel Gomez <d.gomez@posteo.org>
Date: Tue, 28 Mar 2017 21:20:23 +0200
Subject: [PATCH] Add support for :padline with numbers in ob-tangle.
---
lisp/ob-tangle.el | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index b33fcaee4..85ea18a57 100644
--- a/lisp/ob-tangle.el
+++ b/lisp/ob-tangle.el
@@ -284,9 +284,16 @@ used to limit the exported source code blocks by language."
(insert-file-contents file-name))
(goto-char (point-max))
;; Handle :padlines unless first line in file
- (unless (or (string= "no" (cdr (assq :padline (nth 4 spec))))
- (= (point) (point-min)))
- (insert "\n"))
+ (let ((padlines (format "%s" (cdr (assq :padline (nth 4 spec))))))
+ (cond
+ ((and (string= "nil" padlines) (not (= (point) (point-min))))
+ (insert "\n"))
+ ((string= "no" padlines)
+ nil)
+ ((numberp (string-to-int padlines))
+ (dotimes (i (string-to-int padlines)) (insert "\n")))
+ (t
+ (insert "\n"))))
(insert content)
(write-region nil nil file-name))))
;; if files contain she-bangs, then make the executable
--
2.12.2
next reply other threads:[~2017-03-28 19:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-28 19:47 Daniel P Gomez [this message]
2017-03-29 12:27 ` Have SRC_BLOCK :padline accept numbers Nicolas Goaziou
2017-03-29 16:03 ` Daniel P Gomez
2017-03-30 7:50 ` Nicolas Goaziou
2017-04-18 8:37 ` Nicolas Goaziou
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJTMgxg0+bub2OzaKhUVN32O3iLWe44OkyS1P0nb-4H8z-PT=w@mail.gmail.com' \
--to=gomez.danp@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.