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

org-ql-agenda: Custom formatter support #23

Open
georgewsinger opened this issue Jun 3, 2019 · 19 comments
Open

org-ql-agenda: Custom formatter support #23

georgewsinger opened this issue Jun 3, 2019 · 19 comments

Comments

@georgewsinger
Copy link

Is there a way to force org-ql-agenda to show the name of the buffer from which each task is derived? I tried adding :auto-category t to :super-groups but it didn't work (i.e., it probably groups by category but still doesn't show the name of the category).

@alphapapa
Copy link
Owner

You could modify the formatter to do so.

@georgewsinger
Copy link
Author

By this do you mean modifying this function to show the buffer source?

@alphapapa
Copy link
Owner

Yes. You can see a comment at the bottom that mentions adding the proper prefix, which refers to imitating org-agenda-prefix-format. Adding support for that would let you set the prefix according to your preferences.

Alternatively, you could use simple :after function advice to alter the string returned by the function.

@alphapapa alphapapa changed the title Show filenames in org-ql-agenda? org-ql-agenda: Custom formatter support Aug 10, 2019
@alphapapa alphapapa self-assigned this Aug 10, 2019
@alphapapa
Copy link
Owner

I probably won't work on this soon, but it's a good idea.

@alphapapa
Copy link
Owner

#44

@alphapapa alphapapa added this to the 0.5 milestone Jan 19, 2020
@Whil-
Copy link

Whil- commented May 3, 2020

Isn't this already supported with the use of "select" in org-ql-query? There one can provide a custom sexp to format the output. Same with the action argument to org-ql-select, no?

Is there a reason for not using the same functionality in the org-ql views?

@alphapapa
Copy link
Owner

@Whil- If you want to override the formatting function used in org-ql-view, you could use function advice. As I've said in other issues, I'm not very interested in adding little things that would be intended to be deprecated in the future.

@Whil-
Copy link

Whil- commented May 3, 2020

Got it, thanks. Though providing the select functionality also for the view function should hardly be considered minor. Thinking of org mode documents as a database of entities is very powerful and org-ql is very helpful with this. And allowing the output from the query on the database to be customized by for example adding attributes from the nodes etc. makes a lot of sense.

This ofc already is possible using org-ql-select and org-ql-query. So I'll just finish with a thumbs up for that! 👍

@alphapapa
Copy link
Owner

Though providing the select functionality also for the view function should hardly be considered minor.

What I mean is, since I plan to implement a new view library, I don't want to spend much effort on implementing formatting changes that would be obsoleted by the future plans.

In the meantime, you can use advice-add or cl-letf to override the formatting function in your code.

However, since this has taken a while, it might be worth adding an argument and/or a variable to let users more easily change the formatting function.

@pragmat1c1
Copy link

pragmat1c1 commented Oct 26, 2020

As I have pointed out here on reddit, the URL from OP provided in link is not working anymore. So I don't know which format function he is referencing.

Also does that mean - asked from an Elisp newbie - I need to go into the source code and modify the format function? Or the returned string?

@alphapapa
Copy link
Owner

Let's pick one place or the other to have this conversation. I'll reply on Reddit again.

@pragmat1c1
Copy link

pragmat1c1 commented Oct 26, 2020

For completeness I'll repost the solution via adding an advice here as well, if you don't mind?

(defun ugt/org-ql-view--format-element (orig-fun &rest args)
  "This function will intercept the original function and
   add the filename to the result.

   ARGS is `element' in `org-ql-view--format-element'"
  (if (not args)
      ""
    (let* ((element args)
           (properties (cadar element))
           (result (apply orig-fun element))
           (filename (buffer-name
                      (marker-buffer
                       (plist-get properties :org-marker)))))
      (concat filename " " result))))
(advice-add 'org-ql-view--format-element :around #'ugt/org-ql-view--format-element)

@alphapapa alphapapa modified the milestones: 0.5, 0.6 Nov 20, 2020
@jun8git
Copy link

jun8git commented Apr 24, 2021

Minor tweak to @pragmat1c1 code. In case someone wants to add category instead of filename.
updated properties as mentioned @ reddit comment

(defun ugt/org-ql-view--format-element (orig-fun &rest args)
  "This function will intercept the original function and
   add the category to the result.

   ARGS is `element' in `org-ql-view--format-element'"
  (if (not args)
      ""
    (let* ((element args)
           (properties (cadar element))
           (result (apply orig-fun element))
           (category (get-text-property
                      0
                      'org-category
                      (plist-get properties :todo-keyword))))
      (org-add-props (concat category ":" result) (text-properties-at 0 result)))))
(advice-add 'org-ql-view--format-element :around #'ugt/org-ql-view--format-element)

@alphapapa
Copy link
Owner

Since it's been so long since the last 0.x release, I'm going to defer this to 0.7 in an effort to reduce the scope of 0.6 and release it sooner.

@dmitri-zganiaiko
Copy link

I'm using this version of org-ql:

     Status: Installed in ‘org-ql-20220301.841/’ (unsigned).
    Version: 20220301.841
     Commit: af18eac2b80b2f56c135f37fcbdcce19fbc34b65

and the function from the comment above returns an empty category.

Here's the fixed version:

  (defun zdo/org-ql-view--format-element (orig-fun &rest args)
    "This function will intercept the original function and
   add the category to the result.

   ARGS is `element' in `org-ql-view--format-element'"
    (if (not args)
        ""
      (let* ((element args)
             (properties (cadar element))
             (result (apply orig-fun element))
             (category (org-entry-get (plist-get properties :org-marker) "CATEGORY")))
        (org-add-props
            (format "   %-8s %s" (concat category ":") result)
            (text-properties-at 0 result)))))
  (advice-add 'org-ql-view--format-element :around #'zdo/org-ql-view--format-element)

with nice indentation 🙂

image

@alphapapa
Copy link
Owner

For future reference, this issue will generally be addressed by the branch mentioned here: #331

@larrasket
Copy link

Thanks @dmitri-zganiaiko. I added some modifications to make sure the indentation will work too if the file or buffer name are too long.

(defun salih/org-ql-view--format-element (orig-fun &rest args)
  "This function will intercept the original function and
add the category to the result.

ARGS is `element' in `org-ql-view--format-element'"
  (if (not args)
      ""
    (let* ((element args)
           (properties (cadar element))
           (result (apply orig-fun element))
           (smt "")
           (category (org-entry-get (plist-get properties :org-marker) "CATEGORY")))
      (if (> (length category) 11)
          (setq category (substring category 0 10)))
      (if (< (length category) 11)
          (setq smt (make-string (- 11 (length category)) ?\s)))
      (org-add-props
       (format "   %-8s %s" (concat category ":" smt) result)
       (text-properties-at 0 result)))))

@pcompassion

This comment was marked as off-topic.

@alphapapa

This comment was marked as off-topic.

@alphapapa alphapapa removed this from the 0.8 milestone Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants