[ESS] elisp code: show function arguments

Kiermeier, Andreas (PIRSA - SARDI) Kiermeier.Andreas at saugov.sa.gov.au
Tue Apr 3 07:32:22 CEST 2007


I've just tried this myself, and it works fine for me (GNU Emacs,
Windows XP).

You may want to add the lines

;; bind my-r-show-args to F2
(define-key ess-mode-map [f2] 'my-r-show-args)

But that's only additional and shouldn't stop Sven's code from working.

When you say "I can't seem to get Sven's functionality to work" do you
get any error messages?

I noticed that (not surprisingly) an R process has to be associated with
the "filename.R" buffer in which you are typing your commands. To do
this for example, create a file called "whatever.R' and load it into
Emacs. Start an R process (M-x R), then type a command such as


into the "whatever.R" buffer (not the R process). Here you should get an
error after typing '(' since no process is yet associated with the
buffer, and Sven's function doesn't know where to look for the argument
info. Now submit the command you just typed to R, e.g. with the cursor
on the same line as the command press C-c C-j, which will prompt you for
the process - press the Enter key to confirm. (Someone else may be able
to confirm a different & better way of associating an R process with a

Now, when you go back to your whatever.R buffer you should be able to
type (on a new line) 


At which point the mini buffer should show the arguments.

If you've got the [f2] key defined as above, you can also press F2 after
any function (such as rnorm(  ), but it must have an open '(' but no
close ')'.

Hope this helps.




-----Original Message-----
From: ess-help-bounces at stat.math.ethz.ch
[mailto:ess-help-bounces at stat.math.ethz.ch] On Behalf Of Mark W Kimpel
Sent: Tuesday, 3 April 2007 14:34
To: Sven Hartenstein; ess-help at stat.math.ethz.ch
Subject: Re: [ESS] elisp code: show function arguments

I can't get Sven's code to run. As I stated in another post, I am a
newbie and am probably just doing something wrong. I did, btw, figure
out that emacs IS loading the proper .emacs file.

Anyway, I can't seem to get Sven's functionality to work. Below is my
entire .emacs file. Could someone tell me what is wrong?


;;to initiate ess load
(load "/home/mkimpel/src/ess-5.3.3/lisp/ess-site")

;;The following function should be called when point (text cursor) is
between two parentheses of a R function call.
;;It will then (invisibly) query R for which arguments the respective
function knows as well as their default values and show the result.
;; http://www.svenhartenstein.de/emacs-ess.php

(defun my-r-show-args ()
   "Show arguments and their default values of function in minibuffer."
   (interactive "*")
   (let ((pointposition (point)))
     (up-list -1)
     (let ((posend (point)))
	(backward-sexp 1)
	(setq object (buffer-substring-no-properties posend (point)))
	(ess-command (concat "try(args(" object "), silent=TRUE)\n")
		     (get-buffer-create "*my-r-args-completion*"))
     (goto-char pointposition)
   (with-current-buffer "*my-r-args-completion*"
     (goto-char (point-min))
     (if (equal nil (search-forward "function" 10 t))
	  (message my-r-noargsmsg)
	(goto-char (point-min))
	(zap-to-char 1 (string-to-char "("))
	(goto-char (point-max))
	(zap-to-char -1 (string-to-char ")"))
	(if (equal my-r-show-as "tooltip")
	    (tooltip-show (concat "ARGS: " (buffer-string)))
	  (message (concat "ARGS: " (buffer-string)))
   (kill-buffer "*my-r-args-completion*")
(defvar my-r-noargsmsg "Sorry, no arguments found"
   "The message that is returned if my-r-show-args does not find a list
of arguments.") (defvar my-r-show-as nil
   "How my-r-show-args should show the argument list. Possible values
are: 'message' (the default) or 'tooltip'.")

;; call my-r-show-args automatically
(define-key ess-mode-map "(" '(lambda nil "" (interactive)
(skeleton-pair-insert-maybe nil) (my-r-show-args)))

Sven Hartenstein wrote:
> Dear friends of Emacs and R,
> I wrote an emacs lisp function that shows a R-function's arguments and

> their default values on a single keystroke or as you type the opening 
> paranthesis ("(") after a function name. People like me who can't 
> remember all the parameter's names can thus very easily see them.
> See screenshots and get it here:
> http://www.svenhartenstein.de/emacs-ess.php
> The function uses ESS functions. I consider it quite handy and would 
> be interested to know whether anything similar existed already and how

> it could be improved in case someone else considers it useful. (This 
> is one of my first lisp functions, I'm sure there's much to optimize.)

> In fact, any feedback is highly appreciated.
> Happy R-coding,
> Sven
> ______________________________________________
> ESS-help at stat.math.ethz.ch mailing list 
> https://stat.ethz.ch/mailman/listinfo/ess-help

Mark W. Kimpel MD
Department of Psychiatry
Indiana University School of Medicine

ESS-help at stat.math.ethz.ch mailing list

More information about the ESS-help mailing list