mypasshide.el
changeset 1640 cbcc2ac8f3e3
child 1641 bbb65280822b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mypasshide.el	Fri Nov 20 17:24:58 2020 +0200
@@ -0,0 +1,32 @@
+
+(defvar mypasshide-prefix-re "^pass: *")
+
+(defun mypasshide--toggle-display (overlay hide)
+  "Hide or reveal region. Signature follows convention for
+`reveal-toggle-invisible' from `reveal' mode."
+  (if hide
+      (overlay-put overlay 'display (propertize "****" 'face 'warning))
+    (overlay-put overlay 'display nil)))
+
+(defun mypasshide--hide ()
+  (save-excursion
+    (goto-char (point-min))
+    (while (re-search-forward mypasshide-prefix-re nil t)
+      (let* ((beg (match-end 0))
+            (end (line-end-position))
+            (overlay (make-overlay beg end)))
+        (mypasshide--toggle-display overlay t)
+        (overlay-put overlay 'reveal-toggle-invisible #'mypasshide--toggle-display)
+        ))))
+
+(define-minor-mode mypasshide-mode
+  "Hide passwords after `mypasshide-prefix-re' and activate
+`reveal-mode'. Disabling is not implemented."
+  :group 'reveal
+  (if mypasshide-mode
+      (progn
+        (mypasshide--hide)
+        (reveal-mode))))
+
+(provide 'mypasshide)
+