0

I currently have Emacs encrypting a .gpg file transparently as is the expected behaviour and I'm wondering if this can be extended to all file types so that Emacs can attempt decryption on all files without having to use the .gpg extension. I know something like this can be done with org-mode and txt files:

(add-to-list 'auto-mode-alist '("\\.txt$" . org-mode)) 

But is there an equivalent for gpg too?

To clarify, I don't mean having to call a file foo.org.gpg to open it in org-mode, rather just foo.org and still encrypt/decrypt it anyway without needing ;; -*- epa-file-encrypt-to: ("[email protected]") -*- either.

2
  • "rather just foo.org" -- are you saying that you intend to have every org-mode file on your filesystem encrypted? You're happy that Emacs will never encounter a *.org file which is not encrypted? Commented Feb 28, 2024 at 13:32
  • @phils Not really, no. I meant that I want Emacs to check every file to see if it needs decryption before opening it. Most of my files, whether *.org or *.md or *.txt or *.tex (which is pretty much all the types I have), are not encrypted, but for those that are, I want to continue using the "proper" extension and still have Emacs check before opening and, if they're not encrypted, do nothing else but open them. Commented Feb 28, 2024 at 21:42

1 Answer 1

0

You can do this but, in case it's not obvious, the requirement is that all files with matching filenames are encrypted.

So if you're really sure that's what you want, then see C-hv epa-file-name-regexp

(n.b. Applied too broadly, this could cause carnage -- you might inadvertently encrypt system-critical files, for instance. Don't do anything like this without very carefully considering all of the possible ramifications.)

4
  • – Thanks for the answer. I understand from what you're saying that a sort of global "check all .abc files" rule is possible which assumes all .abc files must be encrypted. I would like such a global rule but I want Emacs to decrypt encrypted .abc files and simply open the rest if no encryption exists. Commented Feb 28, 2024 at 21:44
  • You would need to write a custom file handler which implements that functionality, then, because the one that is used for .gpg files does not work for non-encrypted files (which you can trivially demonstrate by -- without using emacs -- giving an unencrypted file a *.gpg filename, and then trying to open it with emacs). Commented Feb 28, 2024 at 22:12
  • (The one that is used for .gpg files also assumes that you do want to encrypt all files with matching filenames whenever you save them.) Commented Feb 28, 2024 at 22:22
  • Thanks for the explanation. I work within an Obsidian-style 'vault' so I suppose the possibility of affecting system critical files is close to zero. That said, using the .gpg does not seem like a bad choice if my only alternative is to write a custom file handler. Commented Feb 29, 2024 at 1:04

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.