Emacs carnival: (re-)discovery of new features
This month's Emacs carnival is on feature discovery in Emacs, specifically asking six questions which I'll mostly answer in-line:
How often do you discover an Emacs feature?
I seem to discover new features regularly, at least once a month if not weekly. See the answer to question 4 below.
What was the most recent feature that you adopted?
Using the Diary and Calendar features that have been part of Emacs for a very long time. I expand on this below.
Are you a “Set it and forget it” type of user?
Yes, pretty much. Anything I find potentially useful gets added to my init scripts. If a new feature proves useful, it stays. If I forget about because it did not achieve any traction, I often end up leaving it in my initialization until I run into it again, at which time I usually remove it.
Do you read Emacs-centric social media trolling for new things to try?
Not trolling per se but I do look out for new things to try, following a large number of blog posts, following the Emacs hashtag on the fediverse, and by reading the News entries for any new version of Emacs.
What’s the next feature that you’d like to try?
I don't know. It depends on what I see next.
If you’re a Feature Creator, tell us about that!
I'm not a feature creator generally. I do however tweak the behaviour of existing features quite a lot. My Emacs is therefore very different to anybody else's, something that is true of many of us.
The core of this blog post, however, is my answer to question 2 above, where I will go into more detail on my most recent addition to my Emacs configuration.
Diary and Calendar mode
I'm a long time user of org mode not only for writing prose and code but also for managing my life via the agenda. However, having retired, my needs for time management have reduced significantly.1 This made me question whether org and its agenda were the right tools for me now.
Browsing the Emacs info manual, as one does, I ran into the The Calendar and the Diary section of the manual. This was not a new discovery: in starting to play around with these features, I realised I had an old diary file with entries from 2006! So I must have obviously used it before I encountered org mode.
The attraction of using the diary features of Emacs is that it is very simple. Although entries can be more complex, most of the time, each entry is a single line.
I should note that I still use org mode but mostly for writing (such as this blog entry).
The Diary and the modern connected world
One of the advantages of (semi-)retiring is that I mostly no longer have to use third party non-free and privacy invading tools such as Outlook, a tool which was forced upon me by my employer. However, I have lost appointment notifications appearing on my mobile phone that such tools, e.g. the Outlook's calendar, provide. I have many less appointments now but I do still have some and it would be nice to be able to receive notifications on the phone from the Emacs diary.
My solution to this consists of two elements: notifications for single events and a daily reminder of my agenda for the day.
Appointment notifications
To get notifications on my phone, I am making use of ntfy, an HTTP-based pub-sub notification service. I have a shell script, notify.sh which sends (publishes) text to ntfy. On the phone, I subscribe to my postings on that site and any new entries appear as notifications on the phone.
Getting Emacs to send appropriate information to the notification system has been done by advising the appt-display-message function. This function is provided by the built-in appt package in Emacs. Normally, the appt package displays upcoming appointments in the mini-buffer and indicates the presence of the appointment in the mode line. To have Emacs do more than this, specifically send information about the appointment to ntfy, the following advice is added:
(advice-add 'appt-display-message :after #'esf/appointment-notification)
and the function invoked, i.e. the advice, is2
(defun esf/appointment-notification (string mins)
(shell-command (format "~/synced/bin/notify.sh \"🔔 %s in %d minutes\" >/dev/null 2>/dev/null"
(car string) (car mins))))
Daily summary of agenda
Ideally, I should have been able to take the same approach for a daily summary, especially as Emacs already brings up a buffer with my day's appointments automatically early in the morning (if Emacs is running; otherwise, it does so when you start up Emacs). However, I found it easier to write my own function which uses functionality from the Diary system but formats the output in a form more suitable for sending as a notification to my phone:
(defun esf/diary-daily-notification ()
(interactive)
(let ((l (diary-list-entries (calendar-current-date) 2))
entries entry)
;; (message "There are %d entries for today: %s" (length l) l)
(dolist (entry l)
(let* ((description (cadr entry))
(date (car entry))
(year (nth 2 date))
(month (car date))
(day (car (cdr date)))
)
(setq entries (concat entries "\n"
(format "%s-%s-%s " year month day)
description "\n"))))
(if entries
(shell-command
(format "~/synced/bin/notify.sh \"📅 %s\" >/dev/null 2>/dev/null"
entries)) )))
The summary generated is for the current date and the next day as I find it useful to have a bit of a look ahead.
I then use the timer capabilities of Emacs (something else I have essentially re-discovered) to invoke that function every morning:
(require 'diary-lib)
(setq esf/diary-daily-notification-timer
(run-at-time "7am"
(* 24 3600)
'esf/diary-daily-notification))
ielm
A real discovery, from writing the codes above, is the interactive evaluation of Emacs Lisp expressions, ielm, basically a REPL for Emacs Lisp. I have always previously evaluated expressions in the scratch buffer but the ielm mode provides more support for trying Lisp expressions out. Very useful.
Blog navigation
| Previous post | Blog | Next post |
|---|---|---|
| Emacs carnival: rec mode, an all-text database system | Index | None (yet!) |
You can find me on Mastodon or you can email me should you wish to comment on this entry or the whole blog.
References
Footnotes:
Not in terms of time but in terms of things that have to be done.
This code and the code in the next section potentially need a little bit of tweaking, specifically to protect any double quotes that could appear in diary entries. This is left as an exercise for the reader. I simply ensure I do not use double quotes in my diary!