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

Super mode gone after refreshing agenda with `g` #6

Closed
bascht opened this Issue Aug 2, 2017 · 14 comments

Comments

Projects
None yet
3 participants
@bascht

bascht commented Aug 2, 2017

First of all: Thanks for creating this beautiful add-on to org-mode! I run into one simple problem: After starting emacs, org-super-agenda-mode is enabled and everything is fine.

However after refreshing the agenda with g or starting the agenda later (C-a a) the agenda view is back to normal.

I'm on Emacs 25.2.1 with Prelude.
Am I holding it wrong? 😃

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 2, 2017

Owner

Hi Sebastian,

Thanks for your kind words. If you have time, I'd love if you could share an example config and/or a screenshot that I could add to the examples page. :)

I think the problem is that you're setting org-super-agenda-groups in a let, and the value of the variable isn't being preserved for the redo command. I'm not sure if there's a way to fix that, because I don't think Org is designed to do that.

Have you tried using it as a custom agenda command? I think that if you set the variable as a setting in a custom agenda command (see help for org-agenda-custom-commands), it will persist for the redo.

Other than that, if you set the variable globally, it will definitely persist across redos.

So I guess I should ask, can you show me an example of the code you're using, how you're setting the variable and running the command?

Thanks.

Owner

alphapapa commented Aug 2, 2017

Hi Sebastian,

Thanks for your kind words. If you have time, I'd love if you could share an example config and/or a screenshot that I could add to the examples page. :)

I think the problem is that you're setting org-super-agenda-groups in a let, and the value of the variable isn't being preserved for the redo command. I'm not sure if there's a way to fix that, because I don't think Org is designed to do that.

Have you tried using it as a custom agenda command? I think that if you set the variable as a setting in a custom agenda command (see help for org-agenda-custom-commands), it will persist for the redo.

Other than that, if you set the variable globally, it will definitely persist across redos.

So I guess I should ask, can you show me an example of the code you're using, how you're setting the variable and running the command?

Thanks.

@bascht

This comment has been minimized.

Show comment
Hide comment
@bascht

bascht Aug 2, 2017

Hi @alphapapa. Thanks for your quick reply. I'm not that firm in Elisp – so it was indeed some kind of scoping issue with the (let) command. I've since added it as a custom command and this works (small snippet from my org-init.el, taken from https://github.com/bascht/dotfiles-public/tree/master/home/.emacs.d/personal):

(use-package org-super-agenda
  :config (org-super-agenda-mode))

(setq org-agenda-custom-commands
      '(("c" "Super Agenda" agenda
         (org-super-agenda-mode)
         ((org-super-agenda-groups
           '(
             (:name "Next Items"
                    :time-grid t
                    :tag ("NEXT" "outbox"))
             (:name "Important"
                    :priority "A")
             (:name "Today"
                    :time-grid t
                    :scheduled today)
             (:name "Quick Picks"
                    :effort < 00:30 ; ← that one doesn't seem to work, no?
                    )
             (:priority<= "B"
                          :order 1)
             )))
         (org-agenda nil "a"))))

If I censor away my own data a bit, I'd be happy to supply a screenshot with my example. 😄

bascht commented Aug 2, 2017

Hi @alphapapa. Thanks for your quick reply. I'm not that firm in Elisp – so it was indeed some kind of scoping issue with the (let) command. I've since added it as a custom command and this works (small snippet from my org-init.el, taken from https://github.com/bascht/dotfiles-public/tree/master/home/.emacs.d/personal):

(use-package org-super-agenda
  :config (org-super-agenda-mode))

(setq org-agenda-custom-commands
      '(("c" "Super Agenda" agenda
         (org-super-agenda-mode)
         ((org-super-agenda-groups
           '(
             (:name "Next Items"
                    :time-grid t
                    :tag ("NEXT" "outbox"))
             (:name "Important"
                    :priority "A")
             (:name "Today"
                    :time-grid t
                    :scheduled today)
             (:name "Quick Picks"
                    :effort < 00:30 ; ← that one doesn't seem to work, no?
                    )
             (:priority<= "B"
                          :order 1)
             )))
         (org-agenda nil "a"))))

If I censor away my own data a bit, I'd be happy to supply a screenshot with my example. 😄

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 2, 2017

Owner

