+ ,(if (fboundp 'balloon-help-mode)
+ ''balloon-help
+ ''help-echo)
+ ,(intern (format "gnus-balloon-face-%d" type))))
+
+(defun gnus-spec-tab (column)
+ (if (> column 0)
+ `(insert-char ? (max (- ,column (current-column)) 0))
+ (let ((column (abs column)))
+ `(if (> (current-column) ,column)
+ (let ((end (point)))
+ (if (= (move-to-column ,column) ,column)
+ (delete-region (point) end)
+ (delete-region (1- (point)) end)
+ (insert " ")))
+ (insert-char ? (max (- ,column (current-column)) 0))))))
+
+(defun gnus-correct-length (string)
+ "Return the correct width of STRING."
+ (apply #'+ (mapcar #'char-width string)))
+
+(defun gnus-correct-substring (string start &optional end)
+ (let ((wstart 0)
+ (wend 0)
+ (wseek 0)
+ (seek 0)
+ (length (length string))
+ (string (concat string "\0")))
+ ;; Find the start position.
+ (while (and (< seek length)
+ (< wseek start))
+ (incf wseek (char-width (aref string seek)))
+ (incf seek))
+ (setq wstart seek)
+ ;; Find the end position.
+ (while (and (<= seek length)
+ (or (not end)
+ (<= wseek end)))
+ (incf wseek (char-width (aref string seek)))
+ (incf seek))
+ (setq wend seek)
+ (substring string wstart (1- wend))))
+
+(defun gnus-string-width-function ()
+ (cond
+ (gnus-use-correct-string-widths
+ 'gnus-correct-length)
+ ((fboundp 'string-width)
+ 'string-width)
+ (t
+ 'length)))
+
+(defun gnus-substring-function ()
+ (cond
+ (gnus-use-correct-string-widths
+ 'gnus-correct-substring)
+ ((fboundp 'string-width)
+ 'gnus-correct-substring)
+ (t
+ 'substring)))