[ESS] setwd shortcut

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 5 09:39:23 CEST 2010

>>>>> "ChuckB" == Charles C Berry <cberry at tajo.ucsd.edu>
>>>>>     on Sat, 3 Jul 2010 20:01:12 -0700 writes:

    ChuckB> On Sat, 3 Jul 2010, baptiste auguie wrote:
    >> On Sat, Jul 3, 2010 at 9:43 PM, Charles C. Berry <cberry at tajo.ucsd.edu> wrote:
    >> [...]
    >>> Save a keyboard macro?
    >>> (setq last-kbd-macro
    >>>   [?\C-  ?\C-u ?\M-| ?p ?w ?d return ?\C-p ?s ?e ?t ?w ?d ?\( ?\" ?\C-e ?\"
    >>> ?\)])
    >> Sounds good, but how do I call it? (I placed the definition in
    >> ~/.emacs but now what?)

    ChuckB> Try this:

    ChuckB> (fset 'my-setwd-macro
    ChuckB> [?\C-  ?\C-u ?\M-| ?p ?w ?d return ?\C-p ?s ?e ?t ?w ?d ?\( ?\" ?\C-e ?\" ?\)])

    ChuckB> (add-hook
    ChuckB>    'ess-mode-hook
    ChuckB>    '(lambda()
    ChuckB>       (define-key ess-mode-map "\C-c\C-s" 'my-setwd-macro)))

    ChuckB> Now in test.R try typing C-c C-s

I agree the ideas are nice {I'm summarizing them}

1) in foo.R,  allow to setwd() (to the 'dirname' directory of foo.R)
   in the *R* process that "belongs to" foo.R, by a simple command.

2) Using keyboard macros is a powerful emacs feature, and it's
   great if it is taught, as with this example.
   Thank you, Chuck!


a) the idea is too good to just be available as a keyboard macro
   (they are not "robust", "maintainable", ...)

   Any volunteers for providing a "real"

   (defun ess-execute-setwd-dirname ()


b) the binding to C-c C-s  is not good.
   C-c C-s is already bound to the quite important "switch process"
   function   something I use quite a bit, if I try the same 
   R code 
     i.  in different versions of R,
     ii. with different versions of an R package (in the same version of R)
     iii. combination of i. and ii.

To find free key bindings, starting with C-c
anywhere in Emacs,
type   C-c C-h and you will see the bindings already in use.

  C-c C-m  <===> C-c RET  is free, and we could use that.
alternatively, we could use
which is also unbound (for me / typically?) in foo.R
and which we have just started make use of in other contexts of 
"directory synchronization"
{almost the "dual" of this situation: namely from *R*, set the
 emacs and ESS default directory to the one that setwd() points to}

Looking forward to your comments

Martin Maechler, 
ETH Zurich

More information about the ESS-help mailing list