[ESS] Adjust R option width to current frame width

Martin Maechler maechler at stat.math.ethz.ch
Fri Jan 20 16:57:38 CET 2006


    FrL> Martin Mächler asked me to post the following lisp snippet to the list:

>> (defun fl-ess-adjust-width ()
>>   (interactive)
>>   (ess-execute
>>    (concat "options(width="
>> 	   (number-to-string (frame-width))
>> 	   ")") 'buffer))

note that ESS already has (almost) this functionality,
though in ess-inf.el and with a more generic name.

 (defun ess-execute-screen-options ()
   "Cause S to set the \"width\" option to 1 less than the frame width.
 Also sets the \"length\" option to 99999.
 This is a good thing to put in `ess-post-run-hook' --- for the S dialects."
   (interactive)
   (if (string= ess-language "S")
       (ess-eval-linewise (format "options(width=%d,length=99999)"
				  (1- (frame-width))))))

it does use frame-width -1' though.

>> (add-hook 'inferior-ess-mode-hook
>>           (lambda ()
>> 	    (define-key inferior-ess-mode-map "\C-cw"
>>           'fl-ess-adjust-width)))

    FrL> which sets R option width to the current frame width when pressing C-cw
    FrL> ... I personally don't want that the width changes automatically as in
    FrL> the windows console, hence I never bothered to look whether that is
    FrL> possible.


Now that's a good idea and I propose to add the following to the
  (defun ess-add-MM-keys )
which already was use to set such useful "C-c <letter>" settings

which would lead to 

(defun ess-add-MM-keys ()
  "Define MM's user keys, currently only \\<ess-mode-map>\\[ess-insert-function-outline]."
  (interactive)
  (require 'ess-mode)
  (define-key ess-mode-map "\C-cf" 'ess-insert-function-outline)
  (require 'ess-inf)
  (define-key inferior-ess-mode-map "\C-cw" 'ess-execute-screen-options)
  )


-- and yes, one should rewrite this using (add-hook ..) instead
   of (require ..).
Martin




More information about the ESS-help mailing list