emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 4cb53c0528: Improve don't save bookmark context from encrypted fi


From: Michael Albinus
Subject: master 4cb53c0528: Improve don't save bookmark context from encrypted files
Date: Thu, 22 Sep 2022 07:14:58 -0400 (EDT)

branch: master
commit 4cb53c0528aad73ac001a5d0b4ae336b8ec65408
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Improve don't save bookmark context from encrypted files
    
    * 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                 | 30 ++++++++++++++++--------------
 lisp/auth-source-pass.el | 10 ++++++++++
 lisp/auth-source.el      | 15 +++++++++++++++
 lisp/bookmark.el         | 14 ++++++++++----
 lisp/epa-hook.el         |  4 ++++
 lisp/net/tramp-crypt.el  |  8 ++++++++
 6 files changed, 63 insertions(+), 18 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 398cc2598e..7a573b5e83 100644
--- 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
diff --git a/lisp/auth-source-pass.el b/lisp/auth-source-pass.el
index 86e0b48a79..0955e2ed07 100644
--- a/lisp/auth-source-pass.el
+++ b/lisp/auth-source-pass.el
@@ -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
 
diff --git a/lisp/auth-source.el b/lisp/auth-source.el
index c79e5b81f7..feefd391a8 100644
--- a/lisp/auth-source.el
+++ b/lisp/auth-source.el
@@ -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)
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index f150a24bbf..0384812d3f 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -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)))
diff --git a/lisp/epa-hook.el b/lisp/epa-hook.el
index 70c3030881..386bd73964 100644
--- a/lisp/epa-hook.el
+++ b/lisp/epa-hook.el
@@ -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"
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index d556c87606..16c4049a68 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]