A minor mode to hide sensitive values in buffers per major mode
  • Emacs Lisp 100%
Find a file
Erick Navarro ba182aafeb fix: only remove overlays created by cloak-mode
we were deleting all the overlays associated with the current text
selection
2026-03-09 08:55:18 -06:00
cloak-mode.el fix: only remove overlays created by cloak-mode 2026-03-09 08:55:18 -06:00
demo.gif Add demo gif 2022-10-09 19:35:13 -05:00
LICENSE Initial commit 2022-10-08 13:03:41 -05:00
README.md feat: add support to define pattern per buffer name 2026-03-08 23:28:38 -06:00

Cloak-mode

MELPA

Minor mode to cloak sensitive data

Motivation

I used to use hidepw package but it only supports a plain list of regexs and also use font locking which have some conflicts with other packages, cloak-mode allows to setup a regex by major mode, which fits betters for my use case.

Demo

demo

Installation

Cloning the repo

Clone this repo somewhere, and add this to your config:

(add-to-list 'load-path "path where the repo was cloned")

;; for example we load it for envrc files
(require 'cloak-mode)
(setq cloak-mode-patterns '((envrc-file-mode . "[a-zA-Z0-9_]+[ \t]*=[ \t]*\\(.*+\\)$")))
(global-cloak-mode)

;; or for a buffer by name
(require 'cloak-mode)
(setq cloak-mode-patterns '(("*scratch*" . "[a-zA-Z0-9_]+[ \t]*=[ \t]*\\(.*+\\)$")))
(global-cloak-mode)

Using use-package

(use-package cloak-mode
  :ensure t
  :config
  (global-cloak-mode))

Using straight.el

(use-package cloak-mode
  :straight (cloak-mode
             :type git
             :host github
             :repo "erickgnavar/cloak-mode")
  :config
  (global-cloak-mode))

Examples

Single pattern per mode

In case we need just one pattern we can define directly as a string

(setq cloak-mode-patterns '((envrc-file-mode . "[a-zA-Z0-9_]+[ \t]*=[ \t]*\\(.*+\\)$")))

Many patterns per mode

In case we need many patterns we can define a list of strings

(setq cloak-mode-patterns '((envrc-file-mode . ("first-pattern" "second pattern"))))

Buffer name matching

You can also match buffers by name (useful for special buffers like *scratch* or *Messages*):

;; Match specific buffer names
(setq cloak-mode-patterns '(("*scratch*" . "[a-zA-Z0-9_]+=\\(.*\\)")))

;; Mixed: major mode and buffer name
(setq cloak-mode-patterns '((envrc-file-mode . "[a-zA-Z0-9_]+=[ \t]*\\(.*\\)$")
                            ("*scratch*" . "[a-zA-Z0-9_]+=\\(.*\\)")))

;; Multiple patterns per buffer name
(setq cloak-mode-patterns '(("*scratch*" . ("pattern1" "pattern2"))))