Great, I'm glad you got it working! Here are a couple of FYIs:

  1. Since you used :time-grid t in the "Next Items" group, it will group everything that matches it, so none of those items will make it down to the "Today" group. Maybe that's what you want, in which case the one in "Today" is redundant. :)
  2. No, I haven't added an :effort selector, because I've never used efforts before! :) But I think it should be easy to add, so I'll put that on my list.

If I censor away my own data a bit, I'd be happy to supply a screenshot with my example.

That would be great! In fact, instead of having to use GIMP on a screenshot, you can use this function I happen to have handy, which just replaces the visible heading of the current item in the agenda view, without changing the heading of the actual item:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary...IT IS NECESSARY
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Back to agenda buffer
    (save-excursion
      (when (and old-heading new-heading)
        ;; Replace agenda text
        (let ((inhibit-read-only t))
          (goto-char (line-beginning-position))
          (when (search-forward old-heading (line-end-position))
            (replace-match new-heading 'fixedcase 'literal)))))))
Owner

alphapapa commented Aug 2, 2017

Great, I'm glad you got it working! Here are a couple of FYIs:

  1. Since you used :time-grid t in the "Next Items" group, it will group everything that matches it, so none of those items will make it down to the "Today" group. Maybe that's what you want, in which case the one in "Today" is redundant. :)
  2. No, I haven't added an :effort selector, because I've never used efforts before! :) But I think it should be easy to add, so I'll put that on my list.

If I censor away my own data a bit, I'd be happy to supply a screenshot with my example.

That would be great! In fact, instead of having to use GIMP on a screenshot, you can use this function I happen to have handy, which just replaces the visible heading of the current item in the agenda view, without changing the heading of the actual item:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary...IT IS NECESSARY
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Back to agenda buffer
    (save-excursion
      (when (and old-heading new-heading)
        ;; Replace agenda text
        (let ((inhibit-read-only t))
          (goto-char (line-beginning-position))
          (when (search-forward old-heading (line-end-position))
            (replace-match new-heading 'fixedcase 'literal)))))))
@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 3, 2017

Owner

I just added effort selectors. They seem to be working, but please let me know if they work right for you. Thanks.

Owner

alphapapa commented Aug 3, 2017

I just added effort selectors. They seem to be working, but please let me know if they work right for you. Thanks.

@bascht

This comment has been minimized.

Show comment
Hide comment
@bascht

bascht Aug 3, 2017

@alphapapa Thanks for the :effort selector! Just updated to the latest version & it works! 😄
I cannot get (org-agenda-sharpie) to work, though. I'm in Agenda mode, cursor on the agenda item, run the function with M-x, can enter the new title in the Mini Buffer, but the actual item won't change. The *messages* buffer is empty. Any hints? 😄

bascht commented Aug 3, 2017

@alphapapa Thanks for the :effort selector! Just updated to the latest version & it works! 😄
I cannot get (org-agenda-sharpie) to work, though. I'm in Agenda mode, cursor on the agenda item, run the function with M-x, can enter the new title in the Mini Buffer, but the actual item won't change. The *messages* buffer is empty. Any hints? 😄

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 3, 2017

Owner

Great, glad it's working.

So sorry about the function not working. That code that I commented out, that I wasn't sure if it was necessary...well apparently it is. Oops. :) This should work, I just tested it:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary...IT IS!
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Back to agenda buffer
    (save-excursion
      (when (and old-heading new-heading)
        ;; Replace agenda text
        (let ((inhibit-read-only t))
          (goto-char (line-beginning-position))
          (when (search-forward old-heading (line-end-position))
            (replace-match new-heading 'fixedcase 'literal)))))))

Thank you!

Owner

alphapapa commented Aug 3, 2017

Great, glad it's working.

So sorry about the function not working. That code that I commented out, that I wasn't sure if it was necessary...well apparently it is. Oops. :) This should work, I just tested it:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary...IT IS!
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Back to agenda buffer
    (save-excursion
      (when (and old-heading new-heading)
        ;; Replace agenda text
        (let ((inhibit-read-only t))
          (goto-char (line-beginning-position))
          (when (search-forward old-heading (line-end-position))
            (replace-match new-heading 'fixedcase 'literal)))))))

Thank you!

@bascht

This comment has been minimized.

Show comment
Hide comment
@bascht

bascht Aug 3, 2017

@alphapapa We're one step further. The Sharpie will rewrite the very last tag (I've no idea why, though):

before

screenshot_20170803_180728

