Implemented mypasshide-mode for hiding passwords from my .org files.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Fri, 20 Nov 2020 17:24:58 +0200
changeset 1640 cbcc2ac8f3e3
parent 1639 9b97a088274e
child 1641 bbb65280822b
Implemented mypasshide-mode for hiding passwords from my .org files.
.emacs-my
mypasshide.el
--- a/.emacs-my	Fri Nov 20 12:07:48 2020 +0200
+++ b/.emacs-my	Fri Nov 20 17:24:58 2020 +0200
@@ -1889,6 +1889,7 @@
 
 (when (featurep 'company)
   (add-hook 'org-mode-hook #'my-company-text-setup))
+(add-hook 'org-mode-hook #'mypasshide-mode)
 
 (defun my-org-archive-location (path)
   "For given PATH make path to archive. Currently add undescore
--- /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)
+