From ec6813157e450ef0f5f4915b5782232d8466ce3f Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 2 Jan 2018 12:39:46 +0100 Subject: [PATCH] org-capture: Demote error when capturing `file+headline' in non-Org buffers * lisp/org-capture.el (org-capture-set-target-location): Warn when capturing a `file+headline' target and buffer is not in Org mode. Fixes: 22352 --- lisp/org-capture.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 032102108..cb1741f2f 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1,6 +1,6 @@ ;;; org-capture.el --- Fast note taking in Org -*- lexical-binding: t; -*- -;; Copyright (C) 2010-2017 Free Software Foundation, Inc. +;; Copyright (C) 2010-2018 Free Software Foundation, Inc. ;; Author: Carsten Dominik ;; Keywords: outlines, hypermedia, calendar, wp @@ -927,18 +927,24 @@ Store them in the capture property list." (_ (error "Cannot find target ID \"%s\"" id)))) (`(file+headline ,path ,headline) (set-buffer (org-capture-target-buffer path)) + ;; Org expects the target file to be in Org mode, otherwise + ;; it throws an error. However, the default notes files + ;; should work out of the box. In this case, we switch it to + ;; Org mode. (unless (derived-mode-p 'org-mode) - (error "Target buffer \"%s\" for file+headline not in Org mode" - (current-buffer))) + (org-display-warning + (format "Capture requirement: switching buffer %S to Org mode" + (current-buffer))) + (org-mode)) (org-capture-put-target-region-and-position) (widen) (goto-char (point-min)) (if (re-search-forward (format org-complex-heading-regexp-format (regexp-quote headline)) nil t) - (goto-char (line-beginning-position)) + (beginning-of-line) (goto-char (point-max)) - (or (bolp) (insert "\n")) + (unless (bolp) (insert "\n")) (insert "* " headline "\n") (beginning-of-line 0))) (`(file+olp ,path . ,outline-path)