From d6f096546e795430844098af85c3ed703b1597e2 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 23 May 2017 18:10:06 +0200 Subject: [PATCH] org-capture: Fix number of blank lines with :unnarrowed option * lisp/org-capture.el (org-capture-finalize): Remove blank lines number fix, which only applies to narrowed capture buffers. (org-capture-insert-template-here): (org-capture-place-plain-text): (org-capture-place-item): (org-capture-place-entry): Do not hard-code number of blank lines after entry. Reported-by: Igor Perepelytsya Reported-by: Jay Dresser --- lisp/org-capture.el | 31 ++++++++++++------------------- testing/lisp/test-org-capture.el | 2 +- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 551ff28ec..755bf73f3 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -723,16 +723,6 @@ captured item after finalizing." (kill-region m1 m2)) (setq abort-note 'dirty))) - ;; Make sure that the empty lines after are correct - (when (and (> (point-max) end) ; indeed, the buffer was still narrowed - (member (org-capture-get :type 'local) - '(entry item checkitem plain))) - (save-excursion - (goto-char end) - (or (bolp) (newline)) - (org-capture-empty-lines-after - (or (org-capture-get :empty-lines-after 'local) - (org-capture-get :empty-lines 'local) 0)))) ;; Postprocessing: Update Statistics cookies, do the sorting (when (derived-mode-p 'org-mode) (save-excursion @@ -1101,7 +1091,7 @@ may have been stored before." (setq beg (point)) (org-capture-verify-tree txt) (org-paste-subtree level txt 'for-yank) - (org-capture-empty-lines-after 1) + (org-capture-empty-lines-after) (org-capture-position-for-last-stored beg) (outline-next-heading) (setq end (point)) @@ -1161,7 +1151,7 @@ may have been stored before." "\n")) ;; Insert item. (insert txt) - (org-capture-empty-lines-after 1) + (org-capture-empty-lines-after) (org-capture-position-for-last-stored beg) (forward-char 1) (setq end (point)) @@ -1282,7 +1272,7 @@ Of course, if exact position has been required, just put it there." (org-capture-empty-lines-before) (setq beg (point)) (insert txt) - (org-capture-empty-lines-after 1) + (org-capture-empty-lines-after) (org-capture-position-for-last-stored beg) (setq end (point)) (org-capture-mark-kill-region beg (1- end)) @@ -1366,7 +1356,7 @@ Point will remain at the first line after the inserted text." (let* ((template (org-capture-get :template)) (type (org-capture-get :type)) beg end pp) - (or (bolp) (newline)) + (unless (bolp) (insert "\n")) (setq beg (point)) (cond ((and (eq type 'entry) (derived-mode-p 'org-mode)) @@ -1388,13 +1378,16 @@ Point will remain at the first line after the inserted text." (org-capture-empty-lines-after) (goto-char beg) (org-list-repair) - (org-end-of-item) - (setq end (point))) - (t (insert template))) + (org-end-of-item)) + (t + (insert template) + (org-capture-empty-lines-after) + (skip-chars-forward " \t\n") + (unless (eobp) (beginning-of-line)))) (setq end (point)) (goto-char beg) - (if (re-search-forward "%\\?" end t) - (replace-match "")))) + (when (re-search-forward "%\\?" end t) + (replace-match "")))) (defun org-capture-set-plist (entry) "Initialize the property list from the template definition." diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index c630142d3..7b022b164 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -1,6 +1,6 @@ ;;; test-org-capture.el --- Tests for org-capture.el -*- lexical-binding: t; -*- -;; Copyright (C) 2015 Nicolas Goaziou +;; Copyright (C) 2015, 2017 Nicolas Goaziou ;; Author: Nicolas Goaziou -- 2.11.4.GIT