harbour-sextant/lisp/local-projects/sextant/files/files.lisp
Renaud Casenave-Péré e6b27769fa WIP Backup
2025-10-09 09:25:45 +02:00

40 lines
2.1 KiB
Common Lisp

(uiop:define-package :sextant/files/files
(:use :cl :sextant/files/paths))
(defun load-recentf (filename maxsize)
(let ((recentf-pathname (cache-filepath filename)))
(when (probe-file recentf-pathname)
(subseq (uiop:safe-read-file-form recentf-pathname :package :sextant/files/recentf) 0 maxsize))))
(defun save-recentf (filename recentf-lst)
(let ((recentf-pathname (cache-filepath filename)))
(with-open-file (stream (ensure-directories-exist recentf-pathname)
:direction :output :if-exists :supersede)
(prin1 recentf-lst stream))))
(defun push-to-recentf (recentf-lst pathname agenda-files maxsize)
(when (notany (lambda (files-lst)
(uiop:subpathp pathname (truename (parse-namestring (car files-lst)))))
agenda-files)
(subseq (remove-duplicates (push pathname recentf-lst)
:from-end t
:test #'uiop:pathname-equal)
0 maxsize)))
(defun collect-files (directory &optional (filter "*.*"))
(mapcar (lambda (dir)
(cons dir
(sort (remove-if #'uiop:hidden-pathname-p (uiop:directory-files dir filter))
#'string< :key #'pathname-name)))
(flatten (labels ((collect-dirs (dir)
(let ((subdirs (remove-if
(lambda (d)
(uiop:hidden-pathname-p
(merge-pathnames
(car (last (pathname-directory d)))
(uiop:pathname-parent-directory-pathname d))))
(uiop:subdirectories dir))))
(cons (concatenate 'string directory
(enough-namestring dir (truename directory)))
(mapcar #'collect-dirs subdirs)))))
(collect-dirs (truename directory))))))