[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/pdf-tools f68899c 2/6: Sanitize buffer name for use as tem
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/pdf-tools f68899c 2/6: Sanitize buffer name for use as temp file prefix |
Date: |
Fri, 3 Dec 2021 10:58:20 -0500 (EST) |
branch: elpa/pdf-tools
commit f68899cf0646255ca763f1144f7a9520e7cd46db
Author: Roshan Shariff <roshan.shariff@gmail.com>
Commit: Vedang Manerikar <ved.manerikar@gmail.com>
Sanitize buffer name for use as temp file prefix
Prefixes for temporary files are derived from either the file name
associated with the pdf-view buffer, or the buffer name if it is not
visiting a file. If the buffer name contains '/' characters, then it is
not a valid file name.
Clean up non-alphanumeric characters in the buffer name before using
it as a temp file prefix.
---
lisp/pdf-util.el | 23 +++++++++++++----------
lisp/pdf-view.el | 7 +------
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/lisp/pdf-util.el b/lisp/pdf-util.el
index c57f6ec..23945c8 100644
--- a/lisp/pdf-util.el
+++ b/lisp/pdf-util.el
@@ -558,12 +558,7 @@ killed."
(let ((temporary-file-directory
pdf-util--base-directory))
(setq pdf-util--dedicated-directory
- (make-temp-file (convert-standard-filename
- (concat (if buffer-file-name
- (file-name-nondirectory
- buffer-file-name)
- (buffer-name))
- "-"))
+ (make-temp-file (convert-standard-filename
(pdf-util-temp-prefix))
t))
(add-hook 'kill-buffer-hook 'pdf-util-delete-dedicated-directory
nil t)))
@@ -577,13 +572,21 @@ killed."
"Expand filename against current buffer's dedicated directory."
(expand-file-name name (pdf-util-dedicated-directory)))
-(defun pdf-util-make-temp-file (prefix &optional dir-flag suffix)
+(defun pdf-util-temp-prefix ()
+ "Create a temp-file prefix for the current buffer"
+ (concat (if buffer-file-name
+ (file-name-nondirectory buffer-file-name)
+ (replace-regexp-in-string "[^[:alnum:]]+" "-" (buffer-name)))
+ "-"))
+
+(defun pdf-util-make-temp-file (&optional prefix dir-flag suffix)
"Create a temporary file in current buffer's dedicated directory.
See `make-temp-file' for the arguments."
- (let ((temporary-file-directory
- (pdf-util-dedicated-directory)))
- (make-temp-file (convert-standard-filename prefix) dir-flag suffix)))
+ (let ((temporary-file-directory (pdf-util-dedicated-directory)))
+ (make-temp-file (convert-standard-filename
+ (or prefix (pdf-util-temp-prefix)))
+ dir-flag suffix)))
;; * ================================================================== *
diff --git a/lisp/pdf-view.el b/lisp/pdf-view.el
index 41d07b4..532b524 100644
--- a/lisp/pdf-view.el
+++ b/lisp/pdf-view.el
@@ -319,12 +319,7 @@ PNG images in Emacs buffers."
(not (and buffer-file-name
(file-readable-p buffer-file-name)))))
(pdf-tools-pdf-buffer-p))
- (let ((tempfile (pdf-util-make-temp-file
- (concat (if buffer-file-name
- (file-name-nondirectory
- buffer-file-name)
- (buffer-name))
- "-"))))
+ (let ((tempfile (pdf-util-make-temp-file)))
(write-region nil nil tempfile nil 'no-message)
(setq-local pdf-view--buffer-file-name tempfile)))
;; Decryption needs to be done before any other function calls into
- [nongnu] elpa/pdf-tools updated (5f77dae -> a8847b7), ELPA Syncer, 2021/12/03
- [nongnu] elpa/pdf-tools e8efff3 1/6: Update Appveyor configs, ELPA Syncer, 2021/12/03
- [nongnu] elpa/pdf-tools d976e47 5/6: Use theme background for tooltip arrow, ELPA Syncer, 2021/12/03
- [nongnu] elpa/pdf-tools 2a07329 4/6: fix: use POSIX standard builtin to search PATH, ELPA Syncer, 2021/12/03
- [nongnu] elpa/pdf-tools 8a7804a 3/6: fix: handle alternative paths to sh, ELPA Syncer, 2021/12/03
- [nongnu] elpa/pdf-tools f68899c 2/6: Sanitize buffer name for use as temp file prefix,
ELPA Syncer <=
- [nongnu] elpa/pdf-tools a8847b7 6/6: Adapt Emacs' easy-menu change #50, ELPA Syncer, 2021/12/03