]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-utils.el
Update copyright year to 2016
[gnu-emacs] / lisp / mh-e / mh-utils.el
index d7d3107b908b26fd13a6deed81c38ffe243760b5..66971014fa17d1e1633bb354a5175befbd810a43 100644 (file)
@@ -1,6 +1,7 @@
 ;;; mh-utils.el --- MH-E general utilities
 
-;; Copyright (C) 1993, 1995, 1997, 2000-2011  Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1995, 1997, 2000-2016 Free Software Foundation,
+;; Inc.
 
 ;; Author: Bill Wohler <wohler@newt.com>
 ;; Maintainer: Bill Wohler <wohler@newt.com>
@@ -418,21 +419,21 @@ names and the function is called when OUTPUT is available."
                                         return-nil-if-folder-empty)
   "Normalizes FOLDER name.
 
-Makes sure that two '/' characters never occur next to each
-other. Also all occurrences of \"..\" and \".\" are suitably
+Makes sure that two `/' characters never occur next to each
+other. Also all occurrences of `..' and `.' are suitably
 processed. So \"+inbox/../news\" will be normalized to \"+news\".
 
-If optional argument EMPTY-STRING-OKAY is nil then a '+' is added
+If optional argument EMPTY-STRING-OKAY is nil then a `+' is added
 at the front if FOLDER lacks one. If non-nil and FOLDER is the
 empty string then nothing is added.
 
 If optional argument DONT-REMOVE-TRAILING-SLASH is non-nil then a
-trailing '/' if present is retained (if present), otherwise it is
+trailing `/' if present is retained (if present), otherwise it is
 removed.
 
 If optional argument RETURN-NIL-IF-FOLDER-EMPTY is non-nil, then
 return nil if FOLDER is \"\" or \"+\". This is useful when
-normalizing the folder for the \"folders\" command which displays
+normalizing the folder for the `folders' command which displays
 the directories in / if passed \"+\". This is usually not
 desired. If this argument is non-nil, then EMPTY-STRING-OKAY has
 no effect."
@@ -484,18 +485,18 @@ no effect."
   folder)
 
 (defmacro mh-children-p (folder)
-  "Return t if FOLDER from sub-folders cache has children.
-The car of folder is the name, and the cdr is either t or some
-sort of count that I do not understand. It's too small to be the
-number of messages in the sub-folders and too large to be the
-number of sub-folders. XXX"
+  "Return t if FOLDER from sub-folders cache has children."
+;; The car of folder is the name, and the cdr is either t or some
+;; sort of count that I do not understand. It's too small to be the
+;; number of messages in the sub-folders and too large to be the
+;; number of sub-folders. XXX
   `(if (cdr ,folder)
        t
      nil))
 
 ;;;###mh-autoload
 (defun mh-folder-list (folder)
-  "Return FOLDER and its descendents.
+  "Return FOLDER and its descendants.
 FOLDER may have a + prefix. Returns a list of strings without the
 + prefix. If FOLDER is nil, then all folders are considered. For
 example, if your Mail directory only contains the folders +inbox,
@@ -514,7 +515,7 @@ they will not be returned."
     ;; folder is specified, ensure it is nil to avoid adding the
     ;; folder to the folder-list and adding a slash to it.
     (when folder
-      (setq folder (mh-replace-regexp-in-string "^\+" "" folder))
+      (setq folder (mh-replace-regexp-in-string "^\\+" "" folder))
       (setq folder (mh-replace-regexp-in-string "/+$" "" folder))
       (if (equal folder "")
           (setq folder nil)))
@@ -652,7 +653,7 @@ with \"+\"."
 ;;;###mh-autoload
 (defun mh-expand-file-name (filename &optional default)
   "Expand FILENAME like `expand-file-name', but also handle MH folder names.
-Any filename that starts with '+' is treated as a folder name.
+Any filename that starts with `+' is treated as a folder name.
 See `expand-file-name' for description of DEFAULT."
   (if (mh-folder-name-p filename)
       (expand-file-name (substring filename 1) mh-user-path)
@@ -702,36 +703,37 @@ See Info node `(elisp) Programmed Completion' for details."
          (remainder (cond (last-complete (substring name (1+ last-slash)))
                           (name (substring name 1))
                           (t ""))))
-    (cond ((eq flag nil)
+    (cond ((eq (car-safe flag) 'boundaries)
+           (list* 'boundaries
+                  (let ((slash (mh-search-from-end ?/ orig-name)))
+                    (if slash (1+ slash)
+                      (if (string-match "\\`\\+" orig-name) 1 0)))
+                  (if (cdr flag) (string-match "/" (cdr flag)))))
+          ((eq flag nil)
            (let ((try-res
                   (try-completion
-                   name
-                   (mapcar (lambda (x)
-                             (cons (concat (or last-complete "+") (car x))
-                                   (cdr x)))
-                    (mh-sub-folders last-complete t))
+                   remainder
+                   (mh-sub-folders last-complete t)
                    predicate)))
              (cond ((eq try-res nil) nil)
                    ((and (eq try-res t) (equal name orig-name)) t)
                    ((eq try-res t) name)
-                   (t try-res))))
+                   (t (concat (or last-complete "+") try-res)))))
           ((eq flag t)
-           (mapcar (lambda (x)
-                     (concat (or last-complete "+") x))
-                   (all-completions
-                    remainder (mh-sub-folders last-complete t) predicate)))
+           (all-completions
+            remainder (mh-sub-folders last-complete t) predicate))
           ((eq flag 'lambda)
            (let ((path (concat (unless (and (> (length name) 1)
                                             (eq (aref name 1) ?/))
                                  mh-user-path)
                                (substring name 1))))
-             (cond (mh-allow-root-folder-flag (file-exists-p path))
+             (cond (mh-allow-root-folder-flag (file-directory-p path))
                    ((equal path mh-user-path) nil)
-                   (t (file-exists-p path))))))))
+                   (t (file-directory-p path))))))))
 
 ;; Shush compiler.
-(defvar completion-root-regexp)          ; XEmacs
-(defvar minibuffer-completing-file-name) ; XEmacs
+(mh-do-in-xemacs
+  (defvar completion-root-regexp))
 
 (defun mh-folder-completing-read (prompt default allow-root-folder-flag)
   "Read folder name with PROMPT and default result DEFAULT.