* mu4e-utils.el: improve sorting in mu4e-get-maildirs
This commit is contained in:
@ -110,44 +110,41 @@ Function returns the CHAR typed."
|
|||||||
(setq okchar (member response optionkars)))
|
(setq okchar (member response optionkars)))
|
||||||
response))
|
response))
|
||||||
|
|
||||||
(defun mu4e--get-maildirs-1 (path &optional mdir)
|
(defun mu4e~get-maildirs-1 (path &optional mdir)
|
||||||
"Get maildirs under path, recursively, as a list of relative
|
"Get maildirs under path, recursively, as a list of relative
|
||||||
paths."
|
paths."
|
||||||
;; first, we get a list of all directory paths under PATH that have a
|
;; first, we get a list of all directory paths under PATH that have a
|
||||||
;; directory 'cur' as leaf; then we we remove from that list all of those that
|
;; directory 'cur' as leaf; then we we remove from that list all of those that
|
||||||
;; don't have tmp, new sister dirs. And there we're done!
|
;; don't have tmp, new sister dirs. And there we're done!
|
||||||
|
|
||||||
;; 1. get all proper subdirs of the current dir
|
;; 1. get all proper subdirs of the current dir
|
||||||
(let* ((subdirs
|
(let* ((subdirs
|
||||||
(remove-if
|
(remove-if
|
||||||
(lambda (de)
|
(lambda (de)
|
||||||
(or (not (file-directory-p (concat path mdir "/" de)))
|
(or (not (file-directory-p (concat path mdir "/" de)))
|
||||||
(string-match "\\.\\{1,2\\}$" de)))
|
(string-match "\\.\\{1,2\\}$" de)))
|
||||||
(directory-files (concat path mdir))))
|
(directory-files (concat path mdir))))
|
||||||
;; 2. get the list of dirs with a /cur leaf dir
|
;; 2. get the list of dirs with a /cur leaf dir
|
||||||
(maildirs))
|
(maildirs '()))
|
||||||
(dolist (dir subdirs)
|
(dolist (dir subdirs)
|
||||||
(if (string= dir "cur")
|
(when (string= dir "cur")
|
||||||
;; be pedantic, and insist on there being a new/tmp as well
|
;; be pedantic, and insist on there being a new/tmp as well
|
||||||
(when (and (file-directory-p (concat path mdir "/new" ))
|
(when (and (file-directory-p (concat path mdir "/new" ))
|
||||||
(file-directory-p (concat path mdir "/tmp")))
|
(file-directory-p (concat path mdir "/tmp")))
|
||||||
(add-to-list 'maildirs mdir t))
|
(add-to-list 'maildirs (if mdir mdir "/") t)))
|
||||||
(setq maildirs (append maildirs
|
(setq maildirs (append maildirs
|
||||||
(mu4e--get-maildirs-1 path (concat mdir "/" dir))))))
|
(mu4e~get-maildirs-1 path (concat mdir "/" dir)))))
|
||||||
maildirs))
|
maildirs))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-get-maildirs (path)
|
(defun mu4e-get-maildirs (path)
|
||||||
"Get maildirs under path, recursively, as a list of relative
|
"Get maildirs under path, recursively, as a list of relative
|
||||||
paths (ie., /archive, /sent etc.). Most of the work is done in
|
paths (ie., /archive, /sent etc.). Most of the work is done in
|
||||||
`mu4e-get-maildirs-1, but we handle the special-case of the
|
`mu4e-get-maildirs-1'."
|
||||||
top-level Maildir here."
|
(sort (mu4e~get-maildirs-1 path)
|
||||||
(append
|
(lambda (m1 m2)
|
||||||
(when (and (file-directory-p (concat path "/cur"))
|
(when (string= m1 "/")
|
||||||
(file-directory-p (concat path "/tmp"))
|
-1 ;; '/' comes first
|
||||||
(file-directory-p (concat path "/new")))
|
(compare-strings m1 0 nil m2 0 nil t)))))
|
||||||
'("/"))
|
|
||||||
(mu4e--get-maildirs-1 path)))
|
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-ask-maildir (prompt)
|
(defun mu4e-ask-maildir (prompt)
|
||||||
|
|||||||
Reference in New Issue
Block a user