2

Within the emacs org-mode agenda timeline view, where items are separated by what I'm calling "date headings", I'd like to be able to control how the dates appear. Specifically, I'd like to abbreviate the day names and the month names.

For example, the default seems to be usage of full-names for the days and months:

Week-agenda (W06):
Monday      6 February 2017 W06
  Dated:      Scheduled:  TODO Backup laptop.
  Dated:      Scheduled:  PROJ Figure out quantum gravity.
  Habit:      TODO Feed pet whale.
Tuesday     7 February 2017
  Dated:      Scheduled:  TODO Buy new toothbrush.
  Dated:      Scheduled:  PROJ Resolve the Hodge conjecture.
Wednesday   8 February 2017
  Dated:      Scheduled:  TODO Clean finger nails.
  Dated:      Scheduled:  PROJ Create artificial life-form.
.
.
.

But I'd like it to look like this:

Week-agenda (W06):
Mon       6 Feb 2017 W06
  Dated:    Scheduled:  TODO Backup laptop.
  Dated:    Scheduled:  PROJ Figure out quantum gravity.
  Habit:    TODO Feed pet whale.
Tue       7 Feb 2017
  Dated:    Scheduled:  TODO Buy new toothbrush.
  Dated:    Scheduled:  PROJ Resolve the Hodge conjecture.
Wed       8 Feb 2017
  Dated:    Scheduled:  TODO Clean finger nails.
  Dated:    Scheduled:  PROJ Create artificial life-form.
.
.
.

I'd like to know how to make this change, and ideally I'd also like to know how I could have figured out how to do this by myself. I tried browsing variables using

M-x org-customize RET

but didn't see anything that seemed appropriate to modify. I was thinking maybe I should be looking at the source code of org-mode to see if I could figure it out.

  • 1
    Have a look at the variable org-agenda-format-date and the function org-agenda-format-date-aligned. The doc-string refers us to the function format-time-string, so look up that also. To see what makes the function tick, use M-x find-function -- you may need to load the library first though -- e.g., M-x eval-expression RET (require 'org-agenda) RET – lawlist Feb 14 '17 at 16:50
  • Here is an example I did in my Emacs infancy a few years ago to modify the appearance of dates in the agenda view: superuser.com/a/652026/206164 I might do something different now that I have a few years of Emacs under my belt, but that should get you started. – lawlist Feb 14 '17 at 16:56
1

A Solution (below) & How To Get It

How To

Here's one way to find the answer to this question for oneself:

  1. Formulate the (base) question and problem statement(s) to be clear, accurate, precise, and concise (and potentially formulate multiple versions of the question with different wording or perspective).

  2. Imagine potential solutions to the base question, and ways that one could find those potential solutions. This leads to further questions.

    For example, since I thought I might be able to manipulate variables to control the timeline view formatting, I should imagine, hmm, how could I discover the appropriate variable? Is there a way to search through all the variables? Is there a way to search for relevant variables?

    I had a method for browsing the variables, but that wasn't good enough.

  3. Review How To Ask Questions The Smart Way

  4. Search online for potential solutions. (But if base question isn't answered, use the further questions.)

  5. Skim/Read the Emacs Documentation/Manual and Org-mode Documentation/Manual, and do some more web searches when necessary.

Doing all this, I find:

  1. Searching online for (how to search for emacs variable), I find the first hit is (GNU Emacs Manual: Apropos). I find these two useful commands: M-x apropos and M-x apropos-variable

  2. Trying M-x apropos-variable RET agenda, I get a list of many variables that I can search (not just browse), and can select (by hitting RET) to get more information. Searching for (date) yields org-agenda-format-date. Its info gives its value as org-agenda-format-date-aligned and says this is defined in the file org-agenda.el.

    Hitting RET on the file name org-agenda.el (which is also a link) shows the file contents at the relevant location! Here, org-agenda-format-date and org-agenda-format-date-aligned are defined, and one can see that the latter is a function.

    It turns out, I could also find this variable by browsing via M-x org-customize RET > Org > Org Agenda > Org Agenda Daily/Weekly > Org Agenda Format Date. This reveals even more explicitly that the value (org-agenda-format-date-aligned) is a function.

    Looking at the function definition, the variable names inside it, and already being able to recognize common syntax for displaying text/numbers, I see that this is the function I should be modifying or replacing with my own function (as suggested by lawlist).

  3. I investigate the sub-functions to find out how to modify them (referring to the Emacs Lisp Intro/Manual when necessary to figure out optional arguments and confirm syntax).

  4. Looking in the most immediately relevant manual, I find: The Org (Mode) Manual > Agenda Views > Custom agenda views > Setting Options. It gives an example using org-agenda-custom-commands. This is not really relevant, although it does show a usage of setq that inspires me.

    In my .emacs initialization file, I use setq (see solution below), instead of defalias, as suggested by lawlist, to set org-agenda-format-date to a new function that I define: my-org-agenda-format-date-aligned.

  5. I restart emacs with this new initialization file, check my agenda, see that the day and month names are now abbreviated, but I'll have to make further adjustments to reduce some of the horizontal spacing.

  6. Further investigation reveals org-agenda-prefix-format to be the relevant variable. I use setq again in my .emacs file to modify this variable. (I'm not sure if this is really the proper use of setq, but it works!)

Solution

Disclaimer: this may be a bad hacky kluge, since I barely know what I'm doing here.

In my .emacs initialization file, I added the following.

;; Modify agenda display (spacing and name abbreviations)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; modify agenda "date headings" format (to abbreviate day and month names)
(setq org-agenda-format-date 'my-org-agenda-format-date-aligned)

(defun my-org-agenda-format-date-aligned (date)                                                                                                                                             
  "Format a DATE string for display in the daily/weekly agenda, or timeline.
This function makes sure that dates are aligned for easy reading."
  (require 'cal-iso)
  (let* ((dayname (calendar-day-name date 1 nil))
         (day (cadr date))
         (day-of-week (calendar-day-of-week date))
         (month (car date))
         (monthname (calendar-month-name month 1))
         (year (nth 2 date))
         (iso-week (org-days-to-iso-week
                    (calendar-absolute-from-gregorian date)))
         (weekyear (cond ((and (= month 1) (>= iso-week 52))
                          (1- year))
                         ((and (= month 12) (<= iso-week 1))
                          (1+ year))
                         (t year)))
         (weekstring (if (= day-of-week 1)
                         (format " W%02d" iso-week)
                       "")))
         (format "%-8s %2d %s %4d%s"
            dayname day monthname year weekstring)))

; modify spacing too:
(setq org-agenda-prefix-format
  '((agenda  . " %i %-10:c%?-12t% s")
    (timeline  . "  % s")
    (todo  . " %i %-12:c")
    (tags  . " %i %-12:c")
    (search . " %i %-12:c"))
)

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.