[ESS] elisp code: show function arguments

Mark W Kimpel mwkimpel at gmail.com
Tue Apr 3 07:03:59 CEST 2007


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?

Thanks,
Mark

;;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 ")"))
	(delete-trailing-whitespace)
	(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
Neuroinformatics
Department of Psychiatry
Indiana University School of Medicine




More information about the ESS-help mailing list