From 0bcc35551eab2618f010f9a7578f6f7bfa92a3e0 Mon Sep 17 00:00:00 2001 From: Boruch Baum Date: Mon, 17 Aug 2020 18:24:41 -0400 Subject: [PATCH] Update session-default save directory upon use + Use the most recently seleted save directory as the default for the remainder of the session. + It turns out that this behavior had already been partially but incompletely implemented sometime in the past, within function w3m-read-file-name; however, that function wasn't being used universally (ie. w3m-save-buffer). + Function w3m-read-file-name is basically a wrapper for the emacs-native funcion read-file-name, but with the added confusion of differing its arg-names and re-ordering them, so I changed it to be consistent. --- ChangeLog | 16 ++++++++++++++++ w3m-save.el | 28 +++++++++++++++------------- w3m.el | 28 ++++++++++++++++------------ 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 581230362..66d194e2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2020-08-17 Boruch Baum + + * w3m-save.el (w3m-save-buffer-directory): Mark variable as deprecated + in favor of `w3m-default-save-directory'. + (w3m-save-buffer): Replace deprecated variable, and use function + `w3m-read-file-name' instead of `read-file-name'. This has the + consequence of updating a session's default save directory to the most + recent used save diretory. Update docstring. + + * w3m.el (w3m-read-file-name): Rename and re-order args to be + consistent with underlying emacs function `read-file-name', and update + docstring. + (w3m-download): Remove unnecessary `condition-case' + (w3m-download, w3m-goto-ftp-url): update args for new version of + `w3m-read-file-name' + 2020-08-16 Katsumi Yamaoka * .travis.yml (allow_failures): Temporarily add builds on emacs27 diff --git a/w3m-save.el b/w3m-save.el index 077cdfe89..fd65d30d0 100644 --- a/w3m-save.el +++ b/w3m-save.el @@ -33,7 +33,9 @@ (defcustom w3m-save-buffer-directory (expand-file-name "saved/" w3m-default-save-directory) - "Default directory for saved pages and their image files." + "DEPRECATED: Use `w3m-default-save-directory' instead! + +Default directory for saved pages and their image files." :group 'w3m :type 'directory) @@ -54,15 +56,15 @@ a prefix argument to function `w3m-save-buffer'." (defun w3m-save-buffer (name &optional no-images) "Save the current w3m buffer. -Save the current buffer as `w3m-save-buffer-directory'/NAME.html, -and optionally save the buffer's associated image files in -folder `w3m-save-buffer-directory'/NAME-files/. Use of -`w3m-save-buffer-directory' may be over-ridden by including a -folder path in NAME. Variable `w3m-save-buffer-html-only' -determines whether images will be saved by default, but that -setting may be toggled using the prefix argument (the -optional NO-IMAGES). The saved page will be added to the -history list, and be viewable using `w3m-next-page'." +Save the current buffer as `w3m-default-save-directory'/NAME.html, +and optionally save the buffer's associated image files in folder +`w3m-default-save-directory'/NAME-files/. The value of +`w3m-default-save-directory' may be changed for the current +session by including a folder path in NAME. Variable +`w3m-save-buffer-html-only' determines whether images will be +saved by default, but that setting may be toggled using the +prefix argument (the optional NO-IMAGES). The saved page will be +added to the history list, and be viewable using `w3m-next-page'." (interactive (if (and w3m-current-url (or (not (string-match "\\`[\C-@- ]*\\'\\|\\`about:\\|\\`file:" @@ -80,11 +82,11 @@ history list, and be viewable using `w3m-next-page'." (case-fold-search t)) (setq name (replace-regexp-in-string "[\C-@- \"*/:<>?\\|]+" "_" name)) (list - (read-file-name + (w3m-read-file-name (if (not w3m-save-buffer-html-only) "Save this page (with images) to: " "Save this page (html only) to: ") - (file-name-as-directory w3m-save-buffer-directory) + (file-name-as-directory w3m-default-save-directory) name nil (concat name ".html")) current-prefix-arg)) (error "No valid url for this page"))) @@ -110,7 +112,7 @@ history list, and be viewable using `w3m-next-page'." ((not (string-match "\\.html?\\'" name)) (setq name (concat name ".html")))) (unless (file-name-directory name) - (setq name (expand-file-name name w3m-save-buffer-directory))) + (setq name (expand-file-name name w3m-default-save-directory))) (setq subdir (concat (file-name-sans-extension name) "-files")) (cond ((and (not no-images) (file-exists-p name) (file-exists-p subdir)) (if (yes-or-no-p diff --git a/w3m.el b/w3m.el index 5b9c987c3..e296669c0 100644 --- a/w3m.el +++ b/w3m.el @@ -4805,20 +4805,27 @@ BUFFER is nil, all contents will be inserted in the current buffer." ;; dynamically-generated pages. (string-match "^\\(?:last-modified\\|etag\\):" head)))))))) -(defun w3m-read-file-name (&optional prompt dir default existing) +(defun w3m-read-file-name (&optional prompt dir default-filename mustmatch initial) + "Prompt the user for a file-path name, and returns that value. + +This is basically a wrapper for the emacs-native function + `read-file-name'. If PROMPT is NIL, use default string 'Save + to'. If DIR is NIL, use `w3m-default=dave-directory'. DEFAULT-FILENAME, + MUSTMATCH, and INITIAL are as documented for function + `read-file-name'." (unless prompt - (setq prompt (if (and default (not (string-equal default ""))) - (format "Save to (%s): " default) + (setq prompt (if (and initial (not (string-equal initial ""))) + (format "Save to (%s): " initial) "Save to: "))) (setq dir (file-name-as-directory (or dir w3m-default-save-directory))) (let ((default-directory dir) - (file (read-file-name prompt dir nil existing default))) + (file (read-file-name prompt dir default-filename mustmatch initial))) (if (not (file-directory-p file)) (setq w3m-default-save-directory (or (file-name-directory file) w3m-default-save-directory)) (setq w3m-default-save-directory file) - (if default - (setq file (expand-file-name default file)))) + (if initial + (setq file (expand-file-name initial file)))) (expand-file-name file))) ;;; Handling character sets: @@ -5829,10 +5836,7 @@ NO-CACHE is ignored (always download)." (if (string-match "\\`[^\n\t :]+:/+" url) (substring url (match-end 0)) url) - (condition-case nil - (eval (car (get 'w3m-default-save-directory 'standard-value)) - t) - (error w3m-default-save-directory)))) + w3m-default-save-directory)) file-name-history)) dir) (when (string-match "\\`[\t ]*\\'" basename) @@ -5842,7 +5846,7 @@ NO-CACHE is ignored (always download)." (while (not filename) (setq filename (w3m-read-file-name (format "Download %s to: " url) - w3m-default-save-directory basename) + w3m-default-save-directory nil nil basename) dir (directory-file-name (file-name-directory filename))) (cond ((file-exists-p filename) (if (file-directory-p filename) @@ -9421,7 +9425,7 @@ this function will prompt user for it." (dired-other-window ftp) (setq file (file-name-nondirectory ftp)) (unless filename - (setq filename (w3m-read-file-name nil nil file))) + (setq filename (w3m-read-file-name nil nil nil nil file))) (unless (file-writable-p (file-name-directory filename)) (error "Permission denied, %s" (file-name-directory filename))) (when (or (not (file-exists-p filename))