Captured lines in elisp

I am very new to Lisp - and especially to Elisp - and I have a problem handling strings:

I want to convert a Windows style style to a Unix style path - especially I need to convert the path I get from Visual Studio to the Cygwin path, since I want to be able to open the file from Visual Studio in Emacs (I hope to use emacsclient --eval for of this):

The Visual Studio path has the following format:

C:\Users\name\documents\visual studio 2010\projects\test 

I want to change it to the appropriate Cygwin path, which would be as follows:

 /cygdrive/c/Users/name/documents/visual studio 2010/projects/test 

However, an attempt to execute the following in the zero buffer is no longer performed:

 (replace-regexp-in-string "\\" "\/" "C:\users\someone") (subst-char-in-string ?\ ?/ "C:\users\someone") >> Debugger entered--Lisp error: (error "Non-hex digit used for Unicode escape") 

Is there a way to make Elisp not escape the backslashes in each line?

EDIT :

This is how I call emacs from Visual Studio using external tools:

 emacsclient -d 127.0.0.1:0.0 --eval '(convert-win-to-cygwin-path $(ItemPath))' 

$ (ItemPath) will be replaced with C:\Users\asf , which I cannot influence, so it will pass a String with single backslash emacs, which I need to change in emacs.

Can I make emacs KNOW that it needs to make a double backslash from one backslash?

EDIT 2: Solution

I changed the way I try to start emacs by actually invoking a shell script that will run emacs - this way I can make sure emacs gets the correct path:

 #!/bin/bash export PATH="/usr/bin/:/bin/:$PATH" filename=$1 line=$2 column=$3 cyged_path=$(cygpath "$filename") echo "Cyged path: $cyged_path" emacsclient -d 127.0.0.1:0.0 -n +$line:$column "$cyged_path" 

And I call it from Visual Studio with the following arguments in the external tools window:

 Path: <path_to_cygwin>\bin\bash.exe Arguments: <path_to_script> $(ItemPath) $(CurLine) $(CurCol) 
+4
source share
6 answers

You do not have to do anything.

Cygwin provides a command specifically for converting Windows paths to Cygwin paths, so you don’t have to worry about that.

 cmd> C:\cygwin\bin\cygpath.exe "C:\Users\name\documents\visual studio 2010\projects\test" /cygdrive/c/Users/name/documents/visual studio 2010/projects/test 

Edit: I was curious about the backticks equivalent of the Windows shell and found the Bash backticks package equivalent that suggests you could do all this with this single-liner?

 cmd> for /f "usebackq tokens=*" %a in (`C:\cygwin\bin\cygpath.exe "$(ItemPath)"`) do emacsclient -d 127.0.0.1:0.0 "%a" 
+3
source

Another way to look at your problem is that your emacsclient -d 127.0.0.1:0.0 --eval '(convert-win-to-cygwin-path $(ItemPath))' passes the file name inside the Elisp line, so the backslashes traits are treated as escape sequences. Thus, the solution should pass it as data, as in emacsclient -d 127.0.0.1:0.0 $(ItemPath) . The next problem is for your Emacs to understand these file names. If you use a regular Windows Emacs build that will work without doing anything special, but if you use a Cygwin build, you will need to do something like the equivalent (but vice versa) cygwin-mout.el.

+1
source

The backslash must be avoided. This will work:

 ELISP> (subst-char-in-string ?\\ ?/ "C:\\users\\someone") "C:/users/someone" 
0
source

Are you sure Windows does not send preprogrammed backslashes? It would be strange if this did not happen.

See this wiki page for how others solved this problem.

0
source

Here's the answer in emacs lisp, although I like that Fils answers. This function converts the area that is expected to be a complete Windows file file, including disk, to the cygwin path.

For instance:

 C:\Users\name\documents\visual studio 2010\projects\test 

becomes ...

 /cygdrive/C/Users/name/documents/visual studio 2010/projects/test 

Here is the code:

 (defun win32-to-cygwin-path() "Converts a win32 path into a cygwin happy one" (interactive) (save-excursion (save-restriction (narrow-to-region (point) (mark)) (goto-char (point-min)) (insert "/cygdrive/") (goto-char (point-min)) (while (search-forward ":" nil t) (replace-match "" nil t)) (while (search-forward "\\" nil t) (replace-match "/" nil t))))) 
0
source

None of these solutions worked for me (emacs 24.3.1), anyway a simple .bat script would do:

 @ECHO OFF c:\cygwin64\bin\cygpath.exe %1 > tmp.txt set /p FILE_TO_EDIT= < tmp.txt del tmp.txt C:\cygwin64\bin\cygstart.exe -- /bin/emacs-w32.exe %FILE_TO_EDIT% 

Save this in file.bat and send the file you want to change as an argument, for WinSCP it will look like this: C: \ Users \ xxxxx \ Desktop \ open.bat!.!

0
source

Source: https://habr.com/ru/post/1440002/


All Articles