diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-02 12:39:46 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-01-02 12:40:54 +0100 |
commit | ec6813157e450ef0f5f4915b5782232d8466ce3f (patch) | |
tree | 15c79ede976b4a3eb426930117fbedcf0b513523 | |
parent | 4c9b5f600f5492bb4381c667ab08fe0a8fe7bbd0 (diff) | |
download | org-mode-ec6813157e450ef0f5f4915b5782232d8466ce3f.tar.gz |
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
-rw-r--r-- | lisp/org-capture.el | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 0321021..cb1741f 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 <carsten at orgmode dot org> ;; 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) |