* org-capture with :prepend t breaks :clock-resume functionality in 9.1.9
@ 2019-10-25 17:35 Cody Goodman
2019-10-26 0:01 ` Cody Goodman
2020-02-12 16:45 ` Bastien
0 siblings, 2 replies; 3+ messages in thread
From: Cody Goodman @ 2019-10-25 17:35 UTC (permalink / raw
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1238 bytes --]
I found a bug and traced down relevant pieces of it, but haven't figured
out how to fix the behavior of org-capture where `:prepend t`
`:clock-resume` works with and clock data from `:clock-in t` is visible
with:
```
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "file.org" "File")
"* TODO %?"
:clock-in t
:clock-resume t)))
```
If you add prepend into the mix though:
```
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "file.org" "File")
"* TODO %?"
:clock-in t
:clock-resume t
:prepend t)))
```
You can no longer see the clocking data. Not the worst thing... right?
Well, :clock-resume depends on the clock-data being before point-max of the
capture buffer.
Causing the part that resumes the previous clock to never fire in
org-capture-finalize:
```
(and org-capture-clock-was-started
org-clock-marker
(eq (marker-buffer org-clock-marker) (buffer-base-buffer))
(>= org-clock-marker (point-min))
(< org-clock-marker (point-max))) ;; clock marker when :prepend t is
past point-max
```
My versions are:
Org mode version 9.1.9 (release_9.1.9-65-g5e4542 @
/home/cody/.emacs.d/straight/build/org/)
GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.10)
[-- Attachment #2: Type: text/html, Size: 1601 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: org-capture with :prepend t breaks :clock-resume functionality in 9.1.9
2019-10-25 17:35 org-capture with :prepend t breaks :clock-resume functionality in 9.1.9 Cody Goodman
@ 2019-10-26 0:01 ` Cody Goodman
2020-02-12 16:45 ` Bastien
1 sibling, 0 replies; 3+ messages in thread
From: Cody Goodman @ 2019-10-26 0:01 UTC (permalink / raw
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 6473 bytes --]
A little different solution that takes advantage of the fact that adding a
newline preserves the clock in the narrowed buffer. Maybe the right thing
to do is to widen/re-narrow buffer to include the clock within org-clock-in
though if it detects it's in an org capture buffer? Here is my working
solution for now with use-package and advice:
(use-package org
:straight org-plus-contrib
:init
(defun my/org-capture-place-entry ()
"Place the template as a new Org entry."
(let ((template (org-capture-get :template))
(reversed? (org-capture-get :prepend))
(exact-position (org-capture-get :exact-position))
(insert-here? (org-capture-get :insert-here))
(level 1))
(org-capture-verify-tree template)
(when exact-position (goto-char exact-position))
(cond
;; Force insertion at point.
((org-capture-get :insert-here) nil)
;; Insert as a child of the current entry.
((org-capture-get :target-entry-p)
(setq level (org-get-valid-level
(if (org-at-heading-p) (org-outline-level) 1)
1))
(if reversed? (outline-next-heading) (org-end-of-subtree t t)))
;; Insert as a top-level entry at the beginning of the file.
(reversed?
(goto-char (point-min))
(unless (org-at-heading-p) (outline-next-heading)))
;; Otherwise, insert as a top-level entry at the end of the file.
(t (goto-char (point-max))))
(let ((origin (point)))
(unless (bolp) (insert "\n"))
(org-capture-empty-lines-before)
(let ((beg (point)))
(save-restriction
(when insert-here? (narrow-to-region beg beg))
(org-paste-subtree level template 'for-yank))
(org-capture-position-for-last-stored beg)
(let ((end (point)))
(org-capture-empty-lines-after)
(unless (org-at-heading-p) (outline-next-heading))
(org-capture-mark-kill-region origin (point))
;; CHANGE: insert a newline so clock is included
(if (org-capture-get :clock-in) (insert "\n"))
(org-capture-narrow beg end)
(when (or (search-backward "%?" beg t)
(search-forward "%?" end t))
(replace-match "")))))))
(defun my/org-capture (&optional goto keys)
"Capture something.
\\<org-capture-mode-map>
This will let you select a template from `org-capture-templates', and
then file the newly captured information. The text is immediately
inserted at the target location, and an indirect buffer is shown where
you can edit it. Pressing `\\[org-capture-finalize]' brings you back to
the \
previous
state of Emacs, so that you can continue your work.
When called interactively with a `\\[universal-argument]' prefix argument
\
GOTO, don't
capture anything, just go to the file/headline where the selected
template stores its notes.
With a `\\[universal-argument] \\[universal-argument]' prefix argument,
go to \
the last note stored.
When called with a `C-0' (zero) prefix, insert a template at point.
When called with a `C-1' (one) prefix, force prompting for a date when
a datetree entry is made.
ELisp programs can set KEYS to a string associated with a template
in `org-capture-templates'. In this case, interactive selection
will be bypassed.
If `org-capture-use-agenda-date' is non-nil, capturing from the
agenda will use the date at point as the default date. Then, a
`C-1' prefix will tell the capture process to use the HH:MM time
of the day at point (if any) or the current HH:MM time."
(interactive "P")
(when (and org-capture-use-agenda-date
(eq major-mode 'org-agenda-mode))
(setq org-overriding-default-time
(org-get-cursor-date (equal goto 1))))
(cond
((equal goto '(4)) (org-capture-goto-target))
((equal goto '(16)) (org-capture-goto-last-stored))
(t
(let* ((orig-buf (current-buffer))
(annotation (if (and (boundp 'org-capture-link-is-already-stored)
org-capture-link-is-already-stored)
(plist-get org-store-link-plist :annotation)
(ignore-errors (org-store-link nil))))
(entry (or org-capture-entry (org-capture-select-template keys)))
initial)
(setq initial (or org-capture-initial
(and (org-region-active-p)
(buffer-substring (point) (mark)))))
(when (stringp initial)
(remove-text-properties 0 (length initial) '(read-only t) initial))
(when (stringp annotation)
(remove-text-properties 0 (length annotation)
'(read-only t) annotation))
(cond
((equal entry "C")
(customize-variable 'org-capture-templates))
((equal entry "q")
(user-error "Abort"))
(t
(org-capture-set-plist entry)
(org-capture-get-template)
(org-capture-put :original-buffer orig-buf
:original-file (or (buffer-file-name orig-buf)
(and (featurep 'dired)
(car (rassq orig-buf
dired-buffers))))
:original-file-nondirectory
(and (buffer-file-name orig-buf)
(file-name-nondirectory
(buffer-file-name orig-buf)))
:annotation annotation
:initial initial
:return-to-wconf (current-window-configuration)
:default-time (or org-overriding-default-time
(org-current-time)))
(org-capture-set-target-location (and (equal goto 0) 'here))
(condition-case error
(org-capture-put :template (org-capture-fill-template))
((error quit)
(if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
(error "Capture abort: %s" (error-message-string error))))
(setq org-capture-clock-keep (org-capture-get :clock-keep))
(condition-case error
(org-capture-place-template
(eq (car (org-capture-get :target)) 'function))
((error quit)
(when (and (buffer-base-buffer (current-buffer))
(string-prefix-p "CAPTURE-" (buffer-name)))
(kill-buffer (current-buffer)))
(set-window-configuration (org-capture-get :return-to-wconf))
(error "Capture template `%s': %s"
(org-capture-get :key)
(error-message-string error))))
(when (and (derived-mode-p 'org-mode) (org-capture-get :clock-in))
(condition-case nil
(progn
(when (org-clock-is-active)
(org-capture-put :interrupted-clock
(copy-marker org-clock-marker)))
(org-clock-in)
;; CHANGE: remove inserted newline now that clock is in narrowed buffer
(save-excursion (if (org-capture-get :clock-in)
(progn (goto-char (point-max)) (join-line))))
(setq-local org-capture-clock-was-started t))
(error "Could not start the clock in this capture buffer")))
(when (org-capture-get :immediate-finish)
(org-capture-finalize))))))))
(advice-add 'org-capture-place-entry :override
#'my/org-capture-place-entry)
(advice-add 'org-capture :override #'my/org-capture)
)
[-- Attachment #2: Type: text/html, Size: 7956 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: org-capture with :prepend t breaks :clock-resume functionality in 9.1.9
2019-10-25 17:35 org-capture with :prepend t breaks :clock-resume functionality in 9.1.9 Cody Goodman
2019-10-26 0:01 ` Cody Goodman
@ 2020-02-12 16:45 ` Bastien
1 sibling, 0 replies; 3+ messages in thread
From: Bastien @ 2020-02-12 16:45 UTC (permalink / raw
To: Cody Goodman; +Cc: emacs-orgmode
Hi Cody,
this should have been fixed, if you can upgrade to Org > 9.3.3.
Thanks,
--
Bastien
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-02-12 16:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-25 17:35 org-capture with :prepend t breaks :clock-resume functionality in 9.1.9 Cody Goodman
2019-10-26 0:01 ` Cody Goodman
2020-02-12 16:45 ` Bastien
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.