0

I use alpha-up as the org-agenda-sorting-strategy. I have many hyperlinks in my task titles. And these items seem to be sorted by the url first (as a hyperlink is [[url][title]]. How do I change this behavior to actually sort on text only?

0

Instead of using alpha-up, use user-defined-up and define org-agenda-cmp-user-defined as a function that does what you want. The doc string for org-agenda-cmp-user-defined says:

This function must receive two arguments, agenda entry a and b.
If a>b, return +1.  If a<b, return -1.  If they are equal as seen by
the user comparison, return nil.
When this is defined, you can make ‘user-defined-up’ and ‘user-defined-down’
part of an agenda sorting strategy.

One way would be to modify the two arguments to delete the URL part of any link that is encountered and then just do an alpha comparison on the results - something like this (N.B. untested and incomplete since it needs a definition of the no-urls function that would do the url erasing and which is left as an exercise, since I don't have the time to implement it atm):

(defun no-urls-string-cmp (a b)
   (let ((a-no-urls (no-urls a))
         (b-no-urls (no-urls b))
      (cond ((string-equal a-no-urls b-no-urls) nil)
            ((string-lessp a-no-urla b-no-urls) -1)
            (t 1))))

(add-hook 'org-agenda-mode-hook 
  (lambda () 
     (setq org-agenda-cmp-user-defined 'no-urls-string-cmp)))

and modify org-agenda-sorting-strategy to use user-defined-up instead of alpha-up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.