+(defun gtk-popup-convert-underscores (str)
+ ;; Convert the XEmacs button accelerator representation to Gtk mnemonic
+ ;; form. If no accelerator has been provided, put one at the start of the
+ ;; string (this mirrors the behaviour under X). This algorithm is also found
+ ;; in menubar-gtk.c:convert_underscores().
+ (let ((new-str (string))
+ (i 0)
+ (found-accel nil))
+ (while (< i (length str))
+ (let ((c (aref str i)))
+ (cond ((eq c ?%)
+ (setq i (1+ i))
+ (if (and (not (eq (aref str i) ?_)) (not (eq (aref str i) ?%)))
+ (setq i (1- i)))
+ (setq found-accel 1)
+ )
+ ((eq c ?_)
+ (setq new-str (concat new-str "_")))
+ ))
+ (setq new-str (concat new-str (string (aref str i))))
+ (setq i (1+ i))
+ )
+ (if found-accel new-str (concat "_" new-str))
+ ))
+