Redact sensitive information with regular expressions
Found a great idea from Zenodium.
This commit is contained in:
		
							parent
							
								
									19f3118d43
								
							
						
					
					
						commit
						f4df7d4368
					
				
					 1 changed files with 28 additions and 1 deletions
				
			
		| 
						 | 
					@ -23,7 +23,34 @@ A literate programming version for Emacs code to generate and store passwords.
 | 
				
			||||||
  ;;
 | 
					  ;;
 | 
				
			||||||
  ;;; Code:
 | 
					  ;;; Code:
 | 
				
			||||||
#+end_src
 | 
					#+end_src
 | 
				
			||||||
* Introduction
 | 
					* Overlay Redaction
 | 
				
			||||||
 | 
					Love [[https://xenodium.com/redact-that-buffer/][this idea]] for using a regular expression to /redact/ (or at least, obscure) sensitive information before screen sharing.
 | 
				
			||||||
 | 
					#+begin_src emacs-lisp
 | 
				
			||||||
 | 
					  (defun toggle-redact-buffer (regexp)
 | 
				
			||||||
 | 
					    "Redact buffer content matching regexp. A space redacts all."
 | 
				
			||||||
 | 
					    (interactive (list (read-regexp "Text to Redact (Regexp)" 'regexp-history-last)))
 | 
				
			||||||
 | 
					    (let* ((redacted)
 | 
				
			||||||
 | 
					           (matches (let ((results '()))
 | 
				
			||||||
 | 
					                      (when (string-empty-p regexp)
 | 
				
			||||||
 | 
					                        (setq regexp "[[:graph:]]")
 | 
				
			||||||
 | 
					                        (setq regexp-history-last regexp)
 | 
				
			||||||
 | 
					                        (add-to-history 'regexp-history regexp))
 | 
				
			||||||
 | 
					                      (save-excursion
 | 
				
			||||||
 | 
					                        (goto-char (point-min))
 | 
				
			||||||
 | 
					                        (while (re-search-forward regexp nil t)
 | 
				
			||||||
 | 
					                          (push (cons (match-beginning 0) (match-end 0)) results)))
 | 
				
			||||||
 | 
					                      (nreverse results))))
 | 
				
			||||||
 | 
					      (mapc (lambda (match)
 | 
				
			||||||
 | 
					              (dolist (overlay (overlays-in (car match) (cdr match)))
 | 
				
			||||||
 | 
					                (setq redacted t)
 | 
				
			||||||
 | 
					                (delete-overlay overlay))
 | 
				
			||||||
 | 
					              (unless redacted
 | 
				
			||||||
 | 
					                (overlay-put (make-overlay (car match) (cdr match))
 | 
				
			||||||
 | 
					                             'display (make-string (- (cdr match) (car match)) ?x))))
 | 
				
			||||||
 | 
					            matches)))
 | 
				
			||||||
 | 
					#+end_src
 | 
				
			||||||
 | 
					I’m not sure how often I will use this, so I’m not putting it on a keybinding, also so, I will also not put a name-spacing prefix on the function.
 | 
				
			||||||
 | 
					* Password Generation
 | 
				
			||||||
Let's assume that I store a bunch of words in data files:
 | 
					Let's assume that I store a bunch of words in data files:
 | 
				
			||||||
#+begin_src emacs-lisp
 | 
					#+begin_src emacs-lisp
 | 
				
			||||||
  (defvar ha-passwords-data-files (list (expand-file-name "adjectives.txt"
 | 
					  (defvar ha-passwords-data-files (list (expand-file-name "adjectives.txt"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue