aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2020-11-08 21:35:51 +0100
committerOmar Polo <op@omarpolo.com>2020-11-08 21:35:51 +0100
commitc68302c3b72cc4082640e7b2248dc6ccf13747b9 (patch)
treede7cc67f0bb79ca6df5fb5b6bc146406ae36a2e1
downloadtmd.el-c68302c3b72cc4082640e7b2248dc6ccf13747b9.tar.gz
tmd.el-c68302c3b72cc4082640e7b2248dc6ccf13747b9.tar.bz2
initial commitHEADmaster
-rw-r--r--README.org13
-rw-r--r--tmd.el71
2 files changed, 84 insertions, 0 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..3bfd9d0
--- /dev/null
+++ b/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 ;)
diff --git a/tmd.el b/tmd.el
new file mode 100644
index 0000000..9de035f
--- /dev/null
+++ b/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