Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run usual org functions like refile or schedule on results from org-ql or org-ql-search #35

Closed
AloisJanicek opened this issue Aug 24, 2019 · 9 comments
Assignees

Comments

@AloisJanicek
Copy link

AloisJanicek commented Aug 24, 2019

I've just noticed that you can't use functions like org-agenda-refile or org-agenda-schedule on result items when using org-ql or org-ql-search. I even tried putting org-ql-block into org-agenda-custom-commands as shown in README, and I got same result.
For example running org-agenda-schedule returns org-agenda-check-type: No Org agenda currently displayed.
I kind of understand that org-ql buffers probably aren't usual org-agenda buffers and that org-ql is still in development, so at this point I am just asking if this is an expected behavior or some kind of issue on my side and if former, is there currently any way to use org-ql and be able to manipulate org items directly from results' buffer?

@mz-pdm
Copy link

mz-pdm commented Aug 25, 2019

This works as a workaround for me:

(defun my-set-org-agenda-type (&rest args)
  (when (and (not org-agenda-type)
             (eq major-mode 'org-agenda-mode))
    (set (make-local-variable 'org-agenda-type) 'agenda)))
(advice-add 'org-agenda-schedule :before 'my-set-org-agenda-type)
(advice-add 'org-agenda-deadline :before 'my-set-org-agenda-type)

Strangely, simply setting org-agenda-type in the agenda buffer doesn't work, its value remains nil.

@AloisJanicek
Copy link
Author

Thank you, works perfectly.
I also noticed that today org-agenda-refile works for me just fine without advising, strange.

@alphapapa
Copy link
Owner

@AloisJanicek Yes, as noted in the readme:

Note: The view buffer is currently put in org-agenda-mode, which means that some Org Agenda commands work, such as jumping to entries and changing item priorities (without necessarily updating the view). This feature is experimental and not guaranteed to work correctly with all commands. (It works to the extent it does because the appropriate text properties are placed on each item, imitating an Agenda buffer.)

@mz-pdm Yes, after some quick testing, I also found the org-agenda-type variable to be essentially unsettable, even buffer-locally with setq-local, which is strange.

I don't know what the best solution is. I don't think we should be advising functions to work around this in org-ql. Ideally we need to set org-agenda-type, then those commands should work. That's the problem we should try to solve first.

@alphapapa alphapapa self-assigned this Aug 26, 2019
@mz-pdm
Copy link

mz-pdm commented Aug 27, 2019

The following piece of code, when placed to org-agenda-finalize-hook, makes org-agenda-do-date-later and org-agenda-do-date-earlier (S-right, S-left) commands working:

    (goto-char (point-min))
    (while (not (eobp))
      (let* ((scheduled (org-get-at-bol 'scheduled))
             (pos (and scheduled (plist-get (cadr scheduled) :begin)))
             (marker (org-get-at-bol 'org-marker)))
        (when (and pos marker)
          (move-marker marker pos (marker-buffer marker))))
      (forward-line))

Advising the commands with org-agenda-type as outlined above is additionally needed.

@alphapapa
Copy link
Owner

@mz-pdm I don't understand what that code is doing, but we definitely can't be doing anything like that in this package. We can't advise any org-agenda functions here.

@mz-pdm
Copy link

mz-pdm commented Aug 29, 2019

What the code does is moving org-marker, present in the entry properties, from the beginning of a scheduled entry to its SCHEDULED: date. This is what the org-agenda-do-date-* functions require. It's a workaround I use to make the functions working, which makes my org-ql-block agenda functionality fairly complete.
Of course, we shouldn't advise Org functions, it's just a workaround until a proper solution, setting org-agenda-type, is found (sorry, I don't have time to help with that at the moment).

@mskorzhinskiy
Copy link
Contributor

@mz-pdm Yes, after some quick testing, I also found the org-agenda-type variable to be essentially unsettable, even buffer-locally with setq-local, which is strange.

I am not sure why this is designed in such way, I am not a emacs lisp expert, but I think there are two bits that making this unsetteble outside.

Frist one is in org-agenda-finalize function which setting org-agenda-type based on text properties from agenda buffer:

(defun org-agenda-finalize ()
  [...]
	(setq org-agenda-type (org-get-at-bol 'org-agenda-type))

The second one is org-agenda-update-agenda-type which is basically do the same but in post-command-hook:

(defun org-agenda-mode ()
  [...]
  (add-hook 'post-command-hook 'org-agenda-update-agenda-type nil 'local)

[...]

(defun org-agenda-update-agenda-type ()
  "Update the agenda type after each command."
  (setq org-agenda-type
	(or (get-text-property (point) 'org-agenda-type)
	    (get-text-property (max (point-min) (1- (point))) 'org-agenda-type))))

Also reading org-ql-agenda-buffer reports that this property is set to nil. I checked practically every symbol in the buffer, but sorry! No luck.

Fortunetly hacking org-ql package was very easy. First function in "Faces/properties" section is the function that is applying properties to the text that will appear in the buffer. Here is the patch:

--- org-ql-agenda-a.el  2019-09-12 20:16:05.143186082 +0200
+++ org-ql-agenda-b.el  2019-09-12 20:15:58.336519490 +0200
@@ -574,6 +574,7 @@
            (org-add-props it properties
              'todo-state todo-keyword
              'tags tag-list
+             'org-agenda-type 'agenda
              'org-habit-p habit-property)))))

Although, shifting entires with "org-agenda-do-date-earlier" and similiar still not working, it reports that timestamp was not found. Probably is should be text properties too?

Anyway, for me org-schedule is enough and I set org-agenda-type to 'search. I believe it suits org-ql buffers better.

mskorzhinskiy pushed a commit to mskorzhinskiy/org-ql that referenced this issue Sep 13, 2019
Some functions in org-agenda checking against org-agenda-type variable to
ensure that this action is valid to run in that type of agenda. Notably
this fix running 'org-agenda-schedule' and 'org-agenda-deadline'
functions.

Also setting agenda type to 'search' prohibits some of the functions that
are still not working on in these buffers, like
"org-agenda-do-date-earlier".
mskorzhinskiy added a commit to mskorzhinskiy/org-ql that referenced this issue Sep 13, 2019
Some functions in org-agenda checking against org-agenda-type variable to
ensure that this action is valid to run in that type of agenda. Notably
this fix running 'org-agenda-schedule' and 'org-agenda-deadline'
functions.

Also setting agenda type to 'search' prohibits some of the functions that
are still not working on in these buffers, like
"org-agenda-do-date-earlier".
@alphapapa
Copy link
Owner

Hi Mikhail,

Thank you very much for doing that research, and for sending the PR. I will see about merging it soon.

@alphapapa
Copy link
Owner

This should be fixed now (at least, for some commands, like scheduling and deadlines). Thanks to all for your help here.

alphapapa pushed a commit that referenced this issue Oct 2, 2019
Some org-agenda commands check the org-agenda-type text property to
ensure that the command is valid to run in that type of agenda.
Notably this fixes running commands org-agenda-schedule and
org-agenda-deadline.

Setting the type to "search" prohibits some of the functions that are
still not working in these buffers, like org-agenda-do-date-earlier.

Fixes #35.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants