Function: mh-index-generate-pretty-name

mh-index-generate-pretty-name is a byte-compiled function defined in mh-search.el.gz.

Signature

(mh-index-generate-pretty-name STRING)

Documentation

Given STRING generate a name which is suitable for use as a folder name.

White space from the beginning and end are removed. All spaces in the name are replaced with underscores and all / are replaced with $. If STRING is longer than 20 it is truncated too. STRING could be a list of strings in which case they are concatenated to construct the base name.

Source Code

;; Defined in /usr/src/emacs/lisp/mh-e/mh-search.el.gz
(defun mh-index-generate-pretty-name (string)
  "Given STRING generate a name which is suitable for use as a folder name.
White space from the beginning and end are removed. All spaces in
the name are replaced with underscores and all / are replaced
with $. If STRING is longer than 20 it is truncated too. STRING
could be a list of strings in which case they are concatenated to
construct the base name."
  (with-temp-buffer
    (if (stringp string)
        (insert string)
      (when (car string) (insert (car string)))
      (dolist (s (cdr string))
        (insert "_" s)))
    (setq string (mh-replace-string "-lbrace" " "))
    (setq string (mh-replace-string "-rbrace" " "))
    (setq string (mh-replace-string "-search" " "))
    (subst-char-in-region (point-min) (point-max) ?\( ?  t)
    (subst-char-in-region (point-min) (point-max) ?\) ?  t)
    (subst-char-in-region (point-min) (point-max) ?- ?  t)
    (goto-char (point-min))
    (while (and (not (eobp)) (memq (char-after) '(?  ?\t ?\n ?\r ?_)))
      (delete-char 1))
    (goto-char (point-max))
    (while (and (not (bobp)) (memq (char-before) '(?  ?\t ?\n ?\r ?_)))
      (delete-char -1))
    (subst-char-in-region (point-min) (point-max) ?  ?_ t)
    (subst-char-in-region (point-min) (point-max) ?\t ?_ t)
    (subst-char-in-region (point-min) (point-max) ?\n ?_ t)
    (subst-char-in-region (point-min) (point-max) ?\r ?_ t)
    (subst-char-in-region (point-min) (point-max) ?/ ?$ t)
    (let ((out (truncate-string-to-width (buffer-string) 20)))
      (cond ((eq mh-searcher 'flists)
             (format "%s/%s" mh-flists-results-folder mh-flists-sequence))
            ((equal out mh-flists-results-folder) (concat out "1"))
            (t out)))))