forked from mirrors/org-mode
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
This commit is contained in:
parent
4c9b5f600f
commit
ec6813157e
|
@ -1,6 +1,6 @@
|
||||||
;;; org-capture.el --- Fast note taking in Org -*- lexical-binding: t; -*-
|
;;; 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>
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
||||||
;; Keywords: outlines, hypermedia, calendar, wp
|
;; Keywords: outlines, hypermedia, calendar, wp
|
||||||
|
@ -927,18 +927,24 @@ Store them in the capture property list."
|
||||||
(_ (error "Cannot find target ID \"%s\"" id))))
|
(_ (error "Cannot find target ID \"%s\"" id))))
|
||||||
(`(file+headline ,path ,headline)
|
(`(file+headline ,path ,headline)
|
||||||
(set-buffer (org-capture-target-buffer path))
|
(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)
|
(unless (derived-mode-p 'org-mode)
|
||||||
(error "Target buffer \"%s\" for file+headline not in Org mode"
|
(org-display-warning
|
||||||
(current-buffer)))
|
(format "Capture requirement: switching buffer %S to Org mode"
|
||||||
|
(current-buffer)))
|
||||||
|
(org-mode))
|
||||||
(org-capture-put-target-region-and-position)
|
(org-capture-put-target-region-and-position)
|
||||||
(widen)
|
(widen)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(if (re-search-forward (format org-complex-heading-regexp-format
|
(if (re-search-forward (format org-complex-heading-regexp-format
|
||||||
(regexp-quote headline))
|
(regexp-quote headline))
|
||||||
nil t)
|
nil t)
|
||||||
(goto-char (line-beginning-position))
|
(beginning-of-line)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(or (bolp) (insert "\n"))
|
(unless (bolp) (insert "\n"))
|
||||||
(insert "* " headline "\n")
|
(insert "* " headline "\n")
|
||||||
(beginning-of-line 0)))
|
(beginning-of-line 0)))
|
||||||
(`(file+olp ,path . ,outline-path)
|
(`(file+olp ,path . ,outline-path)
|
||||||
|
|
Loading…
Reference in a new issue