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

Ross Boylan ross at biostat.ucsf.edu
Thu Apr 18 21:12:12 CEST 2013


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.

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