Mercurial > emacs
comparison lisp/subr.el @ 82365:e5a68f18fcb9
Merge from emacs--rel--22
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-851
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 13 Aug 2007 13:41:28 +0000 |
parents | b98604865ea0 1532be3afc8a |
children | 5b644ae74c91 424b655804ca |
comparison
equal
deleted
inserted
replaced
82364:0c34fdde692c | 82365:e5a68f18fcb9 |
---|---|
2834 (setq list | 2834 (setq list |
2835 (cons (substring string start) | 2835 (cons (substring string start) |
2836 list))) | 2836 list))) |
2837 (nreverse list))) | 2837 (nreverse list))) |
2838 | 2838 |
2839 ;; (string->strings (strings->string X)) == X | 2839 (defun combine-and-quote-strings (strings &optional separator) |
2840 (defun strings->string (strings &optional separator) | |
2841 "Concatenate the STRINGS, adding the SEPARATOR (default \" \"). | 2840 "Concatenate the STRINGS, adding the SEPARATOR (default \" \"). |
2842 This tries to quote the strings to avoid ambiguity such that | 2841 This tries to quote the strings to avoid ambiguity such that |
2843 (string->strings (strings->string strs)) == strs | 2842 (split-string-and-unquote (combine-and-quote-strings strs)) == strs |
2844 Only some SEPARATORs will work properly." | 2843 Only some SEPARATORs will work properly." |
2845 (let ((sep (or separator " "))) | 2844 (let ((sep (or separator " "))) |
2846 (mapconcat | 2845 (mapconcat |
2847 (lambda (str) | 2846 (lambda (str) |
2848 (if (string-match "[\\\"]" str) | 2847 (if (string-match "[\\\"]" str) |
2849 (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"") | 2848 (concat "\"" (replace-regexp-in-string "[\\\"]" "\\\\\\&" str) "\"") |
2850 str)) | 2849 str)) |
2851 strings sep))) | 2850 strings sep))) |
2852 | 2851 |
2853 ;; (string->strings (strings->string X)) == X | 2852 (defun split-string-and-unquote (string &optional separator) |
2854 (defun string->strings (string &optional separator) | |
2855 "Split the STRING into a list of strings. | 2853 "Split the STRING into a list of strings. |
2856 It understands elisp style quoting within STRING such that | 2854 It understands Emacs Lisp quoting within STRING, such that |
2857 (string->strings (strings->string strs)) == strs | 2855 (split-string-and-unquote (combine-and-quote-strings strs)) == strs |
2858 The SEPARATOR regexp defaults to \"\\s-+\"." | 2856 The SEPARATOR regexp defaults to \"\\s-+\"." |
2859 (let ((sep (or separator "\\s-+")) | 2857 (let ((sep (or separator "\\s-+")) |
2860 (i (string-match "[\"]" string))) | 2858 (i (string-match "[\"]" string))) |
2861 (if (null i) (split-string string sep t) ; no quoting: easy | 2859 (if (null i) |
2860 (split-string string sep t) ; no quoting: easy | |
2862 (append (unless (eq i 0) (split-string (substring string 0 i) sep t)) | 2861 (append (unless (eq i 0) (split-string (substring string 0 i) sep t)) |
2863 (let ((rfs (read-from-string string i))) | 2862 (let ((rfs (read-from-string string i))) |
2864 (cons (car rfs) | 2863 (cons (car rfs) |
2865 (string->strings (substring string (cdr rfs)) | 2864 (split-string-and-unquote (substring string (cdr rfs)) |
2866 sep))))))) | 2865 sep))))))) |
2867 | 2866 |
2868 | 2867 |
2869 ;;;; Replacement in strings. | 2868 ;;;; Replacement in strings. |
2870 | 2869 |
2871 (defun subst-char-in-string (fromchar tochar string &optional inplace) | 2870 (defun subst-char-in-string (fromchar tochar string &optional inplace) |