diff lisp/subr.el @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents 183866b06e0b
children d682c0f82a71
line wrap: on
line diff
--- a/lisp/subr.el	Fri Mar 08 13:33:14 2002 +0000
+++ b/lisp/subr.el	Wed Mar 13 08:54:06 2002 +0000
@@ -506,6 +506,22 @@
 (define-function 'char-int 'char-to-int)
 (define-function 'int-char 'int-to-char)
 
+(defun string-width (string)
+  "Return number of columns STRING occupies when displayed.
+With international (Mule) support, uses the charset-columns attribute of
+the characters in STRING, which may not accurately represent the actual
+display width when using a window system.  With no international support,
+simply returns the length of the string."
+  (if (featurep 'mule)
+      (let ((col 0)
+	    (len (length string))
+	    (i 0))
+	(while (< i len)
+	  (setq col (+ col (charset-width (char-charset (aref string i)))))
+	  (setq i (1+ i)))
+	col)
+    (length string)))
+
 
 ;; alist/plist functions
 (defun plist-to-alist (plist)