Emacs skeletons
Hello
Good
I had some success with Emacs skeletons so here are a few more. A nice
feature of skeletons is that after defining one with define-skeleton
one can invoke with with M-x whatever-you-named-your-skeleton
.
(define-skeleton sdw-skel-xyplot "Skeleton for calling R's xyplot in the lattice package" nil (read-string "plot: ") "(" (read-string "formula: ") ",\n" > "data = " (read-string "data: ") ",\n" g ;; if not subset or groups backup nine spaces > "subset = " (read-string "subset: ") & ",\n" | -9 > "groups = " (read-string "groups: ") & ",\n" | -9 ;; if not any label insert `""' > "xlab = " (format "\"%s\"" (read-string "xlab: ")) & "," | "\"\",\n" > "ylab = " (read-string "ylab: ") & "," | "\"\",\n" > "main = " (read-string "main: ") & "," | "\"\",\n" > "auto.key = " (read-string "key: ") & ",\n" | -11 _ ")" )
Here is a skeleton that uses multiple choice to ask me which type of R lattice plot I want. For code reuse/modularity, I have a function that asks for the plot type and a skeleton that calls the function.
(defun sdw-ask-plot-type () "Multiple choice for R lattice plot function" (interactive) (substring (format "%s" (cdr (read-multiple-choice "plot function? " '((?s "xyplot(") (?b "bwplot(") (?s "stripplot(") (?d "dotplot(") (?c "barchart("))))) 1 -1)) (define-skeleton sdw-skel-plot "Skeleton for asking what lattice plot type" nil (sdw-ask-plot-type) _ ")")
Here is a skeleton for creating an Org src
block:
(define-skeleton sdw-skel-org-src "Skeleton for an Org `src' block" nil "#+begin_src " (read-string "Org src language: ") " :results " (substring (format "%s" (cdr (read-multiple-choice "results?" '((?v "value") (?o "output"))))) 1 -1) " :exports " (substring (format "%s" (cdr (read-multiple-choice "exports?" '((?c "code") (?r "results") (?b "both") (?n "none"))))) 1 -1) "\n" _ "\n" "#+end_src")