+(defun elpher-menu-this-window ()
+ "Select this line’s buffer in this window.
+Switch to the buffer, if possible. If there is no buffer, chances
+are that we're looking at a history item. Let's visit the item
+instead of complaining that their buffers have been killed."
+ (interactive)
+ (elpher-menu-handle-buffer-or-data 'switch-to-buffer))
+
+(defun elpher-menu-other-window ()
+ "Select this line’s buffer in other window, leaving buffer menu visible."
+ (interactive)
+ (elpher-menu-handle-buffer-or-data 'switch-to-buffer-other-window))
+
+(defun elpher-menu-switch-other-window ()
+ "Make the other window select this line's buffer.
+The current window remains selected."
+ (interactive)
+ (elpher-menu-handle-buffer-or-data
+ (lambda (buf) (display-buffer buf t))))
+
+(defun elpher-menu-handle-buffer-or-data (buffer-func)
+ "Handle an item in `elpher-menu-mode'.
+Determine the entry ID of the Tabulated List entry at point. If
+ID is a buffer, invoke BUFFER-FUNC on it. Otherwise, ID is a
+list (BUFFER FUNC ARGS...). Switch to BUFFER using BUFFER-FUNC
+and apply FUNC to ARGS."
+ (let ((data (tabulated-list-get-id)))
+ (cond ((bufferp data)
+ (funcall buffer-func data))
+ ((and (listp data)
+ (buffer-live-p (nth 0 data))
+ (fboundp (nth 1 data)))
+ (funcall buffer-func (nth 0 data))
+ (apply (nth 1 data) (nthcdr 2 data)))
+ (t
+ (error "There's no entry on this line of the menu")))))
+