]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve don't save bookmark context from encrypted files
authorMichael Albinus <michael.albinus@gmx.de>
Thu, 22 Sep 2022 11:14:46 +0000 (13:14 +0200)
committerMichael Albinus <michael.albinus@gmx.de>
Thu, 22 Sep 2022 11:14:46 +0000 (13:14 +0200)
* etc/NEWS: Mention 'bookmark-inhibit-context-functions'.
Fix typos.

* lisp/bookmark.el (bookmark-inhibit-context-functions): New defcustom.
(bookmark-make-record): Use it.

* lisp/auth-source-pass.el (auth-source-pass-file-name-p):
* lisp/auth-source.el (auth-source-file-name-p): New defuns.  Add
them to `bookmark-inhibit-context-functions'.

* lisp/epa-hook.el (epa-file-name-p):
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-p): Add them to
`bookmark-inhibit-context-functions'.

etc/NEWS
lisp/auth-source-pass.el
lisp/auth-source.el
lisp/bookmark.el
lisp/epa-hook.el
lisp/net/tramp-crypt.el

index 398cc2598e2c785dedc1d53fc28381a56ee7593c..7a573b5e831385c7522a86dcde29bf1701997aeb 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -183,7 +183,10 @@ of 'user-emacs-directory'.
 +++
 *** Bookmarks no longer include context for encrypted files.
 If you're visiting an encrypted file, setting a bookmark no longer
-includes excerpts from that buffer in the bookmarks file.
+includes excerpts from that buffer in the bookmarks file.  This is
+implemented by the new hook 'bookmark-inhibit-context-functions',
+where packages can register a function which returns non-nil for file
+names to be excluded from adding such excerpts.
 
 ---
 *** 'show-paren-mode' is now disabled in 'special-mode' buffers.
@@ -391,8 +394,8 @@ are also obsolete.
 
 ---
 ** The linum.el library is now obsolete.
-We recommend using either the built-in `display-line-numbers-mode', or
-the `nlinum' package from GNU ELPA instead.  The former has better
+We recommend using either the built-in 'display-line-numbers-mode', or
+the 'nlinum' package from GNU ELPA instead.  The former has better
 performance, but the latter is closer to a drop-in replacement.
 
 ---
@@ -1529,7 +1532,7 @@ uses the 'key-parse' syntax.  It replaces the old 'kmacro-lambda-form'
 (which is now declared obsolete).
 
 ---
-** 'savehist.el' can now truncate variables that are too long.
+** savehist.el can now truncate variables that are too long.
 An element of 'savehist-additional-variables' can now be of the form
 '(VARIABLE . MAX-ELTS)', which means to truncate the VARIABLE's value to
 at most MAX-ELTS elements (if the value is a list) before saving the
@@ -2155,7 +2158,7 @@ nil to disable this confirmation completely.
 *** 'image-dired-thumb-size' increased to 128.
 
 ---
-*** 'image-dired-thumb-(height|width)' are now obsolete.
+*** 'image-dired-thumb-{height,width}' are now obsolete.
 Customize 'image-dired-thumb-size' instead, which will set both the
 height and width.
 
@@ -2469,9 +2472,9 @@ Enabling this minor mode turns on hiding header material, like
 'elide-head' does; disabling it shows the header.  The commands
 'elide-head' and 'elide-head-show' are now obsolete.
 
-*** New package 'osc'.
+*** New package osc.el.
 Support for OSC ("Operating System Command") escape sequences has been
-extracted from 'comint.el' in order to provide interpretation of OSC
+extracted from comint.el in order to provide interpretation of OSC
 sequences in compilation buffers.
 
 Adding the new function 'osc-compilation-filter' to
@@ -2482,7 +2485,6 @@ filtered out.
 The list of handlers (already covering OSC 7 and 8) has been extended
 with a handler for OSC 2, the command to set a window title.
 
-
 +++
 *** New user option 'project-vc-include-untracked'.
 If non-nil, files untracked by a VCS are considered to be part of
@@ -2612,12 +2614,12 @@ in-memory format is now by using ':data-width' and ':data-height'.
 ** "loaddefs.el" generation has been reimplemented.
 The various "loaddefs.el" files in the Emacs tree (which contain
 information about autoloads, built-in packages and package prefixes)
-used to be generated by functions in "autoloads.el".  These are now
-generated by "loaddefs-gen.el" instead.  This leads to functionally
-equivalent loaddef files, but they do not use exactly the same syntax,
-so using 'M-x update-file-autoloads' no longer works.  (This didn't
-work well in most files in the past, either, but it will now signal an
-error in any file.)
+used to be generated by functions in autoloads.el.  These are now
+generated by loaddefs-gen.el instead.  This leads to functionally
+equivalent "loaddef.el" files, but they do not use exactly the same
+syntax, so using 'M-x update-file-autoloads' no longer works.  (This
+didn't work well in most files in the past, either, but it will now
+signal an error in any file.)
 
 In addition, files are scanned in a slightly different way.
 Previously ';;;###' specs inside a top-level form (i.e., something
index 86e0b48a79da53b67c93cabd04a894aa06485bfe..0955e2ed07e59812102c3221a02a184f0fa21cee 100644 (file)
@@ -319,6 +319,16 @@ then NAME & USER, then NAME & PORT, then just NAME."
     (list
      (format "%s" name)))))
 
