Commit Diff
Diff:
/dev/null
c68302c3b72cc4082640e7b2248dc6ccf13747b9
Commit:
c68302c3b72cc4082640e7b2248dc6ccf13747b9
Tree:
de7cc67f0bb79ca6df5fb5b6bc146406ae36a2e1
Author:
Omar Polo <op@omarpolo.com>
Date:
Sun Nov 8 20:35:51 2020 UTC
Message:
initial commit
commit - /dev/null
commit + c68302c3b72cc4082640e7b2248dc6ccf13747b9
blob - /dev/null
blob + 3bfd9d0752be147d51e30789c11f38364c6a5615 (mode 644)
--- /dev/null
+++ README.org
@@ -0,0 +1,13 @@
+#+TITLE: The Most Dangerous Minor Mode
+
+The Most Dangerous Minor Mode, as the name says, is a particularly
+dangerous Emacs minor mode. It’s inspired by the website “the most
+dangerous writing app”.
+
+If you don’t type at least one key every ~tmd-timeout~, (by default 5
+seconds) the whole buffer will be deleted (the narrowing will be
+respected).
+
+You can enable and toggle it with =M-x tmd-minor-mode RET=.
+
+It doesn’t delete the undo history, this is probably a bug ;)
blob - /dev/null
blob + 9de035f512070d80b6a79e84caeafa4b8930e78e (mode 644)
--- /dev/null
+++ tmd.el
@@ -0,0 +1,71 @@
+;;; tmd.el --- The Most Dangerous minor mode. -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2020 Omar Polo
+
+;; Author: Omar Polo
+;; Created: 08 Nov 2020
+;; Keywords: useless
+;; URL: https://git.omarpolo.com/tmd
+
+;; This file is not part of GNU Emacs.
+
+;;; License:
+
+;; Permission to use, copy, modify, and distribute this software for any
+;; purpose with or without fee is hereby granted, provided that the above
+;; copyright notice and this permission notice appear in all copies.
+
+;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+;;; Commentary:
+
+;; The most dangerous minor mode will delete all the text in the
+;; buffer (respecting narrowing) if you don't insert at least one
+;; character every `tmd-timeout'.
+
+;;; Code:
+
+(defvar tmd-timeout "5 seconds"
+ "Timeout before deleting the document.")
+
+(defvar tmd--timer nil
+ "The timer.")
+
+(defvar tmd--buffer nil
+ "The buffer.")
+
+;;;###autoload
+(define-minor-mode tmd-minor-mode
+ "The Most Dangerous Minor Mode."
+ :lighter " tmd"
+ (make-local-variable 'tmd--timer)
+ (make-local-variable 'tmd--buffer)
+ (setq tmd--buffer (current-buffer))
+ (add-hook 'post-self-insert-hook 'tmd--timer-reset))
+
+(defun tmd--delete ()
+ "Delete the whole buffer if the timer is expired."
+ (when tmd--buffer
+ (with-current-buffer tmd--buffer
+ (delete-region (point-min) (point-max))
+ (message "SLOW! MUAHAHAHAHAH"))))
+
+(defun tmd--run-timer ()
+ "Start the timer."
+ (setq tmd--timer (run-with-timer tmd-timeout nil 'tmd--delete)))
+
+(defun tmd--timer-reset ()
+ "Reset the timer."
+ (when tmd-minor-mode
+ (when tmd--timer
+ (cancel-timer tmd--timer))
+ (tmd--run-timer)))
+
+(provide 'tmd)
+;;; tmd.el ends here
Omar Polo