Skip to content

Instantly share code, notes, and snippets.

@vsbuffalo
Created May 21, 2011 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsbuffalo/984062 to your computer and use it in GitHub Desktop.
Save vsbuffalo/984062 to your computer and use it in GitHub Desktop.
List all ESS variables in the current buffer.
;; From Michael Hannon and Vince Buffalo
(require 'cl)
(defun flatten (list) ; From `misc-fns.el'.
"Flatten LIST, returning a list with the atoms in LIST at any level.
Also works for a consp whose cdr is non-nil.
Borrowed from: http://www.emacswiki.org/emacs/lib-requires.el"
(cond ((null list) nil)
((atom list) list)
(t
(let ((old list)
(new ())
item)
(while old
(if (atom old) ; From consp with non-nil cdr.
(setq item old
old nil)
(setq item (car old)
old (cdr old)))
;; Make item atomic.
(while (consp item)
(if (cdr item)
(setq old (cons (cdr item) old)))
(setq item (car item)))
(setq new (cons item new)))
(reverse new)))))
(defun make-sep ()
(list (string ?\n)
(string ?\n)
(make-string 48 ?#)
(string ?\n)
(string ?\n)))
(defun print-var-desc(next-var)
(list (flatten (make-sep))
(describe-variable next-var)))
(let (vars)
(do-symbols (s) (when (and (boundp s) (eq (string-match "ess-" (symbol-name s)) 0))
(push s vars)))
(insert (format "%s" (flatten (mapcar (lambda (s) (print-var-desc s)) vars)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment