[ESS] elisp problems (was Re: feature request: look more places for R on windows [code]) [solved]

Ross Boylan ross at biostat.ucsf.edu
Thu Apr 18 23:48:23 CEST 2013


On 4/18/2013 12:12 PM, Ross Boylan wrote:
> I tried using my macro on an XP machine and it didn't work.  There 
> were 2 problems, one of which I need help solving.
>
> On 3/28/2013 1:51 PM, Ross Boylan wrote:
>> (defun installPath-reg-read (regpath)
>>   ;read a path in the Windows registry. This probably works for string
>>   ;values only. If the path does not exist, it returns nil.
>>   ;Adapted from source:
>> ;http://stackoverflow.com/questions/7436530/can-i-read-the-windows-registry-from-within-elisp-how 
>>
>>   (let ((reg.exe (concat (getenv "windir") "\\system32\\reg.exe"))
>>         tokens last-token)
>>
>>     (setq reg-value (shell-command-to-string (concat reg.exe " query 
>> " regpath " /v InstallPath"))
>>           tokens (split-string reg-value nil t)
>>           last-token (nth (1- (length tokens)) tokens))
>>
>>     (and (not (string= last-token "value.")) last-token))) 
> The first problem is that on XP failure to find a value produces a 
> string ending in "value" without a period.  I added a test for that.
>
> The second problem, which is not XP-specific, is that last-token is 
> not the right value if there are spaces in the path.
> I tried extracting everything after REG_SZ, but I keep getting the 
> whitespace before the string I'm interested in.  Sample attempt
> (string-match "^.*REG_SZ *\\([^ ].*\\) *" tlong)
> (match-string 1 tlong)
> where tlong is my temporary variable corresponding to reg-value 
> above.  I've also tried [:space:].
> I either fail to match or get a match that includes a bunch of leading 
> white-space, perhaps a tab.
(string-match "^.*REG_SZ[\t ]*\\([^ ].*\\) *" tlong)
One must add \t explicitly to the match after REG_SZ.  The original 
string has REG_SZ, a tab (ascii code 9), and then the start of the name 
I want with the letter C.
Bizarrely, neither [:space:] nor [:blank:] seems to match \t, e.g.,
(string-match "^.*REG_SZ[:blank:]*\\([^ ].*\\) *" tlong) does not match.

I'm not sure if the use of space alone fails because it only means 
"space or tab" when used interactively, or if it's failing to match for 
the same reason the character classes fail.

Ross
>
> Any suggestions how to fix this?  Maybe if I looked at the character 
> codes in the string it would help, but the characters visually are 
> whitespace, and so I don't know that the problem is. My understanding 
> is that  a space in a regular expression will match at least a space 
> or a tab (emacs 24.3.1).
>
> tlong is multi-line, if that matters.  The fact that it's the result 
> of shell-command-to-string may be more important in making it behave 
> oddly.
>
> Thanks.
> Ross
>
> P.S. The code with tlong is typed manually and so might have a 
> transcription error, though I don't see one.



More information about the ESS-help mailing list