From: Eshel Yaron Date: Wed, 9 Apr 2025 14:09:40 +0000 (+0200) Subject: recentf.el: Clean up. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=7c5c9996fc7869ea0acf1bbfbaa822434820a3ab;p=emacs.git recentf.el: Clean up. --- diff --git a/lisp/recentf.el b/lisp/recentf.el index 339ba13a3ce..f00d3ed956f 100644 --- a/lisp/recentf.el +++ b/lisp/recentf.el @@ -290,19 +290,6 @@ cleanup the list." ;; Unavailable until recentf has been loaded. (recentf-auto-cleanup)))) -(defcustom recentf-initialize-file-name-history t - "Non-nil means to initialize `file-name-history' with the recent list. -If `file-name-history' is not empty, do nothing." - :group 'recentf - :type 'boolean) - -(defcustom recentf-load-hook nil - "Normal hook run at end of loading the `recentf' package." - :group 'recentf - :type 'hook) -(make-obsolete-variable 'recentf-load-hook - "use `with-eval-after-load' instead." "28.1") - (defcustom recentf-filename-handlers '(abbreviate-file-name) "Functions to post process recent file names. They are successively passed a file name to transform it." @@ -323,13 +310,6 @@ used as shortcuts to open the Nth file." :group 'recentf :type 'boolean) -(defcustom recentf-show-messages t - "Whether to show verbose messages about low-level recentf actions. -nil means to not show messages related to the recentf machinery. -t means show messages that were printed by default on Emacs <= 31.1." - :group 'recentf - :type 'boolean - :version "31.1") ;;; Utilities ;; @@ -360,21 +340,6 @@ Ignore case if `recentf-case-fold-search' is non-nil." (setq list (cdr list))) list) -(defun recentf-dump-variable (variable &optional limit) - "Insert a \"(setq VARIABLE value)\" in the current buffer. -When the value of VARIABLE is a list, optional argument LIMIT -specifies a maximum number of elements to insert. By default insert -the full list." - (let ((value (symbol-value variable))) - (if (atom value) - (insert (format "\n(setq %S '%S)\n" variable value)) - (when (and (integerp limit) (> limit 0)) - (setq value (seq-take value limit))) - (insert (format "\n(setq %S\n '(" variable)) - (dolist (e value) - (insert (format "\n %S" e))) - (insert "\n ))\n")))) - (defvar recentf-auto-cleanup-timer nil "Timer used to automatically cleanup the recent list. See also the option `recentf-auto-cleanup'.") @@ -1332,38 +1297,17 @@ Optional argument N must be a valid digit number. It defaults to 1. ";;; Automatically generated by `recentf' on %s. -*- mode: lisp-data -*-\n" "Header to be written into the `recentf-save-file'.") -(defconst recentf-save-file-coding-system - (if (coding-system-p 'utf-8-emacs) - 'utf-8-emacs - 'emacs-mule) - "Coding system of the file `recentf-save-file'.") - (defun recentf-save-list () "Save the recent list. Write data into the file specified by `recentf-save-file'." (interactive) - (condition-case error - (with-temp-buffer - (erase-buffer) - (set-buffer-file-coding-system recentf-save-file-coding-system) - (insert (format-message recentf-save-file-header - (current-time-string))) - (recentf-dump-variable 'recentf-list recentf-max-saved-items) - (recentf-dump-variable 'recentf-filter-changer-current) - (insert "\n \n;; Local Variables:\n" - (format ";; coding: %s\n" recentf-save-file-coding-system) - ";; End:\n") - (write-region (point-min) - (point-max) - (expand-file-name recentf-save-file) nil - (unless (or (called-interactively-p 'interactive) - recentf-show-messages) - 'quiet)) - (when recentf-save-file-modes - (set-file-modes recentf-save-file recentf-save-file-modes)) - nil) - (error - (warn "recentf mode: %s" (error-message-string error))))) + (with-temp-buffer + (insert (format-message recentf-save-file-header (current-time-string))) + (prin1 (take recentf-max-saved-items recentf-list) (current-buffer)) + (write-region + (point-min) (point-max) (expand-file-name recentf-save-file) nil 'quiet) + (when recentf-save-file-modes + (set-file-modes recentf-save-file recentf-save-file-modes)))) (defun recentf-load-list () "Load a previously saved recent list. @@ -1375,17 +1319,15 @@ empty `file-name-history' with the recent list." ;; We do not want Tramp asking for passwords. (non-essential t)) (when (file-readable-p file) - (load-file file) - (and recentf-initialize-file-name-history - (not file-name-history) - (setq file-name-history (mapcar #'abbreviate-file-name - recentf-list)))))) + (setq recentf-list (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (read (current-buffer))))))) (defun recentf-cleanup () "Cleanup the recent list. That is, remove duplicates, non-kept, and excluded files." (interactive) - (message "Cleaning up the recentf list...") (let ((n 0) (ht (make-hash-table :size recentf-max-saved-items @@ -1400,10 +1342,9 @@ That is, remove duplicates, non-kept, and excluded files." (progn (push f newlist) (puthash key t ht)) - (setq n (1+ n)) - (message "File %s removed from the recentf list" f))) - (message "Cleaning up the recentf list...done (%d removed)" n) + (setq n (1+ n)))) (setq recentf-list (nreverse newlist)))) + ;;; The minor mode ;; @@ -1451,17 +1392,5 @@ buffers you switch to a lot, you can say something like the following: ;; continue standard unloading nil) -;; Obsolete. - -(define-obsolete-function-alias 'recentf-trunc-list #'seq-take "28.1") - -(defun recentf-elements (n) - "Return a list of the first N elements of the recent list." - (declare (obsolete "use `(seq-take recentf-list n)'." "29.1")) - (seq-take recentf-list n)) - (provide 'recentf) - -(run-hooks 'recentf-load-hook) - ;;; recentf.el ends here