# HG changeset patch # User Oleksandr Gavenko # Date 1605885898 -7200 # Node ID cbcc2ac8f3e3907b635de782e7251b82b2ad1859 # Parent 9b97a088274e4f0ff5b93198f08fc8c0e593e646 Implemented mypasshide-mode for hiding passwords from my .org files. diff -r 9b97a088274e -r cbcc2ac8f3e3 .emacs-my --- 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 diff -r 9b97a088274e -r cbcc2ac8f3e3 mypasshide.el --- /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) +