The Emacs commands that create a new frame disappoint me. They create a frame that shares the same set of buffers as the main frame. I don't think a Tip Of The Day (TOTD) popup should have access to all the buffers in a session. I want a popup to display some help and be easily dismissed.1
That's why I designed my Tip Of The Day to run in a
separate Emacs instance. Instead of invoking the TOTD function
directly, Emacs asks the operating system to launch a second Emacs
process. One of the command line switches loads the Lisp file in
which the TOTD function is defined, and another runs the function.
This is achieved by invoking call-process-shell-command
to run a one-line batch file2 that contains this:
"path_to_emacs\emacs.exe" -Q -g 80x42-2+2 -l totd.el --eval (ztotd)
The -l switch loads totd.el, defining
both totd and ztotd. The
--eval switch then invokes ztotd. (The
other function, totd is not used; it's retained for reference.)
The -Q switch starts Emacs "quietly." -g
defines window geometries:3 WxH+X+Y,
where
- W and H specify the frame's width and height in character units.
- X and Y, if ≥0, specify the pixel coordinates of the upper left corner of the window. If <0, specify the distance from the right and bottom of the screen.
This is the statement in my init file that runs the batch file:
(call-process-shell-command "cmd.exe /Q /D /C invoke-emacs-totd.bat" nil 0)
Here's the listing for totd.el. The first
function, totd, is based on code that Dave Pearson
posted on EmacsWiki.4 To make it work with modern Emacs,
I replaced (require 'cl) with (require
'cl-lib) and (loop for s...) with
(cl-loop for s...).
;; Time-stamp: "2026-07-19 17:00:17 RayZ" ;; totd.el by DavePearson ;; This small code snippet displays a “tip of the day” ;; ;; 2026-07-14 Downloaded from https://www.emacswiki.org/emacs/TipOfTheDay ;; 2026-07-19 Derive ztotd to run in separate session (require 'cl-lib) (defun totd () (interactive) (with-output-to-temp-buffer "*Tip of the day*" (let* ((commands (cl-loop for s being the symbols when (commandp s) collect s)) (command (nth (random (length commands)) commands))) (princ (concat "Your tip for the day is:\n========================\n\n" (describe-function command) "\n\nInvoke with:\n\n" (with-temp-buffer (where-is command t) (buffer-string))))))) (defun ztotd () "Display documentation of a random Emacs function to provide a Tip Of The Day. It is intended to run in a separate session of Emacs where it modifies the frame to resemble a minimalist popup. Invoke at the command line with (for example): emacs.exe -Q -g 80x42-2+2 -l totd.el --eval (ztotd)" (interactive) (set-buffer (generate-new-buffer "Tip of the day")) (let* ((commands (cl-loop for s being the symbols when (commandp s) collect s)) (command (nth (random (length commands)) commands))) (insert (concat (describe-function command) "\n\nInvoke with:\n\n" (with-temp-buffer (where-is command t) (buffer-string)))) (tool-bar-mode 0) (menu-bar-mode 0) (setq frame-title-format '("Gnu Emacs Tip of the day")) (pop-to-buffer (current-buffer)) (goto-char (point-min)) (delete-other-windows) (message "Press C-x C-c to dismiss")))
totd is very intrusive by design -- it's supposed to
put a help page "in your face." But I wanted a "clean" look. So I
eliminated the toolbar and menu from the frame, moved "Tip of the
Day" from the buffer to the title, and got rid of other windows.
Plus I call it with
call-process-shell-command instead
of shell-command to prevent a shell output window from
appearing in the main frame.5
The batch file allows the OS itself to initiate the display of TOTD. It can be set up to run right after logon, or combined with Tea Timer or Scheduler for a periodic display.
I like how this performs. However, I hardly ever close and
restart Emacs. As a result, I may go a week or two without seeing a
tip. Is that why Emacs has never included a built-in Tip Of The
Day? Or is it just so easy to implement that "the proof has been
left as an exercise to the user?" Or maybe the help that's shown is
too specific. For example, "What does
image-dired-delete-tag actually do?" you might
wonder. I think that's the whole point of a TOTD -- to inspire
wonder!
If you try this on a non-Windows system, please let me know whether it works.
1 I tried display-buffer-pop-up-frame.
Somehow the popup lost focus and got buried behind the main frame.
When I closed the main frame, I thought that all my files were saved
and Emacs was closed. Only then did I realize the popup was still
running. When I tried to close it, Emacs warned about open files. So
nervously I maximized the small popup frame to review the unsaved
buffers.
2 In fact the batch file contains several lines of comments, too, as
well as the cherished @echo off statement at the very beginning.
@echo off prevents the many lines of comments from getting dumped to
standard output; otherwise those comments would end up in a shell buffer.
3 For more information on command line switches for Emacs, see: https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Invocation.html
4 Please see https://www.emacswiki.org/emacs/TipOfTheDay
5 Thanks to Jackson Ray Hamilton for this suggestion. https://stackoverflow.com/a/22982525
No comments:
Post a Comment
Thank you for taking time to comment. Please note that comments may be deleted if they:
* Contain link(s) to a domain outside USA or Canada or to a commercial enterprise.
* Include non-English words or characters.
* Are irrelevant to the subject matter of the post.
For posts older than 14 days, comments are moderated and require approval.