2011-04-04 15:16:23 +09:00
|
|
|
;;; epa-hook.el --- preloaded code to enable epa-file.el -*- lexical-binding: t -*-
|
2020-02-18 16:42:20 +01:00
|
|
|
|
2025-01-01 07:39:17 +00:00
|
|
|
;; Copyright (C) 2006-2025 Free Software Foundation, Inc.
|
2008-05-01 07:17:08 +00:00
|
|
|
|
|
|
|
;; Author: Daiki Ueno <ueno@unixuser.org>
|
|
|
|
;; Keywords: PGP, GnuPG
|
2010-08-29 12:17:13 -04:00
|
|
|
;; Package: emacs
|
2008-05-01 07:17:08 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2008-05-01 07:17:08 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
2008-05-01 07:17:08 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2008-05-01 07:17:08 +00:00
|
|
|
|
2021-09-22 20:26:40 +02:00
|
|
|
;;; Commentary:
|
|
|
|
|
2008-05-01 07:17:08 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(defgroup epa-file nil
|
2021-09-14 08:43:18 +02:00
|
|
|
"The EasyPG Assistant hooks for transparent file encryption."
|
2008-05-01 07:17:08 +00:00
|
|
|
:version "23.1"
|
|
|
|
:group 'epa)
|
|
|
|
|
|
|
|
(defun epa-file--file-name-regexp-set (variable value)
|
|
|
|
(set-default variable value)
|
|
|
|
(if (fboundp 'epa-file-name-regexp-update)
|
|
|
|
(epa-file-name-regexp-update)))
|
|
|
|
|
Delete remaining calls to purecopy
* lisp/button.el (default-button):
* lisp/calendar/holidays.el (holiday-solar-holidays)
(holiday-bahai-holidays, holiday-islamic-holidays)
(holiday-christian-holidays, holiday-hebrew-holidays)
(holiday-oriental-holidays, holiday-general-holidays):
* lisp/comint.el (comint-file-name-prefix):
* lisp/composite.el (unicode-category-table):
* lisp/cus-face.el (custom-declare-face):
* lisp/custom.el (custom-add-load, custom-add-package-version)
(custom-add-version, custom-add-link, custom-declare-group)
(custom-declare-variable):
* lisp/dired.el (dired-listing-switches):
* lisp/epa-hook.el (epa-file-name-regexp):
* lisp/faces.el (x-font-regexp, x-font-regexp-head)
(x-font-regexp-slant, x-font-regexp-weight, )
(set-face-attribute, set-face-documentation, face-x-resources)
(face-font-registry-alternatives, face-font-family-alternatives)
(term-file-prefix):
* lisp/find-file.el (ff-special-constructs):
* lisp/format.el (format-alist):
* lisp/help.el (help-for-help):
* lisp/image-file.el (image-file-name-extensions):
* lisp/info.el:
* lisp/isearch.el (isearch-help-for-help-internal)
(search-whitespace-regexp):
* lisp/jka-cmpr-hook.el (jka-compr-load-suffixes)
(jka-compr-mode-alist-additions)
(jka-compr-compression-info-list, jka-compr-build-file-regexp):
* lisp/language/ethiopic.el (font-ccl-encoder-alist):
* lisp/language/korea-util.el (default-korean-keyboard):
* lisp/language/tibetan.el (tibetan-precomposition-rule-regexp)
(tibetan-precomposed-regexp):
* lisp/locate.el (locate-ls-subdir-switches):
* lisp/lpr.el (lpr-command):
* lisp/mail/rmail.el (rmail-secondary-file-regexp)
(rmail-secondary-file-directory, rmail-highlighted-headers)
(rmail-ignored-headers, rmail-spool-directory, rmail-file-name):
* lisp/mail/sendmail.el (mail-default-directory)
(mail-signature-file, mail-citation-prefix-regexp)
(mail-personal-alias-file, mail-header-separator):
* lisp/menu-bar.el (yank-menu):
* lisp/net/eudc.el (eudc-tools-menu):
* lisp/newcomment.el (comment-padding, comment-end):
* lisp/obsolete/autoload.el (autoload-generate-file-autoloads):
* lisp/progmodes/hideshow.el (hs-special-modes-alist):
* lisp/ps-print.el (ps-page-dimensions-database):
* lisp/rfn-eshadow.el (file-name-shadow-tty-properties):
* lisp/shell.el (shell-dumb-shell-regexp):
* lisp/simple.el (overwrite-mode-binary, overwrite-mode-textual)
(mark-inactive, shell-command-switch)
(next-error-overlay-arrow-position):
* lisp/subr.el (package--builtin-versions, eval-after-load):
* lisp/tab-bar.el ([tab-bar]):
* lisp/term/pgtk-win.el (x-gtk-stock-map):
* lisp/term/x-win.el (x-gtk-stock-map):
* lisp/tool-bar.el ([tool-bar]):
* lisp/widget.el (define-widget): Remove calls to purecopy.
2024-12-09 21:26:25 +01:00
|
|
|
(defcustom epa-file-name-regexp "\\.gpg\\(~\\|\\.~[0-9]+~\\)?\\'"
|
2008-05-01 07:17:08 +00:00
|
|
|
"Regexp which matches filenames to be encrypted with GnuPG.
|
|
|
|
|
2020-02-18 16:59:00 +01:00
|
|
|
If you set this outside Custom while epa-file is already enabled,
|
|
|
|
you have to call `epa-file-name-regexp-update' after setting it
|
|
|
|
to properly update `file-name-handler-alist'. Setting this
|
|
|
|
through Custom does that automatically."
|
2008-05-01 07:17:08 +00:00
|
|
|
:type 'regexp
|
|
|
|
:group 'epa-file
|
|
|
|
:set 'epa-file--file-name-regexp-set)
|
|
|
|
|
|
|
|
(defcustom epa-file-inhibit-auto-save t
|
|
|
|
"If non-nil, disable auto-saving when opening an encrypted file."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'epa-file)
|
|
|
|
|
|
|
|
(defvar epa-file-encrypt-to nil
|
Fix minor mode docstrings for the new meaning of a nil ARG.
* abbrev.el (abbrev-mode):
* allout.el (allout-mode):
* autoinsert.el (auto-insert-mode):
* autoarg.el (autoarg-mode, autoarg-kp-mode):
* autorevert.el (auto-revert-mode, auto-revert-tail-mode)
(global-auto-revert-mode):
* battery.el (display-battery-mode):
* composite.el (global-auto-composition-mode)
(auto-composition-mode):
* delsel.el (delete-selection-mode):
* desktop.el (desktop-save-mode):
* dired-x.el (dired-omit-mode):
* dirtrack.el (dirtrack-mode):
* doc-view.el (doc-view-minor-mode):
* double.el (double-mode):
* electric.el (electric-indent-mode, electric-pair-mode):
* emacs-lock.el (emacs-lock-mode):
* epa-hook.el (auto-encryption-mode):
* follow.el (follow-mode):
* font-core.el (font-lock-mode):
* frame.el (auto-raise-mode, auto-lower-mode, blink-cursor-mode):
* help.el (temp-buffer-resize-mode):
* hilit-chg.el (highlight-changes-mode)
(highlight-changes-visible-mode):
* hi-lock.el (hi-lock-mode):
* hl-line.el (hl-line-mode, global-hl-line-mode):
* icomplete.el (icomplete-mode):
* ido.el (ido-everywhere):
* image-file.el (auto-image-file-mode):
* image-mode.el (image-minor-mode):
* iswitchb.el (iswitchb-mode):
* jka-cmpr-hook.el (auto-compression-mode):
* linum.el (linum-mode):
* longlines.el (longlines-mode):
* master.el (master-mode):
* mb-depth.el (minibuffer-depth-indicate-mode):
* menu-bar.el (menu-bar-mode):
* minibuf-eldef.el (minibuffer-electric-default-mode):
* mouse-sel.el (mouse-sel-mode):
* msb.el (msb-mode):
* mwheel.el (mouse-wheel-mode):
* outline.el (outline-minor-mode):
* paren.el (show-paren-mode):
* recentf.el (recentf-mode):
* reveal.el (reveal-mode, global-reveal-mode):
* rfn-eshadow.el (file-name-shadow-mode):
* ruler-mode.el (ruler-mode):
* savehist.el (savehist-mode):
* scroll-all.el (scroll-all-mode):
* scroll-bar.el (scroll-bar-mode):
* server.el (server-mode):
* shell.el (shell-dirtrack-mode):
* simple.el (auto-fill-mode, transient-mark-mode)
(visual-line-mode, overwrite-mode, binary-overwrite-mode)
(line-number-mode, column-number-mode, size-indication-mode)
(auto-save-mode, normal-erase-is-backspace-mode, visible-mode):
* strokes.el (strokes-mode):
* time.el (display-time-mode):
* t-mouse.el (gpm-mouse-mode):
* tool-bar.el (tool-bar-mode):
* tooltip.el (tooltip-mode):
* type-break.el (type-break-mode-line-message-mode)
(type-break-query-mode):
* view.el (view-mode):
* whitespace.el (whitespace-mode, whitespace-newline-mode)
(global-whitespace-mode, global-whitespace-newline-mode):
* xt-mouse.el (xterm-mouse-mode): Doc fix.
* emacs-lisp/easy-mmode.el (define-globalized-minor-mode): Fix
autogenerated docstring.
2011-10-19 08:54:24 -04:00
|
|
|
"Recipient(s) used for encrypting files.
|
2008-05-01 07:17:08 +00:00
|
|
|
May either be a string or a list of strings.")
|
|
|
|
|
|
|
|
(put 'epa-file-encrypt-to 'safe-local-variable
|
Remove redundant #' before lambda
* admin/unidata/unidata-gen.el (unidata-gen-table)
(unidata-gen-table-symbol, unidata-gen-table-integer)
(unidata-gen-table-numeric, unidata-gen-table-word-list)
(unidata-describe-decomposition):
* lisp/apropos.el (apropos-user-option):
* lisp/bookmark.el (bookmark-bmenu-search):
* lisp/composite.el (unicode-category-table):
* lisp/elec-pair.el (electric-pair--balance-info):
* lisp/electric.el (electric-quote-chars):
* lisp/emulation/cua-base.el (cua-rectangle-mark-key):
* lisp/epa-hook.el (epa-file-encrypt-to):
* lisp/faces.el (face-font-selection-order)
(face-font-family-alternatives, face-font-registry-alternatives)
(face-valid-attribute-values, tty-run-terminal-initialization):
* lisp/files.el (recover-file, file-expand-wildcards):
* lisp/frame.el (frames-on-display-list):
* lisp/help-at-pt.el (help-at-pt-display-when-idle):
* lisp/help-fns.el (help-fns--face-attributes):
* lisp/ido.el (ido-mode, ido-unc-hosts):
* lisp/isearch.el (isearch-highlight-regexp)
(isearch-highlight-lines-matching-regexp):
* lisp/language/indian.el (script-regexp-alist):
* lisp/language/lao.el:
* lisp/leim/quail/ipa.el (ipa-x-sampa-prepend-to-keymap-entry):
* lisp/mh-e/mh-folder.el (mh-process-commands):
* lisp/mh-e/mh-mime.el (mh-display-with-external-viewer):
* lisp/ps-mule.el (ps-mule-end-job):
* lisp/ps-print.el (ps-color-scale, ps-background-pages)
(ps-background-text, ps-background-image, ps-background)
(ps-begin-job, ps-print-translation-table):
* lisp/recentf.el (recentf-sort-ascending)
(recentf-sort-descending, recentf-sort-basenames-ascending)
(recentf-sort-basenames-descending)
(recentf-sort-directories-ascending)
(recentf-sort-directories-descending):
* lisp/replace.el (occur-engine-add-prefix):
* lisp/select.el (xselect--encode-string):
* lisp/server.el (server-use-tcp):
* lisp/ses.el (ses-sort-column):
* lisp/sort.el (sort-columns):
* lisp/term/ns-win.el (window-system-initialization):
* lisp/tree-widget.el (tree-widget-image-formats):
* lisp/whitespace.el (whitespace-report-region): Remove redundant #'
before lambda.
2021-10-21 23:35:07 +02:00
|
|
|
(lambda (val)
|
|
|
|
(or (stringp val)
|
|
|
|
(and (listp val)
|
|
|
|
(catch 'safe
|
|
|
|
(mapc (lambda (elt)
|
|
|
|
(unless (stringp elt)
|
|
|
|
(throw 'safe nil)))
|
|
|
|
val)
|
|
|
|
t)))))
|
2008-05-01 07:17:08 +00:00
|
|
|
|
|
|
|
(put 'epa-file-encrypt-to 'permanent-local t)
|
|
|
|
|
|
|
|
(defvar epa-file-handler
|
|
|
|
(cons epa-file-name-regexp 'epa-file-handler))
|
|
|
|
|
|
|
|
(defvar epa-file-auto-mode-alist-entry
|
|
|
|
(list epa-file-name-regexp nil 'epa-file))
|
|
|
|
|
|
|
|
(defun epa-file-name-regexp-update ()
|
2020-02-18 16:59:00 +01:00
|
|
|
"Update `file-name-handler-alist' after configuring outside Custom.
|
|
|
|
After setting `epa-file-name-regexp-update' outside the Custom
|
|
|
|
interface, update `file-name-handler-alist'."
|
2008-05-01 07:17:08 +00:00
|
|
|
(interactive)
|
|
|
|
(unless (equal (car epa-file-handler) epa-file-name-regexp)
|
|
|
|
(setcar epa-file-handler epa-file-name-regexp)))
|
|
|
|
|
|
|
|
(defun epa-file-find-file-hook ()
|
|
|
|
(if (and buffer-file-name
|
|
|
|
(string-match epa-file-name-regexp buffer-file-name)
|
|
|
|
epa-file-inhibit-auto-save)
|
2008-12-10 01:35:39 +00:00
|
|
|
(auto-save-mode 0)))
|
2008-05-01 07:17:08 +00:00
|
|
|
|
2022-09-19 09:42:28 +02:00
|
|
|
(defun epa-file-name-p (file)
|
|
|
|
"Say whether FILE is handled by `epa-file'."
|
|
|
|
(and auto-encryption-mode (string-match-p epa-file-name-regexp file)))
|
|
|
|
|
2022-09-22 13:14:46 +02:00
|
|
|
(with-eval-after-load 'bookmark
|
|
|
|
(add-hook 'bookmark-inhibit-context-functions
|
|
|
|
#'epa-file-name-p))
|
|
|
|
|
2008-05-01 07:17:08 +00:00
|
|
|
(define-minor-mode auto-encryption-mode
|
2018-07-01 23:34:53 -04:00
|
|
|
"Toggle automatic file encryption/decryption (Auto Encryption mode)."
|
2008-05-01 07:17:08 +00:00
|
|
|
:global t :init-value t :group 'epa-file :version "23.1"
|
2009-09-13 00:52:55 +00:00
|
|
|
;; We'd like to use custom-initialize-set here so the setup is done
|
|
|
|
;; before dumping, but at the point where the defcustom is evaluated,
|
|
|
|
;; the corresponding function isn't defined yet, so
|
|
|
|
;; custom-initialize-set signals an error.
|
|
|
|
:initialize 'custom-initialize-delay
|
2008-05-01 07:17:08 +00:00
|
|
|
(setq file-name-handler-alist
|
|
|
|
(delq epa-file-handler file-name-handler-alist))
|
2018-03-06 20:16:52 -05:00
|
|
|
(remove-hook 'find-file-hook 'epa-file-find-file-hook)
|
2008-05-01 07:17:08 +00:00
|
|
|
(setq auto-mode-alist (delq epa-file-auto-mode-alist-entry
|
|
|
|
auto-mode-alist))
|
|
|
|
(when auto-encryption-mode
|
|
|
|
(setq file-name-handler-alist
|
|
|
|
(cons epa-file-handler file-name-handler-alist))
|
|
|
|
(add-hook 'find-file-hook 'epa-file-find-file-hook)
|
|
|
|
(setq auto-mode-alist (cons epa-file-auto-mode-alist-entry
|
|
|
|
auto-mode-alist))))
|
|
|
|
|
|
|
|
(put 'epa-file-handler 'safe-magic t)
|
|
|
|
(put 'epa-file-handler 'operations '(write-region insert-file-contents))
|
|
|
|
|
2008-05-08 11:24:15 +00:00
|
|
|
(provide 'epa-hook)
|
2008-05-01 07:17:08 +00:00
|
|
|
|
2008-05-08 11:53:29 +00:00
|
|
|
;;; epa-hook.el ends here
|