[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: avoid interpretation of \n, \t, ... in string

From: Pascal J. Bourguignon
Subject: Re: avoid interpretation of \n, \t, ... in string
Date: Wed, 28 Jan 2009 10:59:33 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

Peter Tury <address@hidden> 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)
    (insert-file-contents file)
    (delete "" (split-string (buffer-substring-no-properties
                              (point-min) (point-max))

Then with a file dirs.txt containing:


(read-paths "dirs.txt")
--> ("c:\\test\\directory\\file.txt" "D:\\ANOTHER\\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 ()
  (setf *directories*
          (find-file "~/directories.txt")
                 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))))
            (kill-buffer (current-buffer))))))


in emacs lisp, and something similar in Common Lisp, and with 

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__

reply via email to

[Prev in Thread] Current Thread [Next in Thread]