after

screenshot_20170803_180640

bascht commented Aug 3, 2017

@alphapapa We're one step further. The Sharpie will rewrite the very last tag (I've no idea why, though):

before

screenshot_20170803_180728

after

screenshot_20170803_180640

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 3, 2017

Owner

I'm stumped, I don't know how that could happen. You are using Org 9, right?

I modified the code a bit and tested it again on several headings, and it works every time for me:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (unless old-heading
      (error "Can't find heading.  How can this be?"))
    ;; Back to agenda buffer
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Replace agenda text
    (save-excursion
      (let ((inhibit-read-only t))
        (goto-char (line-beginning-position))
        (when (search-forward old-heading (line-end-position))
          (replace-match new-heading 'fixedcase 'literal))))))

I hope we can get it working, I really like the look of that screenshot. Thanks for your patience.

Owner

alphapapa commented Aug 3, 2017

I'm stumped, I don't know how that could happen. You are using Org 9, right?

I modified the code a bit and tested it again on several headings, and it works every time for me:

(defun org-agenda-sharpie ()
  "Censor the text of items in the agenda."
  (interactive)
  (let (regexp old-heading new-heading properties)
    ;; Save face properties of line in agenda to reapply to changed text
    (setq properties (text-properties-at (point)))

    ;; Go to source buffer
    (org-with-point-at (org-find-text-property-in-string 'org-marker
                                                         (buffer-substring (line-beginning-position)
                                                                           (line-end-position)))
      ;; Save old heading text and ask for new text
      (line-beginning-position)
      (unless (org-at-heading-p)
        ;; Not sure if necessary
        (org-back-to-heading))
      (setq old-heading (when (looking-at org-complex-heading-regexp)
                          (match-string 4))))
    (unless old-heading
      (error "Can't find heading.  How can this be?"))
    ;; Back to agenda buffer
    (setq new-heading (read-from-minibuffer "Overwrite visible heading with: "))
    (add-text-properties 0 (length new-heading) properties new-heading)
    ;; Replace agenda text
    (save-excursion
      (let ((inhibit-read-only t))
        (goto-char (line-beginning-position))
        (when (search-forward old-heading (line-end-position))
          (replace-match new-heading 'fixedcase 'literal))))))

I hope we can get it working, I really like the look of that screenshot. Thanks for your patience.

@bascht

This comment has been minimized.

Show comment
Hide comment
@bascht

bascht Aug 4, 2017

Thanks again for debugging this & providing a new function. I'm on the latest org-mode, but I think there might be something off with my tags / the way they align. The function works in some cases and doesn't in some cases (the headlines tag shows a double colon like :something::).

Long story sort: I cleaned up my items a bit and you can use the uncensored version, as there are (hopefully) no confidential or embarrassing tasks left. 😬

Screenshot

screenshot_20170804_181001

My config (heavily inspired by yours ;))

(setq org-agenda-custom-commands
      '(("c" "Super Agenda" agenda
         (org-super-agenda-mode)
         ((org-super-agenda-groups
           '(
             (:name "Next Items"
                    :time-grid t
                    :tag ("NEXT" "outbox"))
             (:name "Important"
                    :priority "A")
             (:name "Quick Picks"
                    :effort< "0:30"
                    )
             (:priority<= "B"
                          :scheduled > "tomorrow"
                          :order 1)
             )))
         (org-agenda nil "a"))))

bascht commented Aug 4, 2017

Thanks again for debugging this & providing a new function. I'm on the latest org-mode, but I think there might be something off with my tags / the way they align. The function works in some cases and doesn't in some cases (the headlines tag shows a double colon like :something::).

Long story sort: I cleaned up my items a bit and you can use the uncensored version, as there are (hopefully) no confidential or embarrassing tasks left. 😬

Screenshot

screenshot_20170804_181001

My config (heavily inspired by yours ;))

(setq org-agenda-custom-commands
      '(("c" "Super Agenda" agenda
         (org-super-agenda-mode)
         ((org-super-agenda-groups
           '(
             (:name "Next Items"
                    :time-grid t
                    :tag ("NEXT" "outbox"))
             (:name "Important"
                    :priority "A")
             (:name "Quick Picks"
                    :effort< "0:30"
                    )
             (:priority<= "B"
                          :scheduled > "tomorrow"
                          :order 1)
             )))
         (org-agenda nil "a"))))
