From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: avoid interpretation of \n, \t, ... in string Date: Wed, 28 Jan 2009 10:59:33 +0100 Organization: Anevia SAS Message-ID: <7c7i4fkayi.fsf@pbourguignon.anevia.com> References: <665cbb9b-8140-489e-a4d8-a15acce224be@r37g2000prr.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233139574 28735 80.91.229.12 (28 Jan 2009 10:46:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2009 10:46:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 28 11:47:27 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LS7wq-0001ke-5y for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Jan 2009 11:47:08 +0100 Original-Received: from localhost ([127.0.0.1]:33801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LS7vY-0008Bk-4Z for geh-help-gnu-emacs@m.gmane.org; Wed, 28 Jan 2009 05:45:48 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp6-2.free.fr!not-for-mail Original-Newsgroups: gnu.emacs.help Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:Yzg4NDgzMTIyNmFkOTA1NmI4ODNhNWVlYzY2ZGFhMDRlODNlYjc0Yw== Original-Lines: 99 Original-NNTP-Posting-Date: 28 Jan 2009 10:59:34 MET Original-NNTP-Posting-Host: 88.170.236.224 Original-X-Trace: 1233136774 news-2.free.fr 14317 88.170.236.224:39654 Original-X-Complaints-To: abuse@proxad.net Original-Xref: news.stanford.edu gnu.emacs.help:166404 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61725 Archived-At: Peter Tury writes: > I would like to pass paths to shell (extrenal command line programs) > on MS Windows. The paths may contain \n, \t etc. (Eg. c: > \directory-1\new-dir\temp...). However, the string is "evaluated" and > only the result arrives to the shell program. (In the above example: c: > \directory-1 > ew-dir emp...) > > I try to use `call-process-shell-command'. > > I know I could use double back-slash (e.g. c:\directory-1\\new-dir\ > \temp...), but I want to be able to handle any paths in their > "natural" form. How to do it? Switch to Common Lisp. There's no reader macro in emacs lisp, so you cannot do much about it. In Common Lisp, you can trivially implement a reader macro to read strings with no, or with a different escape character. And there are also various "emacsen" written in Common Lisp ;-) Ok, another way to do it would be to store your paths in a file, and to read it: (defun read-paths (file) (with-temp-buffer (insert-file-contents file) (delete "" (split-string (buffer-substring-no-properties (point-min) (point-max)) "[\n\r]+")))) Then with a file dirs.txt containing: c:\test\directory\file.txt D:\ANOTHER\DIRECTORY\FILE.TXT RELATIVE\DIRECTORY\FILE.TXT (read-paths "dirs.txt") --> ("c:\\test\\directory\\file.txt" "D:\\ANOTHER\\DIRECTORY\\FILE.TXT" "RELATIVE\\DIRECTORY\\FILE.TXT") Note that this is a serrious proposition. Myself, I use a directories.txt file containing keyed paths: KEY /some/dir OTHER_KEY /some/other/dir that I read with: (defvar *directories* '()) (defun get-directory (key &optional subpath) (setf subpath (or subpath "")) (unless (getf *directories* key) (error "get-directory: No directory keyed %s" key)) (concat (getf *directories* key) subpath)) (defun load-directories () (interactive) (setf *directories* (progn (find-file "~/directories.txt") (prog1 (loop for (k v) on (split-string (buffer-substring-no-properties (point-min) (point-max))) by (function cddr) nconc (list (intern (format ":%s" (substitute ?- ?_ (downcase k)))) v)) (kill-buffer (current-buffer)))))) (load-directories) in emacs lisp, and something similar in Common Lisp, and with '~/bin/get-directory': #!/bin/bash awk '/^ *'"$1"' */{print $2}' ~/directories.txt in shell: get-directory HYPERSPEC --> /usr/share/doc/hyperspec/HyperSpec/ so I can write all my scripts, whatever the language, independently of any directory location, and thus they can run identically on the various systems I use (each having its own ~/directories.txt file with its specific directories). -- __Pascal Bourguignon__