org-mode
用您喜欢的编程语言编写一个代码块。
示例1-使用elisp
代码块
#+name: list-into-checklist-elisp
#+header: :results list raw replace output
#+header: :var data=my-list-block()
#+begin_src elisp
(dolist (x (split-string data "\n"))
(princ (format "[ ] %s\n" x)))
#+end_src
#+RESULTS: list-into-checklist-elisp
- [ ] Lec 1 | 1:20:36
- [ ] Lec 2 | 1:10:32
- [ ] Lec 3 | 1:08:33
- [ ] Lec 4 | 1:20:33
- [ ] ... More ...
- [ ] Lec 24 | 1:24:47
- [ ] Lec 25 | 1:25:21
示例2-使用perl
代码块
#+name: list-into-checklist-perl
#+header: :results list raw replace output
#+header: :var data=my-list-block()
#+begin_src perl
map { printf qq([ ] %s\n), $_ } split(/\n/, $data);
#+end_src
#+RESULTS: list-into-checklist-perl
- [ ] Lec 1 | 1:20:36
- [ ] Lec 2 | 1:10:32
- [ ] Lec 3 | 1:08:33
- [ ] Lec 4 | 1:20:33
- [ ] ... More ...
- [ ] Lec 24 | 1:24:47
- [ ] Lec 25 | 1:25:21
示例3-使用bash
代码块
#+name: list-into-checklist-bash
#+header: :results list raw replace output
#+header: :shebang #!/usr/bin/env bash
#+header: :var data=my-list-block()
#+begin_src sh
while IFS="\n" read -ra ADDR; do
for i in "${ADDR[@]}"; do
echo "[X] $i"
done
done <<< "$data"
#+end_src
#+RESULTS: list-into-checklist-bash
- [X] Lec 1 | 1:20:36
- [X] Lec 2 | 1:10:32
- [X] Lec 3 | 1:08:33
- [X] Lec 4 | 1:20:33
- [X] ... More ...
- [X] Lec 24 | 1:24:47
- [X] Lec 25 | 1:25:21
示例4-使用python
代码块
#+name: list-into-checklist-python
#+header: :results list raw replace output
#+header: :var data=my-list-block()
#+Begin_src python
l = ["[ ] {x}".format(x=row) for row in data.splitlines()]
for i in l: print i
#+end_src
#+RESULTS: list-into-checklist-python
- [ ] Lec 1 | 1:20:36
- [ ] Lec 2 | 1:10:32
- [ ] Lec 3 | 1:08:33
- [ ] Lec 4 | 1:20:33
- [ ] ... More ...
- [ ] Lec 24 | 1:24:47
- [ ] Lec 25 | 1:25:21
示例5-使用ruby
代码块
#+name: list-into-checklist-ruby
#+header: :results list raw replace output
#+header: :var data=my-list-block()
#+Begin_src ruby
for l in data.split("\n")
puts "[ ] #{l}"
end
#+end_src
#+RESULTS: list-into-checklist-ruby
- [ ] Lec 1 | 1:20:36
- [ ] Lec 2 | 1:10:32
- [ ] Lec 3 | 1:08:33
- [ ] Lec 4 | 1:20:33
- [ ] ... More ...
- [ ] Lec 24 | 1:24:47
- [ ] Lec 25 | 1:25:21
multiple cursors
或query-search-replace
。通过转换为检查清单,您的意思是简单地在行前面加上,对[ ]
吗?