+(defun auth-source-pass-file-name-p (file)
+  "Say whether FILE is used by `auth-source-pass'."
+  (and (stringp file) (stringp auth-source-pass-filename)
+       (string-equal
+        (expand-file-name file) (expand-file-name auth-source-pass-filename))))
+
+(with-eval-after-load 'bookmark
+  (add-hook 'bookmark-inhibit-context-functions
+           #'auth-source-pass-file-name-p))
+
 (provide 'auth-source-pass)
 ;;; auth-source-pass.el ends here
 
index c79e5b81f762f9f35dfdd4b79912cbddca14d2b8..feefd391a877cbb146a5b815b0042674048e767e 100644 (file)
@@ -522,6 +522,21 @@ parameters."
 
 ;; (mapcar #'auth-source-backend-parse auth-sources)
 
+(defun auth-source-file-name-p (file)
+  "Say whether FILE is used by `auth-sources'."
+  (let* ((backends (mapcar #'auth-source-backend-parse auth-sources))
+         (files
+          (mapcar (lambda (x)
+                    (when (member (slot-value x 'type) '(json netrc plstore))
+                      (slot-value x 'source)))
+                  backends)))
+    (member (expand-file-name file)
+            (mapcar #'expand-file-name (remq nil files)))))
+
+(with-eval-after-load 'bookmark
+  (add-hook 'bookmark-inhibit-context-functions
+           #'auth-source-file-name-p))
+
 (cl-defun auth-source-search (&rest spec
                               &key max require create delete
                               &allow-other-keys)
index f150a24bbfb1a5c62b1003fe0255b9a14d51c9eb..0384812d3fd11e4cc6ba4e7c38e5a212ef9b65c0 100644 (file)
@@ -592,6 +592,14 @@ NAME is a suggested name for the constructed bookmark.  It can be nil
 in which case a default heuristic will be used.  The function can also
 equivalently just return ALIST without NAME.")
 
+(defcustom bookmark-inhibit-context-functions nil
+  "List of functions to call before making a bookmark record.
+The functions take `buffer-file-name' as argument.  If any of
+these functions returns non-nil, the bookmark does not record
+context strings from the current buffer."
+  :type 'hook
+  :version "29.1")
+
 (defun bookmark-make-record ()
   "Return a new bookmark record (NAME . ALIST) for the current location."
   (let* ((bookmark-search-size
@@ -599,10 +607,8 @@ equivalently just return ALIST without NAME.")
           ;; don't include any context in the bookmark file, because
           ;; that would leak (possibly secret) data.
           (if (and buffer-file-name
-                   (or (and (fboundp 'epa-file-name-p)
-                            (epa-file-name-p buffer-file-name))
-                       (and (fboundp 'tramp-crypt-file-name-p)
-                            (tramp-crypt-file-name-p buffer-file-name))))
+                   (not (run-hook-with-args-until-success
+                         'bookmark-inhibit-context-functions buffer-file-name)))
               0
             bookmark-search-size))
          (record (funcall bookmark-make-record-function)))
index 70c303088197017c35c2ceb1e020b7737ec4d224..386bd7396405deab028ee27a713ad41e025e1315 100644 (file)
@@ -92,6 +92,10 @@ interface, update `file-name-handler-alist'."
   "Say whether FILE is handled by `epa-file'."
   (and auto-encryption-mode (string-match-p epa-file-name-regexp file)))
 
+(with-eval-after-load 'bookmark
+  (add-hook 'bookmark-inhibit-context-functions
+           #'epa-file-name-p))
+
 (define-minor-mode auto-encryption-mode
   "Toggle automatic file encryption/decryption (Auto Encryption mode)."
   :global t :init-value t :group 'epa-file :version "23.1"
index d556c876066b4044ee884b521424bb521b856811..16c4049a687e178a1066d76da701bc9c54732c0b 100644 (file)
@@ -852,6 +852,14 @@ WILDCARD is not supported."
     (tramp-compat-funcall
      'unlock-file (tramp-crypt-encrypt-file-name filename))))
 
+(with-eval-after-load 'bookmark
+  (add-hook 'bookmark-inhibit-context-functions
+           #'tramp-crypt-file-name-p)
+  (add-hook 'tramp-crypt-unload-hook
+           (lambda ()
+             (remove-hook 'bookmark-inhibit-context-functions
+                          #'tramp-crypt-file-name-p))))
+
 (add-hook 'tramp-unload-hook
          (lambda ()
            (unload-feature 'tramp-crypt 'force)))