Function: mh-read-range

mh-read-range is an autoloaded and byte-compiled function defined in mh-seq.el.gz.

Signature

(mh-read-range PROMPT &optional FOLDER DEFAULT EXPAND-FLAG ASK-FLAG NUMBER-AS-RANGE-FLAG)

Documentation

Read a message range with PROMPT.

If FOLDER is non-nil then a range is read from that folder, otherwise use mh-current-folder.

If DEFAULT is a string then use that as default range to return. If DEFAULT is nil then ask user with default answer a range based on the sequences that seem relevant. Finally if DEFAULT is t, try to avoid prompting the user. Unseen messages, if present, are returned. If the folder has fewer than mh-large-folder messages then "all" messages are returned. Finally as a last resort prompt the user.

If EXPAND-FLAG is non-nil then a list of message numbers corresponding to the input is returned. If this list is empty then an error is raised. If EXPAND-FLAG is nil just return the input string. In this case we don't check if the range is empty.

If ASK-FLAG is non-nil, then the user is always queried for a range of messages. If ASK-FLAG is nil, then the function checks if the unseen sequence is non-empty. If that is the case, mh-unseen-seq, or the list of messages in it depending on the value of EXPAND, is returned. Otherwise if the folder has fewer than mh-large-folder messages then the list of messages corresponding to "all" is returned. If neither of the above holds then as a last resort the user is queried for a range of messages.

If NUMBER-AS-RANGE-FLAG is non-nil, then if a number, N is read as input, it is interpreted as the range "last:N".

This function replaces the existing function mh-read-msg-range. Calls to:

  (mh-read-msg-range folder flag)

should be replaced with:

  (mh-read-range "Suitable prompt" folder t nil flag
                 mh-interpret-number-as-range-flag)

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-seq.el.gz
;;;###mh-autoload
(defun mh-read-range (prompt &optional folder default
                             expand-flag ask-flag number-as-range-flag)
  "Read a message range with PROMPT.

If FOLDER is non-nil then a range is read from that folder, otherwise
use `mh-current-folder'.

If DEFAULT is a string then use that as default range to return. If
DEFAULT is nil then ask user with default answer a range based on the
sequences that seem relevant. Finally if DEFAULT is t, try to avoid
prompting the user. Unseen messages, if present, are returned. If the
folder has fewer than `mh-large-folder' messages then \"all\" messages
are returned. Finally as a last resort prompt the user.

If EXPAND-FLAG is non-nil then a list of message numbers corresponding
to the input is returned. If this list is empty then an error is
raised. If EXPAND-FLAG is nil just return the input string. In this
case we don't check if the range is empty.

If ASK-FLAG is non-nil, then the user is always queried for a range of
messages. If ASK-FLAG is nil, then the function checks if the unseen
sequence is non-empty. If that is the case, `mh-unseen-seq', or the
list of messages in it depending on the value of EXPAND, is returned.
Otherwise if the folder has fewer than `mh-large-folder' messages then
the list of messages corresponding to \"all\" is returned. If neither
of the above holds then as a last resort the user is queried for a
range of messages.

If NUMBER-AS-RANGE-FLAG is non-nil, then if a number, N is read as
input, it is interpreted as the range \"last:N\".

This function replaces the existing function `mh-read-msg-range'.
Calls to:

  (mh-read-msg-range folder flag)

should be replaced with:

  (mh-read-range \"Suitable prompt\" folder t nil flag
                 mh-interpret-number-as-range-flag)"
  (setq default (or default mh-last-seq-used
                    (car (mh-seq-containing-msg (mh-get-msg-num nil) t)))
        prompt (format "%s range" prompt))
  (let* ((folder (or folder mh-current-folder))
         (guess (eq default t))
         (counts (and guess (mh-folder-size folder)))
         (unseen (and counts (> (cadr counts) 0)))
         (large (and counts mh-large-folder (> (car counts) mh-large-folder)))
         (default (cond ((and guess large) (format "last:%s" mh-large-folder))
                        ((and guess (not large)) "all")
                        ((stringp default) default)
                        ((symbolp default) (symbol-name default))))
         (prompt (cond ((and guess large default)
                        (format-prompt "%s (folder has %s messages)"
                                default prompt (car counts)))
                       (default
                         (format-prompt prompt default))))
         (minibuffer-local-completion-map mh-range-completion-map)
         (seq-list (if (eq folder mh-current-folder)
                       mh-seq-list
                     (mh-read-folder-sequences folder nil)))
         (mh-range-seq-names
          (append '(("first") ("last") ("all") ("prev") ("next"))
                  (mh-seq-names seq-list)))
         (input (cond ((and (not ask-flag) unseen) (symbol-name mh-unseen-seq))
                      ((and (not ask-flag) (not large)) "all")
                      (t (completing-read prompt
                                          'mh-range-completion-function nil nil
                                          nil 'mh-range-history default))))
         msg-list)
    (when (and number-as-range-flag
               (string-match "^[ \t]*\\([0-9]+\\)[ \t]*$" input))
      (setq input (concat "last:" (match-string 1 input))))
    (cond ((not expand-flag) input)
          ((assoc (intern input) seq-list)
           (cdr (assoc (intern input) seq-list)))
          ((setq msg-list (mh-translate-range folder input)) msg-list)
          (t (error "No messages in range %s" input)))))