-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwww-get-bash.el
More file actions
70 lines (55 loc) · 1.85 KB
/
Copy pathwww-get-bash.el
File metadata and controls
70 lines (55 loc) · 1.85 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
; Open up some BASH when you're feeling blue. Requires
; wget... but you can modify the call-process to use
; curl, if you're a loser.
;
; Mark Burger, December 29, 2014
(defun www-get-bash ()
"Open a new buffer and read some neatly-formatted bash.org"
(interactive)
(switch-to-buffer "bash-scratch")
;(www-get "http://bash.org/?random1")
(call-process "wget" nil t t "-qO" "-" "http://bash.org/?random1" )
(goto-char 0)
(setq i 0 j 0)
(while (and i j)
; Rip out each quote and process 'em one at a time.
(switch-to-buffer "bash-scratch")
(setq i (search-forward "<p class=\"quote\">" nil t))
(setq j (search-forward "</p>\n" nil t))
(when (and i j)
(setq data (buffer-substring i j))
(with-temp-buffer
(insert data)
(goto-char 0) (while (re-search-forward "<a [^>]*>" nil t)
(replace-match "" nil nil))
(goto-char 0) (while (re-search-forward
"</b></a>.*</p><p class=\"qt\">" nil t)
(replace-match "\n" nil nil))
(goto-char 0) (while (search-forward "<b>" nil t)
(replace-match "" nil nil))
(goto-char 0) (while (search-forward "" nil t)
(replace-match "" nil nil))
(goto-char 0) (while (search-forward "<br />" nil t)
(replace-match "" nil nil))
(goto-char 0) (while (search-forward "</p>" nil t)
(replace-match "" nil nil))
(goto-char 0) (while (search-forward """ nil t)
(replace-match "\"" nil nil))
(goto-char 0) (while (search-forward ">" nil t)
(replace-match ">" nil nil))
(goto-char 0) (while (search-forward "<" nil t)
(replace-match "<" nil nil))
(goto-char 0) (while (search-forward " " nil t)
(replace-match " " nil nil))
(setq data (buffer-string))
)
(switch-to-buffer "bash")
(insert (concat data "\n\n"))
)
)
(kill-buffer "bash-scratch")
(switch-to-buffer "bash")
(goto-char 0)
(longlines-mode)
)