@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 5, 2017

Owner

Thanks, Sebastian, that screenshot looks great, I will add it and the config to the examples page.

I'm perplexed by the problem with the function and the tags issue. I use code straight from Org to read the entry title, so I don't understand how it could be getting a tag instead. You might have actually found an obscure bug in Org itself, so you might look at some of the items it misbehaved on and see if the tag string is correct, and whether this code returns the title or a tag or something else (with point at the beginning of the heading line):

(when (looking-at org-complex-heading-regexp)
                          (match-string 4))

By the way, the (:scheduled > "tomorrow") selector won't work, it should be like (:scheduled future) for anything after today, or (:scheduled (after "2017-08-03")) for arbitrary dates.

Thanks for your help with this!

Owner

alphapapa commented Aug 5, 2017

Thanks, Sebastian, that screenshot looks great, I will add it and the config to the examples page.

I'm perplexed by the problem with the function and the tags issue. I use code straight from Org to read the entry title, so I don't understand how it could be getting a tag instead. You might have actually found an obscure bug in Org itself, so you might look at some of the items it misbehaved on and see if the tag string is correct, and whether this code returns the title or a tag or something else (with point at the beginning of the heading line):

(when (looking-at org-complex-heading-regexp)
                          (match-string 4))

By the way, the (:scheduled > "tomorrow") selector won't work, it should be like (:scheduled future) for anything after today, or (:scheduled (after "2017-08-03")) for arbitrary dates.

Thanks for your help with this!

@bascht

This comment has been minimized.

Show comment
Hide comment
@bascht

bascht Aug 7, 2017

Thanks for the :scheduled future hint! I didn't even notice that no filter did match. 😬
The Org issue itself is really weird. I found one headline where (org-agenda-sharpie) would replace the first bit (the actual file) and after reloading the aganda everything was back to normal and it would replace the actual headline text.

Your search function did work for every headline, however. 😄

bascht commented Aug 7, 2017

Thanks for the :scheduled future hint! I didn't even notice that no filter did match. 😬
The Org issue itself is really weird. I found one headline where (org-agenda-sharpie) would replace the first bit (the actual file) and after reloading the aganda everything was back to normal and it would replace the actual headline text.

Your search function did work for every headline, however. 😄

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 7, 2017

Owner

Hm, that is strange. Of course, this is my own little hack, and so it's not a big surprise that there are corner cases in the agenda's hidden text properties, haha.

Thanks for your help!

Owner

alphapapa commented Aug 7, 2017

Hm, that is strange. Of course, this is my own little hack, and so it's not a big surprise that there are corner cases in the agenda's hidden text properties, haha.

Thanks for your help!

@alphapapa alphapapa closed this Aug 7, 2017

@novoid

This comment has been minimized.

Show comment
Hide comment
@novoid

novoid Aug 12, 2017

In case you're looking for an additional example configuration, I linked the relevant parts of my configuration.

The advantage of my approach is the central definition of my super-agenda which is used as my default agenda defined in org-agenda-custom-commands and in the function my-org-agenda() which brings you to your agenda right away:

  • my-super-agenda
    • defines a variable my-super-agenda-groups which holds my central definition of super-agenda
    • defines function my-super-agenda() which calls my super-agenda interactively or within other functions
      - org-agenda-custom-commands
      - includes my super-agenda as a small snippet which is using the my-super-agenda-groups from above
      - my-org-agenda
      - a function which switches to the already generated agenda (which is waiting in a background buffer) or re-generates my agenda

novoid commented Aug 12, 2017

In case you're looking for an additional example configuration, I linked the relevant parts of my configuration.

The advantage of my approach is the central definition of my super-agenda which is used as my default agenda defined in org-agenda-custom-commands and in the function my-org-agenda() which brings you to your agenda right away:

  • my-super-agenda
    • defines a variable my-super-agenda-groups which holds my central definition of super-agenda
    • defines function my-super-agenda() which calls my super-agenda interactively or within other functions
      - org-agenda-custom-commands
      - includes my super-agenda as a small snippet which is using the my-super-agenda-groups from above
      - my-org-agenda
      - a function which switches to the already generated agenda (which is waiting in a background buffer) or re-generates my agenda
@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Aug 12, 2017

Owner

Thanks, Karl, that's awesome!

Owner

alphapapa commented Aug 12, 2017

Thanks, Karl, that's awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment