From ca096d002576d7298b7e6123e84b47dde3eaf9cb Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Thu, 5 Aug 2021 15:27:41 +0200 Subject: [PATCH] add bba monitor buffer changes inspired by http://howardism.org/Technical/Emacs/beep-for-emacs.html send an alarm if the content of a buffer changes. Neat for your long running SQL queries. --- bba.org | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/bba.org b/bba.org index b85c806f..becacec5 100644 --- a/bba.org +++ b/bba.org @@ -3788,6 +3788,63 @@ the clipboard content before executing it. (define-key global-map (kbd "s-w") 'bba-copy-line-or-region-to-iterm) #+END_SRC +* bba monitor buffer changes +[2021-08-05 Thu 09:59] + +With some code from http://howardism.org/Technical/Emacs/beep-for-emacs.html + +#+begin_src emacs-lisp :tangle yes + (require 'alert) + + (setq alert-default-style 'osx-notifier) + + (defvar beep-speech-executable "say %s" + "An OS-dependent shell string to speak. Replaces `%s' with a phrase.") + + (defvar beep-alert-sound-file + (expand-file-name "/System/Library/Sounds/Submarine.aiff") + "A WAV or AU file used at the completion of a function.") + + (defun beep--beep () + "Play a default notification sound file. + Customize the variable, `beep-alert-sound-file' to adjust the sound." + (play-sound-file beep-alert-sound-file)) + + (defun beep--speak (phrase) + "Call a program to speak the string, PHRASE. + Customize the variable, `beep-speech-executable'." + (let ((command (format beep-speech-executable phrase)) + (inhibit-message t)) + (shell-command command))) + + (defun beep--when-finished (phrase) + "Notify us with string, PHRASE, to grab our attention. + Useful after a long process has completed, but use sparingly, + as this can be pretty distracting." + (message phrase) + (alert phrase :title "Completed") + (beep--beep) + (beep--speak phrase)) + + (defun bba-notify-hook(beg end _) + "notify after changes and remove hook." + (beep--when-finished "The command has completed") + (remove-hook 'after-change-functions 'bba-notify-hook t) + ) + + (defun bba-add-notify-hook() + "add notify hook." + (interactive) + (if (buffer-file-name) + (save-buffer) + (set-buffer-modified-p nil)) ;; set buffer as unmodified + (make-local-variable 'after-change-functions) + (add-hook 'after-change-functions 'bba-notify-hook nil t) + ) + + +#+end_src + * bba lookup dictionary [2019-05-27 Mon 15:15] coffee mug -- 2.47.3