Function: reftex-convert-string
reftex-convert-string is a byte-compiled function defined in
reftex.el.gz.
Signature
(reftex-convert-string STRING SPLIT-RE INVALID-RE DOT KEEP-FP NWORDS MAXCHAR INVALID ABBREV SEP IGNORE-WORDS &optional DOWNCASE)
Documentation
Convert STRING (a sentence) to something shorter.
SPLIT-RE is the regular expression used to split the string into words.
INVALID-RE matches characters which are invalid in the final string.
DOT t means add dots to abbreviated words.
KEEP-FP t means to keep a final punctuation when applicable.
NWORDS Number of words to use.
MAXCHAR Maximum number of characters in the final string.
INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
t: Throw away only the matched part, not the whole word.
ABBREV nil: Never abbreviate words.
t: Always abbreviate words (see reftex-abbrev-parameters).
not t and not nil: Abbreviate words if necessary to shorten
string below MAXCHAR.
SEP String separating different words in the output string.
IGNORE-WORDS List of words which should be removed from the string.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex.el.gz
(defun reftex-convert-string (string split-re invalid-re dot keep-fp
nwords maxchar invalid abbrev sep
ignore-words &optional downcase)
"Convert STRING (a sentence) to something shorter.
SPLIT-RE is the regular expression used to split the string into words.
INVALID-RE matches characters which are invalid in the final string.
DOT t means add dots to abbreviated words.
KEEP-FP t means to keep a final punctuation when applicable.
NWORDS Number of words to use.
MAXCHAR Maximum number of characters in the final string.
INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
t: Throw away only the matched part, not the whole word.
ABBREV nil: Never abbreviate words.
t: Always abbreviate words (see `reftex-abbrev-parameters').
not t and not nil: Abbreviate words if necessary to shorten
string below MAXCHAR.
SEP String separating different words in the output string.
IGNORE-WORDS List of words which should be removed from the string."
(let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
(reftex-label-illegal-re (or invalid-re "\000"))
(abbrev-re (concat
"\\`\\("
(make-string (nth 0 reftex-abbrev-parameters) ?.)
"[" (nth 2 reftex-abbrev-parameters) "]*"
"\\)"
"[" (nth 3 reftex-abbrev-parameters) "]"
(make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
words word)
;; Remove words from the ignore list or with funny characters
(while (setq word (pop words0))
(if downcase (setq word (downcase word)))
(cond
((member (downcase word) ignore-words))
((string-match reftex-label-illegal-re word)
(when invalid
(while (string-match reftex-label-illegal-re word)
(setq word (replace-match "" nil nil word)))
(push word words)))
(t
(push word words))))
(setq words (nreverse words))
;; Restrict number of words
(if (> (length words) nwords)
(setcdr (nthcdr (1- nwords) words) nil))
;; First, try to use all words
(setq string (mapconcat #'identity words sep))
;; Abbreviate words if enforced by user settings or string length
(if (or (eq t abbrev)
(and abbrev
(> (length string) maxchar)))
(setq words
(mapcar
(lambda (w) (if (string-match abbrev-re w)
(if dot
(concat (match-string 1 w) ".")
(match-string 1 w))
w))
words)
string (mapconcat #'identity words sep)))
;; Shorten if still to long
(setq string
(if (> (length string) maxchar)
(substring string 0 maxchar)
string))
;; Delete the final punctuation, if any
(if (and (not keep-fp) (string-match "\\s.+\\'" string))
(setq string (replace-match "" nil nil string)))
string))