forked from biodatascience/datasci611
-
Notifications
You must be signed in to change notification settings - Fork 36
/
util.el
39 lines (34 loc) · 1.19 KB
/
util.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(cl-defmacro 611-chain (name init &body body)
`(let ((,name ,init))
,@(cl-loop for term in body collect
`(setq ,name ,term))
,name))
(defun 611-shell-command-to-lines (&rest args)
(611-chain $ (apply #'shell-command-to-string args)
(split-string $ (format "\n") t "[[:space:]]")))
(defun 611-list-images ()
(611-shell-command-to-lines "find . -type f \\( -iname \"*.png\" -o -iname \"*.jpg\" -o -iname \"*.jpeg\" -o -iname \"*.gif\" \\)"))
(defun 611-insert-rpres-image ()
(interactive)
(let* ((files (611-list-images))
(file (ido-completing-read "Which file? " files)))
(insert (format "```{r, echo=FALSE}
knitr::include_graphics(%S);
```" file))))
(defun 611-smallen-region (s e)
(interactive "r")
(let ((r-text (buffer-substring s e)))
(delete-region s e)
(insert (format "<small>\n"))
(insert r-text)
(insert (format "\n</small>"))))
(defun 611-bash-block ()
(interactive)
(let ((caption (read-string "Caption: "))
(name (read-string "Name: ")))
(insert (format "#+CAPTION: %s
#+NAME: %s
#+begin_src bash :results org replace :exports both
" caption name))
(save-excursion
(insert "#+end_src"))))