diff options
author | Carsten Dominik <carsten.dominik@gmail.com> | 2010-07-05 08:10:46 +0200 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2010-07-05 08:25:51 +0200 |
commit | 8b7c742750483468e2583e83a81b1b12d7444c09 (patch) | |
tree | 4ae255d4121ec0f487ba7f910b7a66a9e20703c6 | |
parent | 3f259819d6ee9a19b4277c55f00965916486804d (diff) | |
download | org-mode-8b7c742750483468e2583e83a81b1b12d7444c09.tar.gz |
Capture: Put final touched to file+regexp & file+function targets
* lisp/org-capture.el (org-capture-set-target-location): Store
exact positions for file+regexp and file+function targets.
(org-capture-place-entry, org-capture-place-item)
(org-capture-place-table-line, org-capture-place-plain-text): Respect
exact positions.
(org-capture-finalize): Make sure we are at the beginning of a line
when fixing the empty lines after the entry.
-rw-r--r-- | lisp/org-capture.el | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 8c887ce..afabb0a 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -454,6 +454,7 @@ bypassed." '(entry item checkitem plain))) (save-excursion (goto-char end) + (or (bolp) (newline)) (org-capture-empty-lines-after (or (org-capture-get :empty-lines 'local) 0)))) ;; Postprocessing: Update Statistics cookies, do the sorting @@ -567,9 +568,10 @@ already gone." (goto-char (point-min)) (if (re-search-forward (nth 2 target) nil t) (progn - (goto-char (match-beginning 0)) + (goto-char (if (org-capture-get :prepend) + (match-beginning 0) (match-end 0))) + (org-capture-put :exact-position (point)) (setq target-entry-p (and (org-mode-p) (org-at-heading-p)))) - (kill-buffer (current-buffer)) (error "No match for target regexp in file %s" (nth 1 target)))) ((eq (car target) 'file+datetree) @@ -588,6 +590,7 @@ already gone." ((eq (car target) 'file+function) (set-buffer (org-capture-target-buffer (nth 1 target))) (funcall (nth 2 target)) + (org-capture-put :exact-position (point)) (setq target-entry-p (and (org-mode-p) (org-at-heading-p)))) ((eq (car target) 'clock) @@ -640,6 +643,8 @@ already gone." (target-entry-p (org-capture-get :target-entry-p)) level beg end) (cond + ((org-capture-get :exact-position) + (goto-char (org-capture-get :exact-position))) ((not target-entry-p) ;; Insert as top-level entry, either at beginning or at end of file (setq level 1) @@ -674,8 +679,11 @@ already gone." "Place the template as a new plain list item." (let* ((txt (org-capture-get :template)) (target-entry-p (org-capture-get :target-entry-p)) - ind beg end) + (ind 0) + beg end) (cond + ((org-capture-get :exact-position) + (goto-char (org-capture-get :exact-position))) ((not target-entry-p) ;; Insert as top-level entry, either at beginning or at end of file (setq beg (point-min) end (point-max))) @@ -731,6 +739,8 @@ already gone." (table-line-pos (org-capture-get :table-line-pos)) ind beg end) (cond + ((org-capture-get :exact-position) + (goto-char (org-capture-get :exact-position))) ((not target-entry-p) ;; Table is not necessarily under a heading (setq beg (point-min) end (point-max))) @@ -804,7 +814,10 @@ already gone." "Place the template plainly." (let* ((txt (org-capture-get :template)) beg end) - (goto-char (if (org-capture-get :prepend) (point-min) (point-max))) + (goto-char (cond + ((org-capture-get :exact-position)) + ((org-capture-get :prepend) (point-min)) + (t (point-max)))) (or (bolp) (newline)) (org-capture-empty-lines-before) (setq beg (point)) |