Function: tmm-add-one-shortcut

tmm-add-one-shortcut is a byte-compiled function defined in tmm.el.gz.

Signature

(tmm-add-one-shortcut ELT)

Source Code

;; Defined in /usr/src/emacs/lisp/tmm.el.gz
(defsubst tmm-add-one-shortcut (elt)
  ;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts
  (cond
   ((eq (cddr elt) 'ignore)
    (cons (concat " " (make-string (length tmm-mid-prompt) ?\-)
                  (car elt))
          (cdr elt)))
   (t
    (let* ((str (car elt))
           (paren (string-search "(" str))
           (pos 0) (word 0) char)
      (catch 'done                             ; ??? is this slow?
        (while (and (or (not tmm-shortcut-words)   ; no limit on words
                        (< word tmm-shortcut-words)) ; try n words
                    (setq pos (string-match "\\w+" str pos)) ; get next word
                    (not (and paren (> pos paren)))) ; don't go past "(binding.."
          (if (or (= pos 0)
                  (/= (aref str (1- pos)) ?.)) ; avoid file extensions
              (dolist (shortcut-style ; try upcase and downcase variants
                       (if (listp tmm-shortcut-style) ; convert to list
                           tmm-shortcut-style
                       (list tmm-shortcut-style)))
                (setq char (funcall shortcut-style (aref str pos)))
                (if (not (memq char tmm-short-cuts)) (throw 'done char))))
          (setq word (1+ word))
          (setq pos (match-end 0)))
        (while (<= tmm-next-shortcut-digit ?9) ; no letter shortcut, pick a digit
          (setq char tmm-next-shortcut-digit)
          (setq tmm-next-shortcut-digit (1+ tmm-next-shortcut-digit))
          (if (not (memq char tmm-short-cuts)) (throw 'done char)))
        (setq char nil))
      (if char (setq tmm-short-cuts (cons char tmm-short-cuts)))
      (cons (concat (if char (concat (char-to-string char) tmm-mid-prompt)
                      ;; keep them lined up in columns
                      (make-string (1+ (length tmm-mid-prompt)) ?\s))
                    str)
            (cdr elt))))))