]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
add bba monitor buffer changes
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Thu, 5 Aug 2021 13:27:41 +0000 (15:27 +0200)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Thu, 5 Aug 2021 13:27:41 +0000 (15:27 +0200)
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

diff --git a/bba.org b/bba.org
index b85c806f2e7707e631d6682e962bfaac79bf364f..becacec5b347a5a1243c4674188f87eca1473796 100644 (file)
--- 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