comparison lisp/prim/obsolete.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents bfd6434d15b3
children a2f645c6b9f8
comparison
equal deleted inserted replaced
188:e29a8e7498d9 189:489f57a838ef
622 622
623 ;; Two loser functions which shouldn't be used. 623 ;; Two loser functions which shouldn't be used.
624 (make-obsolete 'following-char 'char-after) 624 (make-obsolete 'following-char 'char-after)
625 (make-obsolete 'preceding-char 'char-before) 625 (make-obsolete 'preceding-char 'char-before)
626 626
627
628 ;; The following several functions are useful in GNU Emacs 20 because
629 ;; of the multibyte "characters" the internal representation of which
630 ;; leaks into Lisp. In XEmacs/Mule they are trivial and unnecessary.
631 ;; We provide them for compatibility reasons solely.
632
633 (defun string-to-sequence (string type)
634 "Convert STRING to a sequence of TYPE which contains characters in STRING.
635 TYPE should be `list' or `vector'.
636 Multibyte characters are concerned."
637 (cond ((eq type 'list)
638 (mapcar #'identity string))
639 ((eq type 'vector)
640 (mapcar #'identity string))
641 (t
642 (error "Type must be `list' or `vector'"))))
643
644 (defun string-to-list (string)
645 "Return a list of characters in STRING."
646 (mapcar #'identity string))
647
648 (defun string-to-vector (string)
649 "Return a vector of characters in STRING."
650 (mapvector #'identity string))
651
652 (defun store-substring (string idx obj)
653 "Embed OBJ (string or character) at index IDX of STRING."
654 (let* ((str (cond ((stringp obj) obj)
655 ((characterp obj) (char-to-string obj))
656 (t (error
657 "Invalid argument (should be string or character): %s"
658 obj))))
659 (string-len (length string))
660 (len (length str))
661 (i 0))
662 (while (and (< i len) (< idx string-len))
663 (aset string idx (aref str i))
664 (setq idx (1+ idx) i (1+ i)))
665 string))
666
667 ;; ### This function is not compatible with FSF in some cases. Hard
668 ;; to fix, because it is hard to trace the logic of the FSF function.
669 ;; In case we need the exact behaviour, we can always copy the FSF
670 ;; version, which is very long and does lots of unnecessary stuff.
671 (defun truncate-string-to-width (str end-column &optional start-column padding)
672 "Truncate string STR to end at column END-COLUMN.
673 The optional 2nd arg START-COLUMN, if non-nil, specifies
674 the starting column; that means to return the characters occupying
675 columns START-COLUMN ... END-COLUMN of STR.
676
677 The optional 3rd arg PADDING, if non-nil, specifies a padding character
678 to add at the end of the result if STR doesn't reach column END-COLUMN,
679 or if END-COLUMN comes in the middle of a character in STR.
680 PADDING is also added at the beginning of the result
681 if column START-COLUMN appears in the middle of a character in STR.
682
683 If PADDING is nil, no padding is added in these cases, so
684 the resulting string may be narrower than END-COLUMN."
685 (or start-column
686 (setq start-column 0))
687 (let ((len (length str)))
688 (concat (substring str (min start-column len) (min end-column len))
689 (and padding (> end-column len)
690 (make-string (- end-column len) padding)))))
691
692 (defalias 'truncate-string 'truncate-string-to-width)
693 (make-obsolete 'truncate-string 'truncate-string-to-width)
694
695
696
627 ;;; obsolete.el ends here 697 ;;; obsolete.el ends here