Mercurial > hg > xemacs-beta
changeset 5321:57a64ab2ae45
Implement some basic Lisp functions in terms of Common Lisp builtins.
2010-12-30 Aidan Kehoe <kehoea@parhasard.net>
* simple.el (assoc-ignore-case): Remove a duplicate definition of
this function (it's already in subr.el).
* iso8859-1.el (char-width):
On non-Mule, make this function equivalent to that produced by
(constantly 1), but preserve its docstring.
* subr.el (subst-char-in-string): Define this in terms of
#'substitute, #'nsubstitute.
(string-width): Define this using #'reduce and #'char-width.
(char-width): Give this a simpler definition, it makes far more
sense to check for mule at load time and redefine, as we do in
iso8859-1.el.
(store-substring): Implement this in terms of #'replace, now
#'replace is cheap.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Thu, 30 Dec 2010 01:00:40 +0000 |
parents | 31be2a3d121d |
children | df125a42c50c |
files | lisp/ChangeLog lisp/iso8859-1.el lisp/simple.el lisp/subr.el |
diffstat | 4 files changed, 34 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Thu Dec 30 00:50:10 2010 +0000 +++ b/lisp/ChangeLog Thu Dec 30 01:00:40 2010 +0000 @@ -1,3 +1,19 @@ +2010-12-30 Aidan Kehoe <kehoea@parhasard.net> + + * simple.el (assoc-ignore-case): Remove a duplicate definition of + this function (it's already in subr.el). + * iso8859-1.el (char-width): + On non-Mule, make this function equivalent to that produced by + (constantly 1), but preserve its docstring. + * subr.el (subst-char-in-string): Define this in terms of + #'substitute, #'nsubstitute. + (string-width): Define this using #'reduce and #'char-width. + (char-width): Give this a simpler definition, it makes far more + sense to check for mule at load time and redefine, as we do in + iso8859-1.el. + (store-substring): Implement this in terms of #'replace, now + #'replace is cheap. + 2010-12-30 Aidan Kehoe <kehoea@parhasard.net> * update-elc.el (lisp-files-needed-for-byte-compilation)
--- a/lisp/iso8859-1.el Thu Dec 30 00:50:10 2010 +0000 +++ b/lisp/iso8859-1.el Thu Dec 30 01:00:40 2010 +0000 @@ -84,6 +84,17 @@ ;; by default. (setq-default ctl-arrow #xA0) +(when (and (compiled-function-p (symbol-function 'char-width)) + (not (featurep 'mule))) + (defalias 'char-width + (let ((constantly (constantly 1))) + (make-byte-code (compiled-function-arglist constantly) + (compiled-function-instructions constantly) + (compiled-function-constants constantly) + (compiled-function-stack-depth constantly) + (compiled-function-doc-string + (symbol-function 'char-width)))))) + ;; Shouldn't be necessary, but one file in the packages uses it: (provide 'iso8859-1)
--- a/lisp/simple.el Thu Dec 30 00:50:10 2010 +0000 +++ b/lisp/simple.el Thu Dec 30 01:00:40 2010 +0000 @@ -3332,11 +3332,6 @@ ;; keyboard-quit ;; buffer-quit-function ;; keyboard-escape-quit - -(defun assoc-ignore-case (key alist) - "Like `assoc', but assumes KEY is a string and ignores case when comparing." - (assoc* key alist :test #'equalp)) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; mail composition code ;;
--- a/lisp/subr.el Thu Dec 30 00:50:10 2010 +0000 +++ b/lisp/subr.el Thu Dec 30 01:00:40 2010 +0000 @@ -765,14 +765,8 @@ (defun subst-char-in-string (fromchar tochar string &optional inplace) "Replace FROMCHAR with TOCHAR in STRING each time it occurs. Unless optional argument INPLACE is non-nil, return a new string." - (let ((i (length string)) - (newstr (if inplace string (copy-sequence string)))) - (while (> i 0) - (setq i (1- i)) - (if (eq (aref newstr i) fromchar) - (aset newstr i tochar))) - newstr)) - + (funcall (if inplace #'nsubstitute #'substitute) tochar fromchar + (the string string) :test #'eq)) ;; XEmacs addition: (defun replace-in-string (str regexp newtext &optional literal) @@ -961,23 +955,11 @@ 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)) - (with-fboundp '(charset-width char-charset) - (while (< i len) - (setq col (+ col (charset-width (char-charset (aref string i))))) - (setq i (1+ i)))) - col) - (length string))) + (reduce #'+ (the string string) :initial-value 0 :key #'char-width)) (defun char-width (character) "Return number of columns a CHARACTER occupies when displayed." - (if (featurep 'mule) - (with-fboundp '(charset-width char-charset) - (charset-width (char-charset character))) - 1)) + (charset-width (char-charset character))) ;; The following several functions are useful in GNU Emacs 20 because ;; of the multibyte "characters" the internal representation of which @@ -1003,18 +985,9 @@ (defun store-substring (string idx obj) "Embed OBJ (string or character) at index IDX of STRING." - (let* ((str (cond ((stringp obj) obj) - ((characterp obj) (char-to-string obj)) - (t (error - "Invalid argument (should be string or character): %s" - obj)))) - (string-len (length string)) - (len (length str)) - (i 0)) - (while (and (< i len) (< idx string-len)) - (aset string idx (aref str i)) - (setq idx (1+ idx) i (1+ i))) - string)) + (if (stringp obj) + (replace (the string string) obj :start1 idx) + (prog1 string (aset string idx obj)))) ;; From FSF 21.1; ELLIPSES is XEmacs addition.