Mercurial > hg > xemacs-beta
comparison lisp/subr.el @ 777:e65d9cf16707
[xemacs-hg @ 2002-03-15 11:00:28 by ben]
config.h.in, sysdep.c, sysfile.h, systime.h: add HAVE_SYS_TIMES_H and use it to include sys/times.h, used for
struct tms in new POSIX() function times().
mule\mule-charset.el, obsolete.el, subr.el: Put back
previously-deleted truncate-string-to-width. Move other
non-Mule-specific stuff into subr.el or obsolete.el.
configure.in: check for sys/times.h.
author | ben |
---|---|
date | Fri, 15 Mar 2002 11:00:56 +0000 |
parents | d682c0f82a71 |
children | 6fadd0a2230b |
comparison
equal
deleted
inserted
replaced
776:79940b592197 | 777:e65d9cf16707 |
---|---|
521 (setq col (+ col (charset-width (char-charset (aref string i))))) | 521 (setq col (+ col (charset-width (char-charset (aref string i))))) |
522 (setq i (1+ i)))) | 522 (setq i (1+ i)))) |
523 col) | 523 col) |
524 (length string))) | 524 (length string))) |
525 | 525 |
526 (defun char-width (character) | |
527 "Return number of columns a CHARACTER occupies when displayed." | |
528 (if (featurep 'mule) | |
529 (with-fboundp '(charset-width char-charset) | |
530 (charset-width (char-charset character))) | |
531 1)) | |
532 | |
533 ;; The following several functions are useful in GNU Emacs 20 because | |
534 ;; of the multibyte "characters" the internal representation of which | |
535 ;; leaks into Lisp. In XEmacs/Mule they are trivial and unnecessary. | |
536 ;; We provide them for compatibility reasons solely. | |
537 | |
538 (defun string-to-sequence (string type) | |
539 "Convert STRING to a sequence of TYPE which contains characters in STRING. | |
540 TYPE should be `list' or `vector'." | |
541 (ecase type | |
542 (list | |
543 (mapcar #'identity string)) | |
544 (vector | |
545 (mapvector #'identity string)))) | |
546 | |
547 (defun string-to-list (string) | |
548 "Return a list of characters in STRING." | |
549 (mapcar #'identity string)) | |
550 | |
551 (defun string-to-vector (string) | |
552 "Return a vector of characters in STRING." | |
553 (mapvector #'identity string)) | |
554 | |
555 (defun store-substring (string idx obj) | |
556 "Embed OBJ (string or character) at index IDX of STRING." | |
557 (let* ((str (cond ((stringp obj) obj) | |
558 ((characterp obj) (char-to-string obj)) | |
559 (t (error | |
560 "Invalid argument (should be string or character): %s" | |
561 obj)))) | |
562 (string-len (length string)) | |
563 (len (length str)) | |
564 (i 0)) | |
565 (while (and (< i len) (< idx string-len)) | |
566 (aset string idx (aref str i)) | |
567 (setq idx (1+ idx) i (1+ i))) | |
568 string)) | |
569 | |
570 ;; #### This function is not compatible with FSF in some cases. Hard | |
571 ;; to fix, because it is hard to trace the logic of the FSF function. | |
572 ;; In case we need the exact behavior, we can always copy the FSF | |
573 ;; version, which is very long and does lots of unnecessary stuff. | |
574 (defun truncate-string-to-width (str end-column &optional start-column padding) | |
575 "Truncate string STR to end at column END-COLUMN. | |
576 The optional 2nd arg START-COLUMN, if non-nil, specifies | |
577 the starting column; that means to return the characters occupying | |
578 columns START-COLUMN ... END-COLUMN of STR. | |
579 | |
580 The optional 3rd arg PADDING, if non-nil, specifies a padding character | |
581 to add at the end of the result if STR doesn't reach column END-COLUMN, | |
582 or if END-COLUMN comes in the middle of a character in STR. | |
583 PADDING is also added at the beginning of the result | |
584 if column START-COLUMN appears in the middle of a character in STR. | |
585 | |
586 If PADDING is nil, no padding is added in these cases, so | |
587 the resulting string may be narrower than END-COLUMN." | |
588 (or start-column | |
589 (setq start-column 0)) | |
590 (let ((len (length str))) | |
591 (concat (substring str (min start-column len) (min end-column len)) | |
592 (and padding (> end-column len) | |
593 (make-string (- end-column len) padding))))) | |
594 | |
526 | 595 |
527 ;; alist/plist functions | 596 ;; alist/plist functions |
528 (defun plist-to-alist (plist) | 597 (defun plist-to-alist (plist) |
529 "Convert property list PLIST into the equivalent association-list form. | 598 "Convert property list PLIST into the equivalent association-list form. |
530 The alist is returned. This converts from | 599 The alist is returned. This converts from |